argspec = inspect.getargspec(arg)
if len(argspec[0]) == 0:
self.arg = lambda ctx: arg()
- elif len(argspec[0]) != 1:
- raise exceptions.ArgumentError("ColumnDefault Python function takes zero or one positional arguments")
else:
- self.arg = arg
+ defaulted = argspec[3] is not None and len(argspec[3]) or 0
+ if len(argspec[0]) - defaulted > 1:
+ raise exceptions.ArgumentError(
+ "ColumnDefault Python function takes zero or one "
+ "positional arguments")
+ else:
+ self.arg = arg
else:
self.arg = arg
t.delete().execute()
def testargsignature(self):
- def mydefault(x, y):
- pass
- try:
- c = ColumnDefault(mydefault)
- assert False
- except exceptions.ArgumentError, e:
- assert str(e) == "ColumnDefault Python function takes zero or one positional arguments", str(e)
+ ex_msg = \
+ "ColumnDefault Python function takes zero or one positional arguments"
+
+ def fn1(x, y): pass
+ def fn2(x, y, z=3): pass
+ for fn in fn1, fn2:
+ try:
+ c = ColumnDefault(fn)
+ assert False
+ except exceptions.ArgumentError, e:
+ assert str(e) == ex_msg
+
+ def fn3(): pass
+ def fn4(): pass
+ def fn5(x=1): pass
+ def fn6(x=1, y=2, z=3): pass
+ fn7 = list
+
+ for fn in fn3, fn4, fn5, fn6, fn7:
+ c = ColumnDefault(fn)
def teststandalone(self):
c = testbase.db.engine.contextual_connect()