コード例 #1
0
 def test_use_schema_fails(self):
     schema = ('a', 2)
     hybrid = Hybrid(validator, schema)
     with raises(Invalid) as exc:
         hybrid({0: ('a', 1)})
     error = exc.value.args[0]
     assert 'a -> 1 did not match 2' in error
コード例 #2
0
 def test_use_validator_fails(self):
     schema = ()
     hybrid = Hybrid(validator, schema)
     with raises(Invalid) as exc:
         hybrid(0)
     error = exc.value.args[0]
     assert '0 did not pass validation against callable' in error
コード例 #3
0
 def test_hybrid_delegates_when_dict_or_list(self):
     # send off to Recursive when isinstance(value, (dict, list))
     data = {'a': ['a']}
     hybrid = Hybrid(types.string, iterables.AllItems('b'))
     schema = ('a', hybrid)
     with raises(Invalid) as exc:
         validate(data, schema)
     error = exc.value.args[0]
     assert "list[0] item did not match 'b'" in error
コード例 #4
0
 def test_extra_unexpected_items(self):
     optional_schema = (optional(1), 1)
     schema = ('a', Hybrid(validator, optional_schema))
     data = {'a': {'foo': 'bar'}}
     with raises(Invalid) as exc:
         validate(data, schema)
     error = exc.value.args[0]
     assert '-> a did not match {}' in error
     assert exc.value.reason == 'unexpected extra items'
コード例 #5
0
 def test_fail_object(self):
     sschema = (1, 1)
     schema = ('a', Hybrid(validator, sschema))
     data = {'a': {1: 2}}
     with raises(Invalid) as exc:
         validate(data, schema)
     error = exc.value.args[0]
     assert '1 -> 2 did not match 1' in error
     assert error.startswith('-> a -> 1')
コード例 #6
0
 def test_all_objects_pass_with_hybrid(self):
     data = {'a': {'a': 1, 'b': 2, 'c': 3}}
     dawg = Hybrid(lambda x: True, (types.string, types.integer))
     yo_dawg = recursive.AllObjects(dawg)
     schema = ('a', yo_dawg)
     assert validate(data, schema) is None
コード例 #7
0
 def test_hybrid_delegates_when_dict_or_empty_list(self):
     # send off to Recursive when isinstance(value, (dict, list))
     data = {'a': []}
     hybrid = Hybrid(types.string, iterables.AllItems('b'))
     schema = ('a', hybrid)
     assert validate(data, schema) is None
コード例 #8
0
 def test_passes_object(self):
     sschema = (1, 2)
     schema = ('a', Hybrid(validator, sschema))
     data = {'a': {1: 2}}
     assert validate(data, schema) is None
コード例 #9
0
 def test_passes_single_value(self):
     sschema = (1, 2)
     schema = ('a', Hybrid(validator, sschema))
     data = {'a': 2}
     assert validate(data, schema) is None
コード例 #10
0
 def test_use_schema_passes(self):
     schema = ('a', 1)
     hybrid = Hybrid(validator, schema)
     hybrid({0: ('a', 1)})
コード例 #11
0
 def test_use_validator_passes(self):
     schema = ()
     hybrid = Hybrid(validator, schema)
     assert hybrid(1) is None