def test_repr(self): self.assertEqual( repr(arguments._make_constraint(int)), 'int') self.assertEqual( repr(arguments._make_constraint(arguments.nullable(int))), 'nullable(int)') self.assertEqual( repr(arguments._make_constraint([int])), '[int]') self.assertEqual( repr(arguments._make_constraint((23, 42))), '(23, 42)') self.assertEqual( repr(arguments._make_constraint((int, float, str))), '(int, float, str)') self.assertEqual( repr(arguments._make_constraint([int, float, str])), '[int, float, str]') self.assertEqual( repr(arguments._make_constraint({int: str})), '{int: str}') self.assertEqual( repr(arguments._make_constraint(arguments.flatten(int))), 'flatten(int)') self.assertEqual( repr(arguments._make_constraint(arguments.each(int, float))), 'each(int, float)') self.assertEqual( repr(arguments._make_constraint(arguments.either(int, str))), 'either(int, str)') self.assertEqual( repr(arguments._make_constraint(lambda x: x / 2)), 'lambda x: x / 2') self.assertEqual( repr(arguments._make_constraint( arguments.condition(lambda x: x < 3))), 'condition(lambda x: x < 3)') def foo(x): x constraint = arguments.either( arguments.each(int, arguments.condition(lambda x: x%2 == 0)), arguments.sequenceof(foo), str, ) reprs = 'either(each(int, condition(lambda x: x%2 == 0)), [foo], str)' self.assertEqual(repr(arguments._make_constraint(constraint)), reprs)
def test_repr(self): self.assertEqual(repr(arguments._make_constraint(int)), 'int') self.assertEqual( repr(arguments._make_constraint(arguments.nullable(int))), 'nullable(int)') self.assertEqual(repr(arguments._make_constraint([int])), '[int]') self.assertEqual(repr(arguments._make_constraint((23, 42))), '(23, 42)') self.assertEqual(repr(arguments._make_constraint((int, float, str))), '(int, float, str)') self.assertEqual(repr(arguments._make_constraint([int, float, str])), '[int, float, str]') self.assertEqual(repr(arguments._make_constraint({int: str})), '{int: str}') self.assertEqual( repr(arguments._make_constraint(arguments.flatten(int))), 'flatten(int)') self.assertEqual( repr(arguments._make_constraint(arguments.each(int, float))), 'each(int, float)') self.assertEqual( repr(arguments._make_constraint(arguments.either(int, str))), 'either(int, str)') self.assertEqual(repr(arguments._make_constraint(lambda x: x / 2)), 'lambda x: x / 2') self.assertEqual( repr( arguments._make_constraint( arguments.condition(lambda x: x < 3))), 'condition(lambda x: x < 3)') def foo(x): x constraint = arguments.either( arguments.each(int, arguments.condition(lambda x: x % 2 == 0)), arguments.sequenceof(foo), str, ) reprs = 'either(each(int, condition(lambda x: x%2 == 0)), [foo], str)' self.assertEqual(repr(arguments._make_constraint(constraint)), reprs)
def test_either(self): @arguments.accept(arguments.either(int, str)) def foo(a): pass foo(123) foo('blah') with self.assertRaises(TypeError): foo() with self.assertRaises(TypeError): foo(123.456) @arguments.accept(arguments.either(int, arguments.sequenceof(str))) def bar(a): pass bar(123) bar(['doo', 'bee', 'doo']) with self.assertRaises(TypeError): bar('blah') with self.assertRaises(TypeError): bar([123, 456, 789])
def reset(): global _config, _config_overridden, _hooks _config = _DEFAULT_CONFIG.copy() _config_overridden = [] _hooks = [] _config_updated() @_arguments.accept(kwargs = { 'backend': tuple(_VALID_BACKENDS), 'client_name': str, 'in_ports': _arguments.either( _arguments.each(int, _arguments.condition(lambda x: x > 0)), _arguments.sequenceof( _arguments.either(str, [str])), ), 'out_ports': _arguments.either( _arguments.each(int, _arguments.condition(lambda x: x > 0)), _arguments.sequenceof( _arguments.either(str, [str])), ), 'data_offset': (0, 1), 'octave_offset': int, 'initial_scene': _arguments.either( int, _arguments.each(tuple, [int]), _arguments.each(tuple, [int, int]) ),
def reset(): global _config, _config_overridden, _hooks _config = _DEFAULT_CONFIG.copy() _config_overridden = [] _hooks = [] _config_updated() @_arguments.accept(kwargs = { 'backend': tuple(_VALID_BACKENDS), 'client_name': str, 'in_ports': _arguments.either( _arguments.each(int, _arguments.condition(lambda x: x >= 0)), _arguments.sequenceof( _arguments.either(str, [str])), ), 'out_ports': _arguments.either( _arguments.each(int, _arguments.condition(lambda x: x >= 0)), _arguments.sequenceof( _arguments.either(str, [str])), ), 'data_offset': (0, 1), 'octave_offset': int, 'initial_scene': _arguments.either( int, _arguments.each(tuple, [int]), _arguments.each(tuple, [int, int]) ),