def test_custom(self): _type = custom(lambda v: v%2 == 1, int, type_str='an odd number') assert(_type(1) == 1) assert(expect_exception(lambda: _type(2), ValueError)) assert(expect_exception(lambda: _type('a'), ValueError))
r""" An example for using lambdas / functions as custom types. """ from ec.ec import task, arg from ec.utils import custom @task @arg(type=custom(lambda v: v%2 == 1, 'an odd number', int)) #pylint: disable=E1121 def task1(arg1): print arg1