コード例 #1
0
 def test_all_objects_fail_non_callable(self):
     data = {'a': {'a': 1, 'b': 1, 'c': 1}}
     schema = ('a', recursive.AllObjects((types.string, 2)))
     with raises(Invalid) as exc:
         validate(data, schema)
     error = exc.value.args[0]
     assert '-> a -> a -> 1  did not match 2' in error
コード例 #2
0
    def test_all_objects_fail_length(self):
        data = {'a': {'a': 2, 'b': {'a': 'b'}}}
        schema = ('a', recursive.AllObjects((types.string, 2)))
        with raises(SchemaError) as exc:
            validate(data, schema)

        error = exc.value.args[0]
        assert '-> a -> b  has less items in schema than in data' in error
コード例 #3
0
 def test_nested_raises_nested_invalid(self):
     data = {'a': {'a': ['a'], 'b': {}}}
     nested_schema = iterables.AllItems(types.string)
     schema = ('a', recursive.AllObjects((types.string, nested_schema)))
     with raises(Invalid) as exc:
         validate(data, schema)
     error = exc.value.args[0]
     assert 'did not pass validation against callable: AllItems' in error
コード例 #4
0
 def test_all_objects_fail(self):
     data = {'a': {'a': 1, 'b': 'a string', 'c': 3}}
     schema = ('a', recursive.AllObjects((types.string, types.integer)))
     with raises(Invalid) as exc:
         validate(data, schema)
     error = exc.value.args[0]
     assert '-> a -> b -> a string  did not pass validation against callable: integer' in error
     assert 'not of type int' in error
コード例 #5
0
ファイル: test_engine.py プロジェクト: ktdreyer/notario
    def test_traverser_returns_the_recursive_leaf_if_seen(self):
        data = {'a': {'b': [1, 1, 1, 1]}}
        schema = ('a', recursive.AllObjects(('b', [1, 1, 1, 2])))
        with raises(Invalid) as exc:
            validator = engine.Validator(data, schema)
            validator.validate()

        error = exc.value.args[0]
        assert '-> a -> b -> [1, 1, 1, 1] did not match [1, 1, 1, 2]' in error
コード例 #6
0
 def test_all_objects_fail(self):
     data = {0: ('a', '1'), 1: ('b', 2), 2: ('c', '3')}
     schema = ((types.string, types.integer))
     with raises(Invalid) as exc:
         any_object = recursive.AllObjects(schema)
         any_object(data, [])
     msg = '-> a -> 1 did not pass validation against callable: integer'
     error = exc.value.args[0]
     assert msg in error
     assert 'not of type int' in error
コード例 #7
0
    def test_deal_with_recursion(self):
        data = {'a': {'a': 'a', 'b': {'a': 'b', 'c': 'c', 'd': 1}}}
        schema = ('a', (('a', 'a'), ('b', recursive.AllObjects((types.string, types.string)))))
        with raises(Invalid) as exc:
            validator = engine.Validator(data, schema)
            validator.validate()

        error = exc.value.args[0]
        assert '1  did not pass validation against callable: string' in error
        assert 'not of type string' in error
コード例 #8
0
def devices_object(_object, *args):
    error_msg = 'not of type dictionary or list'
    if isinstance(_object, dict):
        v = recursive.AllObjects((types.string, types.string))
        # this is truly unfortunate but we don't have access to the 'tree' here
        # (the tree is the path to get to the failing key. We settle by just being
        # able to report nicely.
        v(_object, [])
        return

    try:
        assert isinstance(_object, list)
    except AssertionError:
        if args:
            raise Invalid('dict type',
                          pair='value',
                          msg=None,
                          reason=error_msg,
                          *args)
        raise
コード例 #9
0
 def test_no_pollution_from_previous_traversing_all_objects(self):
     data = {
         'a': {
             'a': 1,
             'b': 2
         },
         'b': {
             'c': 1,
             'd': 2
         },
         'c': {
             'e': 1,
             'f': 2
         }
     }
     schema = (('a', (('a', 1), ('b', 2))), ('b', (('c', 1), ('d', 2))),
               ('c', recursive.AllObjects((types.string, types.string))))
     with raises(Invalid) as exc:
         validate(data, schema)
     error = exc.value.args[0]
     assert '-> c -> e -> 1  did not pass validation against callable: string' in error
     assert 'not of type str' in error
コード例 #10
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
コード例 #11
0
 def test_all_objects_pass(self):
     data = {'a': {'a': 1, 'b': 2, 'c': 3}}
     schema = ('a', recursive.AllObjects((types.string, types.integer)))
     assert validate(data, schema) is None
コード例 #12
0
 def test_all_objects_pass(self):
     data = {0: ('a', 1), 1: ('b', 2), 2: ('c', 3)}
     schema = ((types.string, types.integer))
     any_object = recursive.AllObjects(schema)
     assert any_object(data, []) is None