def test_function(self): # noinspection PyUnresolvedReferences Fun = c.function(c.String, c.Int, a=c.Float, b=c.enum.of(['X', 'Y', 'Z'])) f = Mock() new_f = Fun(f) self.assertTrue(callable(new_f)) with self.assertRaises(exceptions.PyCombValidationError) as e: new_f() e = e.exception self.assertTrue( e.args[0] in ( 'Error on Function(String, Int, a=Float, b=Enum(X: X, Y: Y, Z: Z)): ' 'expected 2 arguments but was 0 arguments', 'Error on Function(String, Int, b=Enum(X: X, Y: Y, Z: Z), a=Float): ' 'expected 2 arguments but was 0 arguments' ) ) with self.assertRaises(exceptions.PyCombValidationError) as e: Fun('Hello') e = e.exception self.assertTrue(e.args[0] in ( 'Error on Function(String, Int, b=Enum(X: X, Y: Y, Z: Z), a=Float): ' 'expected Function(String, Int, b=Enum(X: X, Y: Y, Z: Z), a=Float) but was str', 'Error on Function(String, Int, a=Float, b=Enum(X: X, Y: Y, Z: Z)): ' 'expected Function(String, Int, a=Float, b=Enum(X: X, Y: Y, Z: Z)) but was str' )) # noinspection PyUnusedLocal def f(x1, x2, a=None, b=None): pass g = Fun(f) self.assertIsNot(f, g) g2 = Fun(g) self.assertIs(g, g2)
def test_function_production(self): # noinspection PyUnresolvedReferences Fun = c.function(c.String, c.Int, a=c.Float, b=c.enum.of(['X', 'Y', 'Z'])) new_f = Fun(lambda: None, ctx=context.create(production_mode=True)) new_f()