Esempio n. 1
0
    def test_fail_single_on_third_schema(self):
        data = Data({'z': 2}, {}).normalized()
        schemas = (('a', 2), ('b', 2), ('z', 1))

        multi = recursive.MultiRecursive(*schemas)
        with raises(Invalid) as exc:
            multi(data, [])
        assert 'z -> 2 did not match 1' in exc.value.args[0]
Esempio n. 2
0
    def test_fail_on_last_schema(self):
        data = Data({'a': 2, 'b': 1}, {}).normalized()
        schemas = (('a', 2), ('b', 2))

        multi = recursive.MultiRecursive(*schemas)
        with raises(Invalid) as exc:
            multi(data, [])
        assert '1 did not match 2' in exc.value.args[0]
Esempio n. 3
0
 def test_pass_on_second_schema(self):
     data = Data({'b': 1}, {}).normalized()
     multi = recursive.MultiRecursive(('a', 2), ('b', 1))
     assert multi(data, []) is None
Esempio n. 4
0
    def test_pass_two_data_items(self):
        data = Data({'a': 2, 'b': 1}, {}).normalized()
        schemas = (('a', 2), ('b', 1))

        multi = recursive.MultiRecursive(*schemas)
        assert multi(data, []) is None
Esempio n. 5
0
 def __init__(self, data, schema):
     self.data = Data(data, schema).normalized()
     self.schema = Schema(data, schema).normalized()
Esempio n. 6
0
 def __init__(self, data, schema, defined_keys=None):
     if defined_keys:
         schema = cherry_pick(schema)
     self.data = Data(data, schema).normalized()
     self.schema = Schema(data, schema).normalized()
Esempio n. 7
0
    def test_get_one_item_back(self):

        data = Data({'a': 1, 'b': 2}, {}).normalized()
        result = utils.sift(data, ['b'])
        assert result == {0: ('b', 2)}
Esempio n. 8
0
 def test_no_required_items(self):
     data = Data({'a': 1, 'b': 2}, {}).normalized()
     result = utils.sift(data)
     assert result == {}
Esempio n. 9
0
 def test_required_item_is_function_with_object(self):
     item = RequiredItem()
     item._object = 'a'
     data = Data({'a': 1, 'b': 2}, {}).normalized()
     result = utils.sift(data, [item])
     assert result == {0: ('a', 1)}