annotate tests/test_schema.py @ 43:4ca530618303

Enhance for formery added check when handling conditionals after resolving schema references
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 20 Jul 2023 09:37:22 +0200
parents 0e7acd426e3a
children ea8c2d01a9d9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2 import copy
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
3 import datetime
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
4 import functools
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
5 import re
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
6 import unittest
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
7
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
8 import _config
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
9
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
10 import configmix.yaml
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
11
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
12 import data_schema
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
13 import data_schema.util
16
2a9e7c4b717e Problem severity now is also an enum
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
14 from data_schema import SEVERITY, ERRORS, WARNINGS
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
15
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
16
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
17 TYPE_RE = type(re.compile(r"\A.+\Z"))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
18
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
19
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
20 def _test_generic_validator_for_yaml(obj, schema, context):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
21 """Callback for loading test1.schema.yml: Always successful"""
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
22 yield from ()
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
23
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
24
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
25 class YAML(unittest.TestCase):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
26
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
27 """Tests to load Python objects from YAML with complex Python-specific
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
28 tags.
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
29
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
30 .. seealso:: https://pyyaml.org/wiki/PyYAMLDocumentation
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
31
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
32 """
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
33
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
34 def test_load_python_name(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
35 y = configmix.yaml.load("key: !!python/name:data_schema.validate")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
36 self.assertTrue(callable(y["key"]))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
37
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
38 def test_load_re(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
39 y = configmix.yaml.load("key: !!python/object/apply:re.compile\n - '^[0-9]+$'")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
40 self.assertTrue(isinstance(y["key"], TYPE_RE))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
41
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
42
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
43 class SchemaInYAML(unittest.TestCase):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
44 def test_file(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
45 with data_schema.util.get_data_stream(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
46 _config.FILEURI_PREFIX + "test1.schema.yml",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
47 basedir=_config.config.getvar_s("projectdir")) as f:
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
48 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
49 None, True, configmix.yaml.load(f))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
50
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
51 def test_data(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
52 with data_schema.util.get_data_stream(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
53 "data:testschematalib:test2.schema.yml") as f:
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
54 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
55 None, True, configmix.yaml.load(f))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
56
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
57
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
58 class SchemaCheck(unittest.TestCase):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
59
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
60 def test_root_creation(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
61 schema = data_schema._Schema(None, True)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
62 self.assertIsInstance(schema, dict)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
63 self.assertEqual(0, len(schema))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
64 self.assertFalse(schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
65
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
66 def test_root_creation_wrong(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
67 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
68 ValueError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
69 data_schema._Schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
70 None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
71 False)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
72
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
73 def test_root_properties(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
74 schema = data_schema._Schema(None, True)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
75 self.assertIsNone(schema.parent)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
76 self.assertIs(schema, schema.ROOT)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
77 self.assertTrue(schema.is_sub_root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
78 self.assertIs(schema, schema.SELF)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
79
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
80 def test_dict_len_bool(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
81 schema = data_schema._Schema(None, True, a=1, b=2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
82 self.assertTrue(schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
83 self.assertEqual(2, len(schema))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
84
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
85 def test_equality(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
86 schema1 = data_schema._Schema(None, True, a=1, b=2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
87 schema2 = data_schema._Schema(None, True, b=2, a=1)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
88 self.assertEqual(schema1, schema2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
89 self.assertIsNot(schema1, schema2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
90
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
91 def test_copy(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
92 schema = data_schema._Schema(None, True, type="str")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
93 schema2 = schema.copy()
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
94 self.assertEqual(schema, schema2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
95
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
96 def test_deepcopy(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
97 d1 = {}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
98 schema = data_schema._Schema(None, True, type="str", b=d1)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
99 schema2 = copy.deepcopy(schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
100 self.assertEqual(schema, schema2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
101 self.assertIs(schema["b"], d1)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
102 self.assertIsNot(schema2["b"], d1)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
103 self.assertIs(schema.parent, schema2.parent)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
104 self.assertIs(schema.is_sub_root, schema2.is_sub_root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
105
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
106 def test_nested_copy(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
107 d1 = {}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
108 d2 = {}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
109 root_schema = data_schema._Schema(None, True, type="str", b=d1)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
110 child_schema = data_schema._Schema(root_schema, True, type="bool", b=d2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
111 copied_child = child_schema.copy()
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
112 self.assertIs(copied_child.ROOT, root_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
113 self.assertIs(copied_child.SELF, copied_child)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
114 self.assertIsNot(copied_child.SELF, root_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
115 self.assertEqual(child_schema, copied_child)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
116 self.assertIs(copied_child["b"], d2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
117
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
118 def test_nested_deepcopy(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
119 d1 = {}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
120 d2 = {}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
121 root_schema = data_schema._Schema(None, True, type="str", b=d1)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
122 child_schema = data_schema._Schema(root_schema, True, type="bool", b=d2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
123 copied_child = copy.deepcopy(child_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
124 self.assertIs(copied_child.ROOT, root_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
125 self.assertIs(copied_child.SELF, copied_child)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
126 self.assertEqual(child_schema, copied_child)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
127 self.assertIsNot(copied_child["b"], d2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
128 self.assertNotEqual(root_schema, child_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
129
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
130
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
131 class ContextCheck(unittest.TestCase):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
132
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
133 def test_root_without_settings(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
134 self.assertRaises(TypeError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
135 data_schema.Context,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
136 None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
137 root_object=object(),
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
138 schema=dict())
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
139
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
140 def test_root_context(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
141 obj = object()
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
142 schema = object()
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
143 settings = data_schema.ValidationSettings(
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
144 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
145 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
146 schema_loader=data_schema.default_schema_loader)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
147 ctx = data_schema.Context(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
148 None, root_object=obj, root_schema=schema, settings=settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
149 self.assertEqual("<ROOT>", str(ctx))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
150 self.assertTrue(ctx.root_object is obj)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
151 self.assertTrue(ctx.root_schema is schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
152 self.assertTrue(ctx.settings is settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
153
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
154 def test_parent_of_root_context(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
155 obj = object()
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
156 schema = object()
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
157 settings = data_schema.ValidationSettings(
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
158 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
159 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
160 schema_loader=data_schema.default_schema_loader)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
161 ctx = data_schema.Context(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
162 None, root_object=obj, root_schema=schema, settings=settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
163 self.assertTrue(ctx.is_root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
164 self.assertIsNone(ctx.parent)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
165 try:
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
166 ctx.safe_parent
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
167 except TypeError:
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
168 pass
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
169 else:
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
170 self.fail(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
171 "Context.safe_parent was expected to raise for a root context")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
172
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
173 def test_root_context_init_root_empty(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
174 settings = data_schema.ValidationSettings(
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
175 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
176 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
177 schema_loader=data_schema.default_schema_loader)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
178 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
179 TypeError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
180 data_schema.Context, None, key="key", settings=settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
181 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
182 TypeError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
183 data_schema.Context, None, index="key", settings=settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
184
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
185 def test_root_context_init_only_one_of_key_index(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
186 settings = data_schema.ValidationSettings(
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
187 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
188 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
189 schema_loader=data_schema.default_schema_loader)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
190 root = data_schema.Context(None, settings=settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
191 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
192 ValueError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
193 data_schema.Context, root, key="key", index="index")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
194
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
195 def test_root_context_init_exactly_one(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
196 settings = data_schema.ValidationSettings(
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
197 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
198 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
199 schema_loader=data_schema.default_schema_loader)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
200 root = data_schema.Context(None, settings=settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
201 self.assertRaises(TypeError, data_schema.Context, root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
202
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
203 def test_nonroot_rootobj_schema(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
204 settings = data_schema.ValidationSettings(
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
205 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
206 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
207 schema_loader=data_schema.default_schema_loader)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
208 obj = object()
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
209 schema = object()
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
210 ctx = data_schema.Context(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
211 None, root_object=obj, root_schema=schema, settings=settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
212 self.assertEqual("<ROOT>", str(ctx))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
213 self.assertTrue(ctx.root_object is obj)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
214 self.assertTrue(ctx.root_schema is schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
215 self.assertTrue(ctx.settings is settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
216 self.assertRaises(TypeError, data_schema.Context, ctx, index=0,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
217 root_object=object())
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
218 self.assertRaises(TypeError, data_schema.Context, ctx, index=0,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
219 root_schema=object())
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
220
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
221 def test_str(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
222 settings = data_schema.ValidationSettings(
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
223 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
224 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
225 schema_loader=data_schema.default_schema_loader)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
226 root = data_schema.Context(None, settings=settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
227 ctx1 = data_schema.Context(root, key="key1")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
228 ctx2 = data_schema.Context(ctx1, index=2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
229 ctx3 = data_schema.Context(ctx2, key="key3")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
230 self.assertEqual("key1 / INDEX:2 / key3", str(ctx3))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
231
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
232 def test_repr(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
233 settings = data_schema.ValidationSettings(
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
234 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
235 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
236 schema_loader=data_schema.default_schema_loader)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
237 root = data_schema.Context(None, settings=settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
238 ctx1 = data_schema.Context(root, key="key1")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
239 ctx2 = data_schema.Context(ctx1, index=2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
240 ctx3 = data_schema.Context(ctx2, key="key3")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
241 self.assertEqual("<Context path=`key1 / INDEX:2 / key3'>", repr(ctx3))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
242
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
243 def test_root(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
244 settings = data_schema.ValidationSettings(
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
245 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
246 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
247 schema_loader=data_schema.default_schema_loader)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
248 root = data_schema.Context(None, settings=settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
249 self.assertTrue(root.is_root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
250 self.assertTrue(root is root.root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
251 self.assertTrue(root.settings is settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
252 ctx1 = data_schema.Context(root, key="key1")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
253 self.assertFalse(ctx1.is_root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
254 self.assertTrue(ctx1.root is root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
255 self.assertTrue(ctx1.settings is settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
256 ctx2 = data_schema.Context(ctx1, index=2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
257 self.assertTrue(ctx2.settings is settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
258 ctx3 = data_schema.Context(ctx2, key="key3")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
259 self.assertEqual("key1 / INDEX:2 / key3", str(ctx3))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
260 self.assertFalse(ctx3.is_root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
261 self.assertTrue(ctx3.root is root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
262 self.assertTrue(ctx3.settings is settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
263
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
264 def test_extra_settings_in_between(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
265 settings = data_schema.ValidationSettings(
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
266 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
267 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
268 schema_loader=data_schema.default_schema_loader)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
269 settings2 = data_schema.ValidationSettings(
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
270 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
271 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
272 schema_loader=data_schema.default_schema_loader)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
273 root = data_schema.Context(None, settings=settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
274 self.assertTrue(root.is_root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
275 self.assertTrue(root is root.root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
276 self.assertTrue(root.settings is settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
277 ctx1 = data_schema.Context(root, key="key1")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
278 self.assertFalse(ctx1.is_root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
279 self.assertTrue(ctx1.root is root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
280 self.assertTrue(ctx1.settings is settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
281 ctx2 = data_schema.Context(ctx1, index=2, settings=settings2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
282 self.assertTrue(ctx2.settings is settings2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
283 ctx3 = data_schema.Context(ctx2, key="key3")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
284 self.assertEqual("key1 / INDEX:2 / key3", str(ctx3))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
285 self.assertFalse(ctx3.is_root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
286 self.assertTrue(ctx3.root is root)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
287 self.assertTrue(ctx3.settings is settings2)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
288
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
289 def test_key_xor_index(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
290 settings = data_schema.ValidationSettings(
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
291 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
292 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
293 schema_loader=data_schema.default_schema_loader)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
294 root = data_schema.Context(None, settings=settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
295 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
296 ValueError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
297 data_schema.Context,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
298 root,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
299 index=0,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
300 key="huhu")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
301
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
302 def test_keyindex_requires_key(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
303 settings = data_schema.ValidationSettings(
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
304 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
305 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
306 schema_loader=data_schema.default_schema_loader)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
307 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
308 ValueError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
309 data_schema.Context,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
310 None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
311 key_index=0,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
312 settings=settings)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
313
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
314
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
315 class SchemaReferences(unittest.TestCase):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
316
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
317 def setUp(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
318 self.empty_schema = data_schema._Schema(None, True)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
319
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
320 def test_no_fragment(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
321 ctx = data_schema.Context(None, root_object={"foo": "bar"}, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
322 self.assertRaises(data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
323 data_schema.try_get_reference,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
324 "object:",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
325 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
326 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
327
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
328 def test_empty_fragment(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
329 ctx = data_schema.Context(None, root_object={"foo": "bar"}, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
330 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
331 "object:#",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
332 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
333 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
334 self.assertIs(r, ctx.root_object)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
335 self.assertIs(r, ctx.current_object)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
336
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
337 def test_point_fragment_with_root(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
338 ctx = data_schema.Context(None, root_object={"foo": "bar"}, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
339 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
340 "object:#.",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
341 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
342 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
343 self.assertIs(r, ctx.root_object)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
344 self.assertIs(r, ctx.current_object)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
345
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
346 def test_point_fragment_with_current_object(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
347 current_object = {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
348 "current": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
349 "object": "value"}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
350 root_object = {"root": current_object}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
351 ctx = data_schema.Context(None, current_object=current_object,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
352 root_object=root_object, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
353 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
354 "object:#.",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
355 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
356 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
357 self.assertIs(r, ctx.current_object)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
358 self.assertIs(r, current_object)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
359 self.assertIsNot(r, ctx.root_object)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
360
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
361 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
362 "object:#.current",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
363 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
364 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
365 self.assertEqual({"object": "value"}, r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
366
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
367 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
368 "object:#.current.object",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
369 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
370 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
371 self.assertEqual("value", r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
372
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
373 def test_point_fragment_with_invalid_current_object_refs(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
374 current_object = {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
375 "current": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
376 "object": "value"}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
377 root_object = {"root": current_object}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
378 ctx = data_schema.Context(None, current_object=current_object,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
379 root_object=root_object, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
380 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
381 "object:#.",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
382 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
383 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
384 self.assertIs(r, ctx.current_object)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
385 self.assertIs(r, current_object)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
386
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
387 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
388 "object:#.non-current",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
389 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
390 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
391 self.assertIsNone(r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
392
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
393 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
394 "object:#.non-current.object", ctx, self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
395 self.assertIsNone(r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
396
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
397 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
398 "object:#.current.non-object", ctx, self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
399 self.assertIsNone(r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
400
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
401 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
402 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
403 data_schema.try_get_reference,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
404 "object:#.current..",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
405 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
406 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
407
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
408 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
409 TypeError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
410 data_schema.try_get_reference,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
411 "object:#..current.object",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
412 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
413 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
414
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
415 def test_fragment_with_current_object_and_root(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
416 current_object = {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
417 "current": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
418 "object": "value"}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
419 root_object = {"root": current_object}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
420 ctx = data_schema.Context(None, current_object=current_object,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
421 root_object=root_object, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
422 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
423 "object:#", ctx, self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
424 self.assertIs(r, ctx.root_object)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
425 self.assertIs(r, root_object)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
426
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
427 def test_default_schema_ref(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
428 ctx = data_schema.Context(None, root_object={"foo": "bar"},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
429 settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
430 r = data_schema.try_get_reference("#foo", ctx, self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
431 self.assertEqual("bar", r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
432 r = data_schema.try_get_reference("#bar", ctx, self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
433 self.assertIsNone(r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
434 sentinel = object()
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
435 r = data_schema.try_get_reference("#bar", ctx, self.empty_schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
436 default=sentinel)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
437 self.assertIs(r, sentinel)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
438
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
439 def test_object_schema_ref(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
440 ctx = data_schema.Context(None, root_object={"foo": "bar"},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
441 settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
442 r = data_schema.try_get_reference("object:#foo", ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
443 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
444 self.assertEqual("bar", r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
445 r = data_schema.try_get_reference("object:#bar", ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
446 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
447 self.assertIsNone(r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
448 sentinel = object()
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
449 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
450 "object:#bar",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
451 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
452 self.empty_schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
453 default=sentinel)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
454 self.assertIs(r, sentinel)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
455
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
456 def test_nested_keys(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
457 sentinel = object()
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
458 ctx = data_schema.Context(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
459 None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
460 root_object={"foo": "bar",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
461 "k1": {"k2": "v2",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
462 "k3": None},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
463 "k4": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
464 "k5": [1, 2, 3]},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
465 settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
466 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
467 "#k1.k2", ctx, self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
468 self.assertEqual("v2", r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
469 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
470 "#k1.k3", ctx, self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
471 self.assertIsNone(r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
472 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
473 "#k1.k3.fornone", ctx, self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
474 self.assertIsNone(r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
475 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
476 "#k1.k3.fornone", ctx, self.empty_schema, default=sentinel)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
477 self.assertIs(r, sentinel)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
478 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
479 "#k5.0", ctx, self.empty_schema, default=sentinel)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
480 self.assertIs(r, sentinel)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
481 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
482 "#k6", ctx, self.empty_schema, default=sentinel)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
483 self.assertIs(r, sentinel)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
484
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
485 def test_url_quoted_fragment(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
486 ctx = data_schema.Context(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
487 None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
488 root_object={"foo": "bar",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
489 "k1": {"k2": "v2",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
490 "k3": None},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
491 "k4": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
492 "k5": [1, 2, 3]},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
493 settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
494 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
495 "#fo%6F", ctx, self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
496 self.assertEqual("bar", r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
497
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
498 def test_no_duplicate_unquoting_in_fragment(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
499 ctx = data_schema.Context(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
500 None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
501 root_object={"fo%o": "bar"},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
502 settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
503 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
504 "#fo%25o", ctx, self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
505 self.assertEqual("bar", r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
506
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
507 def test_schema_ref_must_have_fragment(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
508 ctx = data_schema.Context(None, root_schema={"foo": "bar"}, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
509 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
510 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
511 data_schema.try_get_reference,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
512 "schema:",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
513 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
514 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
515
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
516 def test_schema_ref_must_have_absolute_fragment(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
517 ctx = data_schema.Context(None, root_schema={"foo": "bar"}, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
518 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
519 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
520 data_schema.try_get_reference,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
521 "schema:#",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
522 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
523 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
524
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
525 def test_schema_ref_root_schema(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
526 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
527 None, True, {"foo": "bar"})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
528 ctx = data_schema.Context(None, root_schema=schema, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
529 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
530 "schema:#/", ctx, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
531 self.assertIs(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
532
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
533 def test_unknown_schema_ref_yet(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
534 ctx = data_schema.Context(None, root_object={"foo": "bar"}, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
535 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
536 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
537 data_schema.try_get_reference,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
538 "data:#",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
539 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
540 self.empty_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
541
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
542 def test_schema_not_found(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
543 sentinel = object()
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
544 root_schema = data_schema._Schema(None, True, {"foo": "bar"})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
545 ctx = data_schema.Context(None, root_schema=root_schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
546 settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
547 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
548 "schema:#/foo/bar", ctx, root_schema, default=sentinel)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
549 self.assertIs(r, sentinel)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
550 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
551 "schema:#/foo2", ctx, root_schema, default=sentinel)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
552 self.assertIs(r, sentinel)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
553 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
554 "schema:#/foo3", ctx, root_schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
555 self.assertIsNone(r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
556
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
557 def test_schema_is_found(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
558 subsubschema = {"foo3": "bar3"}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
559 subschema = {"foo2": subsubschema}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
560 schema = data_schema._Schema(None, True, {"foo": subschema})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
561 ctx = data_schema.Context(None, root_schema=schema, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
562 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
563 "schema:#/foo/foo2", ctx, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
564 self.assertEqual(subsubschema, r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
565
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
566 def test_schema_with_trailing_slash_is_found(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
567 subsubschema = {"foo3": "bar3"}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
568 subschema = {"foo2": subsubschema}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
569 schema = data_schema._Schema(None, True, {"foo": subschema})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
570 ctx = data_schema.Context(None, root_schema=schema, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
571 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
572 "schema:#/foo/foo2/", ctx, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
573 self.assertIsNone(r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
574
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
575 def test_schema_is_found_with_quoted_fragment(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
576 subsubschema = {"foo3": "bar3"}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
577 subschema = {"foo2": subsubschema}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
578 schema = data_schema._Schema(None, True, {"foo": subschema})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
579 ctx = data_schema.Context(None, root_schema=schema, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
580 r = data_schema.try_get_reference(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
581 "schema:#/f%6Fo/foo%32", ctx, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
582 self.assertEqual(subsubschema, r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
583
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
584
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
585 class SchemaConditionals(unittest.TestCase):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
586
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
587 def setUp(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
588 self._ctx = data_schema.Context(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
589 None, root_object={"foo": "bar", "foo2": None}, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
590
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
591 def test_no_cond(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
592 schema = data_schema._Schema(None, True, {"$type": None})
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
593 self.assertIs(data_schema.process_schema_conditionals(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
594 schema, self._ctx),
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
595 schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
596
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
597 def test_cond_is_none(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
598 schema = data_schema._Schema(None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
599 "cond": None})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
600 self.assertIs(data_schema.process_schema_conditionals(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
601 schema, self._ctx),
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
602 schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
603
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
604 def test_ambiguous(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
605 schema = data_schema._Schema(None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
606 "cond": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
607 "match": None})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
608 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
609 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
610 data_schema.process_schema_conditionals,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
611 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
612 self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
613
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
614 def test_cond_not_a_sequence(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
615 schema = data_schema._Schema(None, True, {"$type": None,
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
616 "cond": {"$type": None}})
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
617 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
618 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
619 data_schema.process_schema_conditionals,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
620 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
621 self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
622
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
623 def test_match_not_a_sequence(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
624 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
625 None, True, {"$type": None,
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
626 "match": {"$type": None}})
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
627 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
628 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
629 data_schema.process_schema_conditionals,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
630 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
631 self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
632
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
633 def test_condline_not_a_dict(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
634 schema = data_schema._Schema(None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
635 "cond": [None]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
636 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
637 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
638 data_schema.process_schema_conditionals,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
639 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
640 self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
641
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
642 def test_matchline_not_a_dict(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
643 schema = {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
644 "match": [None]}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
645 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
646 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
647 data_schema.process_schema_conditionals,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
648 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
649 self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
650
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
651 def test_cond_unknown_predicate(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
652 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
653 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
654 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
655 {"unexisting-when-xxxx": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
656 "then": {}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
657 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
658 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
659 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
660 data_schema.process_schema_conditionals,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
661 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
662 self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
663
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
664 def test_match_unknown_predicate(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
665 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
666 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
667 "match": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
668 {"unexisting-when-xxxx": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
669 "then": {}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
670 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
671 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
672 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
673 data_schema.process_schema_conditionals,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
674 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
675 self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
676
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
677 def test_simple_replace_when_true(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
678 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
679 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
680 "require": ["huhu", "haha"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
681 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
682 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
683 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
684 "require": ["r1", "r2", "r3"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
685 "new-key": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
686 }}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
687 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
688 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
689 self.assertIsNot(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
690 self.assertEqual(["r1", "r2", "r3"], r["require"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
691 self.assertTrue("new-key" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
692 self.assertIsNone(r["new-key"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
693 self.assertFalse("cond" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
694
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
695 def test_simple_replace_when_not_false(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
696 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
697 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
698 "require": ["huhu", "haha"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
699 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
700 {"when": {"not": False},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
701 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
702 "require": ["r1", "r2", "r3"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
703 "new-key": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
704 }}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
705 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
706 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
707 self.assertIsNot(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
708 self.assertEqual(["r1", "r2", "r3"], r["require"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
709 self.assertTrue("new-key" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
710 self.assertIsNone(r["new-key"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
711 self.assertFalse("cond" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
712
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
713 def test_simple_merge_when_true(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
714 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
715 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
716 "require": ["huhu", "haha"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
717 "old-key": "here I am",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
718 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
719 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
720 "then-merge": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
721 "require": ["r1", "r2", "r3"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
722 "new-key": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
723 "old-key": "{{::DEL::}}"
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
724 }}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
725 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
726 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
727 self.assertIsNot(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
728 self.assertEqual(["huhu", "haha", "r1", "r2", "r3"], r["require"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
729 self.assertTrue("new-key" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
730 self.assertIsNone(r["new-key"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
731 self.assertFalse("old-key" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
732 self.assertFalse("cond" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
733
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
734 def test_simple_replace_first_wins_1(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
735 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
736 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
737 "require": ["huhu", "haha", "hehe"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
738 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
739 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
740 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
741 "new-key2": "v2"}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
742 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
743 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
744 "require": ["r1", "r2", "r3"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
745 "new-key": None}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
746 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
747 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
748 self.assertIsNot(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
749 self.assertEqual(["huhu", "haha", "hehe"], r["require"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
750 self.assertTrue("new-key2" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
751 self.assertEqual("v2", r["new-key2"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
752 self.assertFalse("cond" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
753
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
754 def test_simple_replace_first_wins_2(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
755 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
756 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
757 "require": ["huhu", "haha", "hehe"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
758 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
759 {"when": False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
760 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
761 "new-key2": "v2"}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
762 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
763 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
764 "require": ["r1", "r2", "r3"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
765 "new-key": None}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
766 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
767 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
768 self.assertIsNot(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
769 self.assertEqual(["r1", "r2", "r3"], r["require"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
770 self.assertTrue("new-key" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
771 self.assertIsNone(r["new-key"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
772 self.assertFalse("new-key2" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
773 self.assertFalse("cond" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
774
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
775 def test_simple_replace_when_false(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
776 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
777 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
778 "require": ["huhu", "haha"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
779 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
780 {"when": False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
781 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
782 "require": ["r1", "r2", "r3"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
783 "new-key": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
784 }}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
785 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
786 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
787 self.assertIsNot(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
788 self.assertEqual(["huhu", "haha"], r["require"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
789 self.assertFalse("new-key" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
790 self.assertFalse("cond" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
791
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
792 def test_simple_replace_when_ref_true(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
793 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
794 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
795 "require": ["huhu", "haha"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
796 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
797 {"when-ref-true": '#foo',
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
798 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
799 "require": ["r1", "r2", "r3"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
800 "new-key": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
801 }}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
802 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
803 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
804 self.assertIsNot(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
805 self.assertEqual(["r1", "r2", "r3"], r["require"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
806 self.assertTrue("new-key" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
807 self.assertIsNone(r["new-key"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
808 self.assertFalse("cond" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
809
41
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
810 def test_simple_replace_when_ref_false(self):
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
811 schema = data_schema._Schema(
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
812 None, True, {"$type": None,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
813 "require": ["huhu", "haha"],
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
814 "cond": [
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
815 {"when-ref-false": '#foo2',
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
816 "then": {
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
817 "require": ["r1", "r2", "r3"],
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
818 "new-key": None,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
819 }}
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
820 ]})
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
821 r = data_schema.process_schema_conditionals(schema, self._ctx)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
822 self.assertIsNot(r, schema)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
823 self.assertEqual(["r1", "r2", "r3"], r["require"])
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
824 self.assertTrue("new-key" in r)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
825 self.assertIsNone(r["new-key"])
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
826 self.assertFalse("cond" in r)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
827
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
828 def test_simple_replace_when_ref_true_2(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
829 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
830 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
831 "require": ["huhu", "haha"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
832 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
833 {"when": {"ref-true": '#foo'},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
834 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
835 "require": ["r1", "r2", "r3"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
836 "new-key": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
837 }}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
838 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
839 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
840 self.assertIsNot(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
841 self.assertEqual(["r1", "r2", "r3"], r["require"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
842 self.assertTrue("new-key" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
843 self.assertIsNone(r["new-key"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
844 self.assertFalse("cond" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
845
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
846 def test_simple_replace_when_ref_is_not_true(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
847 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
848 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
849 "require": ["huhu", "haha"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
850 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
851 {"when-ref-true": '#not-a-foo',
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
852 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
853 "require": ["r1", "r2", "r3"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
854 "new-key": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
855 }}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
856 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
857 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
858 self.assertIsNot(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
859 self.assertEqual(["huhu", "haha"], r["require"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
860 self.assertTrue("new-key" not in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
861 self.assertFalse("cond" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
862
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
863 def test_simple_replace_when_ref_is_not_true_2(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
864 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
865 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
866 "require": ["huhu", "haha"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
867 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
868 {"when": {"ref-true": '#not-a-foo'},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
869 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
870 "require": ["r1", "r2", "r3"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
871 "new-key": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
872 }}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
873 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
874 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
875 self.assertIsNot(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
876 self.assertEqual(["huhu", "haha"], r["require"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
877 self.assertTrue("new-key" not in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
878 self.assertFalse("cond" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
879
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
880 def test_simple_replace_when_ref_exists(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
881 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
882 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
883 "require": ["huhu", "haha"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
884 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
885 {"when-ref-exists": '#foo2',
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
886 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
887 "require": ["r1", "r2", "r3"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
888 "new-key": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
889 }},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
890 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
891 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
892 "new-key3": "val"}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
893 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
894 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
895 self.assertIsNot(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
896 self.assertEqual(["r1", "r2", "r3"], r["require"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
897 self.assertTrue("new-key" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
898 self.assertIsNone(r["new-key"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
899 self.assertFalse("new-key3" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
900 self.assertFalse("cond" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
901
41
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
902 def test_simple_replace_when_ref_not_exists(self):
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
903 schema = data_schema._Schema(
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
904 None, True, {"$type": None,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
905 "require": ["huhu", "haha"],
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
906 "cond": [
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
907 {"when-ref-not-exists": '#foo3-non-existing',
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
908 "then": {
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
909 "require": ["r1", "r2", "r3"],
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
910 "new-key": None,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
911 }},
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
912 {"when": True,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
913 "then": {
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
914 "new-key3": "val"}}
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
915 ]})
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
916 r = data_schema.process_schema_conditionals(schema, self._ctx)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
917 self.assertIsNot(r, schema)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
918 self.assertEqual(["r1", "r2", "r3"], r["require"])
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
919 self.assertTrue("new-key" in r)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
920 self.assertIsNone(r["new-key"])
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
921 self.assertFalse("new-key3" in r)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
922 self.assertFalse("cond" in r)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
923
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
924 def test_simple_replace_when_ref_exists_2(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
925 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
926 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
927 "require": ["huhu", "haha"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
928 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
929 {"when": {"ref-exists": '#foo2'},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
930 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
931 "require": ["r1", "r2", "r3"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
932 "new-key": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
933 }},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
934 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
935 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
936 "new-key3": "val"}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
937 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
938 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
939 self.assertIsNot(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
940 self.assertEqual(["r1", "r2", "r3"], r["require"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
941 self.assertTrue("new-key" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
942 self.assertIsNone(r["new-key"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
943 self.assertFalse("new-key3" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
944 self.assertFalse("cond" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
945
41
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
946 def test_simple_replace_when_ref_not_exists_2(self):
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
947 schema = data_schema._Schema(
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
948 None, True, {"$type": None,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
949 "require": ["huhu", "haha"],
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
950 "cond": [
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
951 {"when": {"ref-not-exists": '#foo3-non-existing'},
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
952 "then": {
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
953 "require": ["r1", "r2", "r3"],
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
954 "new-key": None,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
955 }},
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
956 {"when": True,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
957 "then": {
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
958 "new-key3": "val"}}
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
959 ]})
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
960 r = data_schema.process_schema_conditionals(schema, self._ctx)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
961 self.assertIsNot(r, schema)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
962 self.assertEqual(["r1", "r2", "r3"], r["require"])
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
963 self.assertTrue("new-key" in r)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
964 self.assertIsNone(r["new-key"])
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
965 self.assertFalse("new-key3" in r)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
966 self.assertFalse("cond" in r)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
967
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
968 def test_simple_replace_when_ref_exists_is_false(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
969 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
970 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
971 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
972 {"when-ref-exists": '#foo-not-existing',
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
973 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
974 "require": ["r1", "r2", "r3"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
975 "new-key": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
976 }},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
977 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
978 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
979 "new-key3": "val"}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
980 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
981 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
982 self.assertIsNot(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
983 self.assertFalse("require" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
984 self.assertFalse("new-key" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
985 self.assertEqual("val", r["new-key3"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
986 self.assertFalse("cond" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
987
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
988 def test_simple_replace_when_ref_exists_is_false_2(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
989 schema = data_schema._Schema(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
990 None, True, {"$type": None,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
991 "cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
992 {"when": {"ref-exists": '#foo-not-existing'},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
993 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
994 "require": ["r1", "r2", "r3"],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
995 "new-key": None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
996 }},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
997 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
998 "then": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
999 "new-key3": "val"}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1000 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1001 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1002 self.assertIsNot(r, schema)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1003 self.assertFalse("require" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1004 self.assertFalse("new-key" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1005 self.assertEqual("val", r["new-key3"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1006 self.assertFalse("cond" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1007
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1008 def test_allOf_true(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1009 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1010 None, True, {"cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1011 {"when": {"all-of": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1012 True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1013 {"ref-exists": '#foo2'},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1014 {"ref-true": '#foo'}]},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1015 "then": {"$type": "string"}},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1016 {"when": True,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1017 "then": {"$type": None}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1018 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1019 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1020 self.assertIsNot(r, schema)
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1021 self.assertEqual("string", r["$type"])
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1022
41
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1023 def test_allOf_true_2(self):
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1024 schema = data_schema._Schema(
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1025 None, True, {"cond": [
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1026 {"when": {"all-of": [
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1027 True,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1028 {"ref-not-exists": '#foo3-not-existing'},
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1029 {"ref-true": '#foo'}]},
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1030 "then": {"$type": "string"}},
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1031 {"when": True,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1032 "then": {"$type": None}}
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1033 ]})
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1034 r = data_schema.process_schema_conditionals(schema, self._ctx)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1035 self.assertIsNot(r, schema)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1036 self.assertEqual("string", r["$type"])
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1037
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1038 def test_allOf_false(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1039 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1040 None, True, {"cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1041 {"when": {"all-of": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1042 True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1043 {"ref-exists": '#foo-non-existing'},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1044 {"ref-true": '#foo'}]},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1045 "then": {"$type": "string"}},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1046 {"when": True,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1047 "then": {"$type": None}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1048 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1049 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1050 self.assertIsNot(r, schema)
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1051 self.assertIsNone(r["$type"])
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1052
41
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1053 def test_allOf_false_2(self):
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1054 schema = data_schema._Schema(
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1055 None, True, {"cond": [
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1056 {"when": {"all-of": [
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1057 True,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1058 {"ref-not-exists": '#foo2'},
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1059 {"ref-true": '#foo'}]},
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1060 "then": {"$type": "string"}},
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1061 {"when": True,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1062 "then": {"$type": None}}
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1063 ]})
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1064 r = data_schema.process_schema_conditionals(schema, self._ctx)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1065 self.assertIsNot(r, schema)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1066 self.assertIsNone(r["$type"])
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1067
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1068 def test_short_allOf_true(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1069 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1070 None, True, {"cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1071 {"when": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1072 True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1073 {"ref-exists": '#foo2'},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1074 {"ref-true": '#foo'}],
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1075 "then": {"$type": "string"}},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1076 {"when": True,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1077 "then": {"$type": None}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1078 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1079 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1080 self.assertIsNot(r, schema)
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1081 self.assertEqual("string", r["$type"])
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1082
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1083 def test_short_allOf_false(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1084 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1085 None, True, {"cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1086 {"when": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1087 True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1088 {"ref-exists": '#foo-non-existing'},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1089 {"ref-true": '#foo'}],
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1090 "then": {"$type": "string"}},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1091 {"when": True,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1092 "then": {"$type": None}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1093 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1094 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1095 self.assertIsNot(r, schema)
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1096 self.assertIsNone(r["$type"])
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1097
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1098 def test_anyOf_true(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1099 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1100 None, True, {"cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1101 {"when": {"any-of": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1102 False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1103 {"ref-exists": '#foo2'},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1104 {"ref-true": '#foo'}]},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1105 "then": {"$type": "string"}},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1106 {"when": True,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1107 "then": {"$type": None}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1108 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1109 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1110 self.assertIsNot(r, schema)
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1111 self.assertEqual("string", r["$type"])
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1112
41
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1113 def test_anyOf_true_2(self):
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1114 schema = data_schema._Schema(
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1115 None, True, {"cond": [
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1116 {"when": {"any-of": [
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1117 False,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1118 {"ref-not-exists": '#foo3-non'},
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1119 {"ref-false": '#foo2'}]},
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1120 "then": {"$type": "string"}},
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1121 {"when": True,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1122 "then": {"$type": None}}
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1123 ]})
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1124 r = data_schema.process_schema_conditionals(schema, self._ctx)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1125 self.assertIsNot(r, schema)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1126 self.assertEqual("string", r["$type"])
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1127
42
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1128 def test_anyOf_true_indirectly_by_ref(self):
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1129 schema = data_schema._Schema(
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1130 None,
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1131 True,
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1132 {"$ref": "schema:$self#/_lib/s1",
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1133 "_lib": {
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1134 "s1": {
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1135 "cond": [
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1136 {"when": {"any-of": [
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1137 False,
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1138 {"ref-not-exists": '#foo3-non'},
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1139 {"ref-false": '#foo2'}]},
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1140 "then": {"$type": "string"}},
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1141 {"when": True,
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1142 "then": {"$type": None}}
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1143 ]}}})
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1144 r = data_schema.process_schema_conditionals(schema, self._ctx)
43
4ca530618303 Enhance for formery added check when handling conditionals after resolving schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 42
diff changeset
1145 self.assertIs(r, schema)
42
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1146 r = data_schema.process_schema_references(r, self._ctx, check_single_ref_key=False)
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1147 self.assertIsNot(r, schema)
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1148 self.assertEqual("string", r["$type"])
0e7acd426e3a An extra unittest to handle schema conditionals after processing schema references
Franz Glasner <fzglas.hg@dom66.de>
parents: 41
diff changeset
1149
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1150 def test_anyOf_false(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1151 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1152 None, True, {"cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1153 {"when": {"any-of": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1154 False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1155 {"ref-exists": '#foo2-non'},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1156 {"ref-true": '#foo2'}]},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1157 "then": {"$type": "string"}},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1158 {"when": True,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1159 "then": {"$type": None}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1160 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1161 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1162 self.assertIsNot(r, schema)
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1163 self.assertIsNone(r["$type"])
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1164
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1165 def test_oneOf_true(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1166 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1167 None, True, {"cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1168 {"when": {"one-of": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1169 False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1170 {"ref-exists": '#foo2'},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1171 {"not": {"ref-true": '#foo'}}]},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1172 "then": {"$type": "string"}},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1173 {"when": True,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1174 "then": {"$type": None}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1175 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1176 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1177 self.assertIsNot(r, schema)
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1178 self.assertEqual("string", r["$type"])
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1179
41
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1180 def test_oneOf_true_2(self):
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1181 schema = data_schema._Schema(
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1182 None, True, {"cond": [
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1183 {"when": {"one-of": [
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1184 False,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1185 {"not": {"ref-false": '#foo'}}]},
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1186 "then": {"$type": "string"}},
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1187 {"when": True,
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1188 "then": {"$type": None}}
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1189 ]})
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1190 r = data_schema.process_schema_conditionals(schema, self._ctx)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1191 self.assertIsNot(r, schema)
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1192 self.assertEqual("string", r["$type"])
d2b43423fa4c Some new test cases with ref-false, when-ref-false, ref-not-existss, when-ref-not-exists
Franz Glasner <fzglas.hg@dom66.de>
parents: 38
diff changeset
1193
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1194 def test_oneOf_false(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1195 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1196 None, True, {"cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1197 {"when": {"one-of": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1198 False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1199 {"ref-exists": '#foo2'},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1200 {"ref-true": '#foo'}]},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1201 "then": {"$type": "string"}},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1202 {"when": True,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1203 "then": {"$type": None}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1204 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1205 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1206 self.assertIsNot(r, schema)
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1207 self.assertIsNone(r["$type"])
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1208
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1209 def test_oneOf_false_2(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1210 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1211 None, True, {"cond": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1212 {"when": {"one-of": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1213 False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1214 {"not": {"ref-exists": '#foo2'}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1215 {"not": {"ref-true": '#foo'}}]},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1216 "then": {"$type": "string"}},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1217 {"when": True,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1218 "then": {"$type": None}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1219 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1220 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1221 self.assertIsNot(r, schema)
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1222 self.assertIsNone(r["$type"])
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1223
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1224 def test_match_nothing(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1225 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1226 None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1227 True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1228 {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1229 "match": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1230 {"when": False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1231 "then": {"new-key": None}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1232 {"when": False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1233 "then": {"new-key2": None}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1234 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1235 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1236 self.assertFalse("new-key" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1237 self.assertFalse("new-key2" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1238
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1239 def test_match_all(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1240 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1241 None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1242 True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1243 {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1244 "match": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1245 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1246 "then": {"new-key": "value"}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1247 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1248 "then": {"new-key2": "value2"}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1249 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1250 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1251 self.assertEqual("value", r["new-key"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1252 self.assertEqual("value2", r["new-key2"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1253
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1254 def test_match_some(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1255 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1256 None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1257 True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1258 {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1259 "match": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1260 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1261 "then": {"new-key": "value"}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1262 {"when": False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1263 "then": {"new-key2": "value2"}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1264 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1265 "then": {"new-key3": "value3"}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1266 {"when": False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1267 "then": {"new-key4": "value4"}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1268 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1269 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1270 self.assertEqual("value", r["new-key"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1271 self.assertFalse("new-key2" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1272 self.assertEqual("value3", r["new-key3"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1273 self.assertFalse("new-key4" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1274
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1275 def test_match_some_merge(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1276 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1277 None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1278 True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1279 {"match": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1280 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1281 "then": {"new-key": [1, 2]}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1282 {"when": False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1283 "then": {"new-key2": "value2"}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1284 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1285 "then-merge": {"new-key": ["value3"]}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1286 {"when": False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1287 "then": {"new-key3": "value3"}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1288 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1289 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1290 self.assertEqual([1, 2, "value3"], r["new-key"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1291 self.assertFalse("new-key2" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1292 self.assertFalse("new-key3" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1293
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1294 def test_match_some_replace(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1295 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1296 None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1297 True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1298 {"match": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1299 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1300 "then": {"new-key": [1, 2]}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1301 {"when": False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1302 "then": {"new-key2": "value2"}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1303 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1304 "then-replace": {"new-key": ["value3"]}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1305 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1306 "then": {"new-key3": "value3"}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1307 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1308 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1309 self.assertEqual(["value3"], r["new-key"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1310 self.assertFalse("new-key2" in r)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1311 self.assertEqual("value3", r["new-key3"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1312
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1313 def test_match_some_merge_existing(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1314 # the typical case within vlobby: just extend "required"
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1315 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1316 None, True, {"required": [1, 2],
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1317 "match": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1318 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1319 "then": {"required": [3, 4]}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1320 {"when": False,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1321 "then": {"required": [0]}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1322 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1323 "then-merge": {"required": [5, 6, 7]}},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1324 {"when": True,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1325 "then-merge": {"required": [4, 8]}}
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1326 ]})
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1327 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1328 self.assertEqual([3, 4, 5, 6, 7, 4, 8], r["required"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1329
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1330 def test_equal_ref_and_value(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1331 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1332 None, True, {"foos": "bar",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1333 "match": [{
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1334 "when": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1335 "equals": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1336 {"ref": "object:#foo"},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1337 {"value": "bar"}]},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1338 "then-replace": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1339 "foos": "new-bar"}}]
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1340 })
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1341 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1342 self.assertEqual("new-bar", r["foos"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1343
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1344 def test_equal_val_and_ref(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1345 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1346 None, True, {"foos": "bar",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1347 "cond": [{
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1348 "when": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1349 "equals": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1350 {"val": "bar"},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1351 {"ref": "object:#foo"}]},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1352 "then-replace": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1353 "foos": "new-bar"}}]
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1354 })
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1355 r = data_schema.process_schema_conditionals(schema, self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1356 self.assertEqual("new-bar", r["foos"])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1357
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1358 def test_equal_no_list(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1359 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1360 None, True, {"foos": "bar",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1361 "match": [{
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1362 "when": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1363 "equals": {"$type": None},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1364 "then-replace": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1365 "foos": "new-bar"}}}]
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1366 })
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1367 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1368 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1369 data_schema.process_schema_conditionals,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1370 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1371 self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1372
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1373 def test_equal_list_length_mismatch_1(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1374 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1375 None, True, {"foo": "bar",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1376 "match": [{
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1377 "when": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1378 "equals": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1379 {"ref": "object:#foo"}]},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1380 "then-replace": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1381 "foo": "new-bar"}}]
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1382 })
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1383 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1384 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1385 data_schema.process_schema_conditionals,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1386 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1387 self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1388
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1389 def test_equal_list_length_mismatch_3(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1390 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1391 None, True, {"foo": "bar",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1392 "match": [{
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1393 "when": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1394 "equals": [
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1395 {"ref": "object:#foo"},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1396 {"ref": "object:#foo"},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1397 {"ref": "object:#foo"}]},
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1398 "then-replace": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1399 "foo": "new-bar"}}]
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1400 })
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1401 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1402 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1403 data_schema.process_schema_conditionals,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1404 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1405 self._ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1406
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1407 def test_raise_no_schema_loader_available(self):
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1408 settings = data_schema.ValidationSettings(
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1409 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1410 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1411 schema_loader=None)
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1412 schema = data_schema._Schema(
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1413 None, True, {"$ref": "schema:file:/tmp/xxx#/"})
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1414 ctx = data_schema.Context(
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1415 None, root_schema=schema, settings=settings)
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1416 self.assertRaises(
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1417 data_schema.SchemaError,
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1418 data_schema.process_schema_references,
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1419 schema,
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1420 ctx)
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1421
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1422 def test_raise_schema_loader_available_but_invalid_basedir(self):
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1423 settings = data_schema.ValidationSettings(
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1424 skip_keys=[], break_on_keynames_problems=True,
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1425 data_stream_loader=None,
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1426 schema_loader=data_schema.default_schema_loader)
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1427 schema = data_schema._Schema(
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1428 None, True, {
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1429 "$ref": "schema:" + _config.FILEURI_PREFIX + "test1.schema.yml#/"
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1430 })
28
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1431 ctx = data_schema.Context(
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1432 None, root_schema=schema, settings=settings)
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1433 self.assertRaises(
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1434 TypeError, # no basedir given
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1435 data_schema.process_schema_references,
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1436 schema,
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1437 ctx)
db3491e1b590 Allow to customize the loading of the schema dict
Franz Glasner <fzglas.hg@dom66.de>
parents: 19
diff changeset
1438
29
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1439 def test_schema_loader_and_data_stream_available_file(self):
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1440 dsl = functools.partial(
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1441 data_schema.util.get_data_stream,
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1442 basedir=_config.PROJECTDIR)
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1443 settings = data_schema.ValidationSettings(
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1444 skip_keys=[], break_on_keynames_problems=True,
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1445 data_stream_loader=dsl,
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1446 schema_loader=data_schema.default_schema_loader)
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1447 schema = data_schema._Schema(
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1448 None, True, {
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1449 "$ref": "schema:" + _config.FILEURI_PREFIX + "test1.schema.yml#/"
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1450 })
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1451 ctx = data_schema.Context(
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1452 None, root_schema=schema, settings=settings)
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1453 data_schema.process_schema_references(schema, ctx)
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1454
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1455 def test_schema_loader_and_data_stream_available_package_explicit_subdir(self):
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1456 dsl = functools.partial(
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1457 data_schema.util.get_data_stream,
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1458 basedir=_config.PROJECTDIR,
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1459 packagesubdir=None)
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1460 settings = data_schema.ValidationSettings(
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1461 skip_keys=[], break_on_keynames_problems=True,
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1462 data_stream_loader=dsl,
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1463 schema_loader=data_schema.default_schema_loader)
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1464 schema = data_schema._Schema(
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1465 None, True, {
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1466 "$ref": "schema:data:testschematalib.packagedata:test2.schema.yml#/"
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1467 })
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1468 ctx = data_schema.Context(
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1469 None, root_schema=schema, settings=settings)
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1470 data_schema.process_schema_references(schema, ctx)
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1471
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1472 def test_schema_loader_and_data_stream_available_package_implicit_subdir(self):
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1473 dsl = functools.partial(
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1474 data_schema.util.get_data_stream,
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1475 basedir=_config.PROJECTDIR)
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1476 settings = data_schema.ValidationSettings(
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1477 skip_keys=[], break_on_keynames_problems=True,
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1478 data_stream_loader=dsl,
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1479 schema_loader=data_schema.default_schema_loader)
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1480 schema = data_schema._Schema(
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1481 None, True, {
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1482 "$ref": "schema:data:testschematalib:test2.schema.yml#/"
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1483 })
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1484 ctx = data_schema.Context(
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1485 None, root_schema=schema, settings=settings)
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1486 data_schema.process_schema_references(schema, ctx)
68286d27f27d FIX: Allow customization of the data stream loader (get_data_stream())
Franz Glasner <fzglas.hg@dom66.de>
parents: 28
diff changeset
1487
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1488 def test_raise_if_scheme_ref_is_not_the_single_key(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1489 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1490 None, True, {"$ref": "schema:#/",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1491 "$type": None
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1492 })
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1493 ctx = data_schema.Context(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1494 None, root_schema=schema, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1495 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1496 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1497 data_schema.process_schema_references,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1498 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1499 ctx)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1500
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1501 def test_raise_if_scheme_ref_is_not_the_single_key_root(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1502 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1503 None, True, {"$ref": "schema:#/subschema",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1504 "subschema": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1505 "$type": None
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1506 }
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1507 })
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1508 ctx = data_schema.Context(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1509 None, root_schema=schema, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1510 r = data_schema.process_schema_references(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1511 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1512 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1513 check_single_ref_key=False)
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1514 self.assertEqual({"$type": None}, r)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1515
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1516 def test_recursive_schema_scheme(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1517 barschema = {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1518 "$type": "null"
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1519 }
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1520 fooschema = {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1521 "$ref": "schema:#/bar"
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1522 }
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1523 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1524 None, True, {"foo": fooschema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1525 "bar": barschema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1526 "$ref": "schema:#/foo"
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1527 })
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1528 ctx = data_schema.Context(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1529 None, root_schema=schema, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1530 r = data_schema.process_schema_references(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1531 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1532 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1533 check_single_ref_key=False)
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1534 self.assertEqual({"$type": "null"}, r)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1535
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1536 def test_recursive_schema_scheme_raises_if_non_root_is_not_single_key(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1537 barschema = {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1538 "$type": "null"
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1539 }
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1540 fooschema = {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1541 "$ref": "schema:#/bar",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1542 "$type": "dict",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1543 }
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1544 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1545 None, True, {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1546 "foo": fooschema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1547 "bar": barschema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1548 "$ref": "schema:#/foo"
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1549 })
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1550 ctx = data_schema.Context(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1551 None, root_schema=schema, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1552 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1553 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1554 data_schema.process_schema_references,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1555 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1556 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1557 check_single_ref_key=False)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1558
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1559 def test_recursive_schema_scheme_ref_to_non_existing_schema_raises(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1560 barschema = {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1561 "$type": "null"
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1562 }
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1563 fooschema = {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1564 "$ref": "schema:#/non-bar",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1565 }
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1566 schema = data_schema._Schema(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1567 None, True, {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1568 "foo": fooschema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1569 "bar": barschema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1570 "$ref": "schema:#/foo"
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1571 })
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1572 ctx = data_schema.Context(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1573 None, root_schema=schema, settings=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1574 self.assertRaises(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1575 data_schema.SchemaError,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1576 data_schema.process_schema_references,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1577 schema,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1578 ctx,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1579 check_single_ref_key=False)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1580
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1581
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1582 class BasicValidation(unittest.TestCase):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1583
30
2e7c08c356ee Test the the ValidationProblem's str() and repr()
Franz Glasner <fzglas.hg@dom66.de>
parents: 29
diff changeset
1584 def test_problem_enum_name(self):
15
696b83f29363 Use enum props when printing validation problems
Franz Glasner <fzglas.hg@dom66.de>
parents: 13
diff changeset
1585 code = ERRORS.E10001
696b83f29363 Use enum props when printing validation problems
Franz Glasner <fzglas.hg@dom66.de>
parents: 13
diff changeset
1586 self.assertEqual("ERRORS.E10001", str(code))
696b83f29363 Use enum props when printing validation problems
Franz Glasner <fzglas.hg@dom66.de>
parents: 13
diff changeset
1587 self.assertEqual("E10001", code.name)
16
2a9e7c4b717e Problem severity now is also an enum
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
1588 self.assertTrue(isinstance(code, ERRORS))
15
696b83f29363 Use enum props when printing validation problems
Franz Glasner <fzglas.hg@dom66.de>
parents: 13
diff changeset
1589
30
2e7c08c356ee Test the the ValidationProblem's str() and repr()
Franz Glasner <fzglas.hg@dom66.de>
parents: 29
diff changeset
1590 def test_problem_to_str(self):
2e7c08c356ee Test the the ValidationProblem's str() and repr()
Franz Glasner <fzglas.hg@dom66.de>
parents: 29
diff changeset
1591 pr = data_schema.ValidationProblem(code=ERRORS.E10001)
2e7c08c356ee Test the the ValidationProblem's str() and repr()
Franz Glasner <fzglas.hg@dom66.de>
parents: 29
diff changeset
1592 self.assertTrue(str(pr).startswith("ValidationProblem(code=E10001 (list expected), severity=ERROR"))
2e7c08c356ee Test the the ValidationProblem's str() and repr()
Franz Glasner <fzglas.hg@dom66.de>
parents: 29
diff changeset
1593 self.assertTrue(repr(pr).startswith("ValidationProblem(code=E10001 (list expected), severity=ERROR"))
2e7c08c356ee Test the the ValidationProblem's str() and repr()
Franz Glasner <fzglas.hg@dom66.de>
parents: 29
diff changeset
1594
2e7c08c356ee Test the the ValidationProblem's str() and repr()
Franz Glasner <fzglas.hg@dom66.de>
parents: 29
diff changeset
1595 def test_problem_with_other_severity_to_str(self):
2e7c08c356ee Test the the ValidationProblem's str() and repr()
Franz Glasner <fzglas.hg@dom66.de>
parents: 29
diff changeset
1596 pr = data_schema.ValidationProblem(code=ERRORS.E10000,
2e7c08c356ee Test the the ValidationProblem's str() and repr()
Franz Glasner <fzglas.hg@dom66.de>
parents: 29
diff changeset
1597 severity=SEVERITY.WARNING)
2e7c08c356ee Test the the ValidationProblem's str() and repr()
Franz Glasner <fzglas.hg@dom66.de>
parents: 29
diff changeset
1598 self.assertTrue(str(pr).startswith("ValidationProblem(code=E10000 (dict expected), severity=WARNING"))
2e7c08c356ee Test the the ValidationProblem's str() and repr()
Franz Glasner <fzglas.hg@dom66.de>
parents: 29
diff changeset
1599 self.assertTrue(repr(pr).startswith("ValidationProblem(code=E10000 (dict expected), severity=WARNING"))
2e7c08c356ee Test the the ValidationProblem's str() and repr()
Franz Glasner <fzglas.hg@dom66.de>
parents: 29
diff changeset
1600
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1601 def test_schema_must_be_a_dict_alike(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1602 try:
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1603 pr = list(data_schema.validate(None, None))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1604 except data_schema.SchemaError:
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1605 pass
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1606 else:
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1607 self.assertFalse(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1608 "no SchemaError raised when a non-dict given as schema")
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1609
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1610 def test_problem_ctor_no_code(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1611 self.assertRaises(TypeError, data_schema.ValidationProblem, code=None)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1612
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1613 def test_error_ctor(self):
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1614 v = data_schema.ValidationProblem(code=ERRORS.E10000)
16
2a9e7c4b717e Problem severity now is also an enum
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
1615 self.assertEqual(SEVERITY.ERROR, v.severity)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1616
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1617 def test_warning_ctor(self):
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1618 v = data_schema.ValidationProblem(code=WARNINGS.W80000)
16
2a9e7c4b717e Problem severity now is also an enum
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
1619 self.assertEqual(SEVERITY.WARNING, v.severity)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1620
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1621 def test_d1(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1622 x = list(data_schema.validate({}, {"$type": "dict"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1623 self.assertEqual(0, len(x))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1624
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1625 def test_d1_not_nullable(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1626 x = list(data_schema.validate(None, {"$type": "dict"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1627 self.assertEqual(1, len(x))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1628 self.assertEqual(ERRORS.E10000, x[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1629
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1630 def test_d1_nullable(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1631 x = list(data_schema.validate(None, {"$type": "dict",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1632 "nullable": True}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1633 self.assertEqual(0, len(x))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1634
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1635 def test_d2(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1636 x = list(data_schema.validate([], {"$type": "map"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1637 self.assertEqual(1, len(x))
16
2a9e7c4b717e Problem severity now is also an enum
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
1638 self.assertEqual(SEVERITY.ERROR, x[0].severity)
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1639 self.assertEqual(ERRORS.E10000, x[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1640
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1641 def test_d3(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1642 x = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1643 {"key": "value"},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1644 {"$type": "dict",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1645 "required": ["key2"]}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1646 self.assertEqual(2, len(x))
16
2a9e7c4b717e Problem severity now is also an enum
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
1647 self.assertEqual(SEVERITY.ERROR, x[0].severity)
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1648 self.assertEqual(ERRORS.E10004, x[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1649 self.assertEqual("key", x[0].hint)
16
2a9e7c4b717e Problem severity now is also an enum
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
1650 self.assertEqual(SEVERITY.ERROR, x[1].severity)
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1651 self.assertEqual(ERRORS.E10005, x[1].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1652 self.assertEqual(["key2"], x[1].hint)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1653
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1654 def test_d4(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1655 x = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1656 {"key": "value"},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1657 {"$type": "dict",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1658 "keys": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1659 "key": {"$type": "string"},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1660 },
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1661 "required": ["key"]}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1662 self.assertEqual(0, len(x))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1663
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1664 def test_d5(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1665 x = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1666 {"key": "value"},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1667 {"$type": "dict",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1668 "additional-keys": False}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1669 self.assertEqual(1, len(x))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1670 self.assertEqual(ERRORS.E10004, x[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1671 self.assertEqual("key", x[0].hint)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1672
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1673 def test_d5_2(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1674 x = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1675 {"key": "value"},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1676 {"$type": "dict",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1677 "additional-keys": False},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1678 skip_keys=["key"]))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1679 self.assertEqual(0, len(x))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1680
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1681 def test_d5_3(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1682 x = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1683 {"key": "value",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1684 "key2": "value"},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1685 {"$type": "dict",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1686 "additional-keys": False},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1687 skip_keys=[re.compile(r"\Akey\d*\Z")]))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1688 self.assertEqual(0, len(x))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1689
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1690 def test_d5_4(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1691 x = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1692 {"key": "value",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1693 "key2": "value"},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1694 {"$type": "dict",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1695 "additional-keys": False},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1696 skip_keys=[re.compile(r"\A__.+"), re.compile(r"\Akey\d+\Z")]))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1697 self.assertEqual(1, len(x))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1698 self.assertEqual(ERRORS.E10004, x[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1699 self.assertEqual("key", x[0].hint)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1700
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1701 def test_d6(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1702 x = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1703 {"key": "value"},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1704 {"$type": "dict",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1705 "additional-keys": True}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1706 self.assertEqual(0, len(x))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1707
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1708 def test_d7(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1709 x = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1710 {"key": "value"},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1711 {"$type": "dict",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1712 "additional-keys": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1713 "$type": "string"}}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1714 self.assertEqual(0, len(x))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1715
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1716 def test_d8(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1717 x = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1718 {"key": 1234},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1719 {"$type": "dict",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1720 "additional-keys": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1721 "$type": "string"}}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1722 self.assertEqual(1, len(x))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1723 self.assertEqual(ERRORS.E10002, x[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1724 self.assertEqual(1234, x[0].hint)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1725
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1726 def test_d8_2(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1727 x = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1728 {"key": 1234},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1729 {"$type": "dict",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1730 "additional-keys": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1731 "$type": "string"}},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1732 skip_keys=["key"]))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1733 self.assertEqual(0, len(x))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1734
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1735 def test_d9_non_string_keys(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1736 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1737 {0: "value"},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1738 {"$type": "dict",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1739 "additional-keys": True}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1740 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1741 self.assertEqual(ERRORS.E10003, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1742
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1743 def test_d10_int_dict_keys(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1744 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1745 {1: "value", 2: "value2"},
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1746 {"$type": "dict",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1747 "keys": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1748 1: {"$type": "string"}},
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1749 "additional-keys": True,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1750 "key-names": {"$type": "int"}}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1751 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1752
38
5a2fba996773 Implement a "forbidden" schema field for dicts
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 31
diff changeset
1753 def test_d11_forbidden_keys(self):
5a2fba996773 Implement a "forbidden" schema field for dicts
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 31
diff changeset
1754 pr = list(data_schema.validate(
5a2fba996773 Implement a "forbidden" schema field for dicts
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 31
diff changeset
1755 {"key": 1234, "key-2": 5678},
5a2fba996773 Implement a "forbidden" schema field for dicts
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 31
diff changeset
1756 {"$type": "dict",
5a2fba996773 Implement a "forbidden" schema field for dicts
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 31
diff changeset
1757 "additional-keys": True,
5a2fba996773 Implement a "forbidden" schema field for dicts
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 31
diff changeset
1758 "forbidden": ["key"]}))
5a2fba996773 Implement a "forbidden" schema field for dicts
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 31
diff changeset
1759 self.assertEqual(1, len(pr))
5a2fba996773 Implement a "forbidden" schema field for dicts
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 31
diff changeset
1760 self.assertEqual(ERRORS.E10059, pr[0].code)
5a2fba996773 Implement a "forbidden" schema field for dicts
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 31
diff changeset
1761
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1762 def test_error_message(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1763 self.assertEqual("dict expected",
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1764 data_schema.problem_message(ERRORS.E10000))
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1765 pr = data_schema.ValidationProblem(code=ERRORS.E10000)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1766 self.assertEqual("dict expected", data_schema.problem_message(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1767
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1768 self.assertEqual("duplicate dict key",
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1769 data_schema.problem_message(WARNINGS.W80000))
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1770 pr = data_schema.ValidationProblem(code=WARNINGS.W80000)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1771 self.assertEqual("duplicate dict key",
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1772 data_schema.problem_message(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1773
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1774 self.assertRaises(KeyError, data_schema.problem_message, 12345)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1775
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1776 def test_str_enum(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1777 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1778 "e1",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1779 {"$type": "string",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1780 "enum": ["e1", "e2"]}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1781 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1782
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1783 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1784 "e2",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1785 {"$type": "string",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1786 "enum": ["e1", "e2"]}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1787 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1788
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1789 def test_str_not_in_enum(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1790 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1791 "e3",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1792 {"$type": "string",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1793 "enum": ["e1", "e2"]}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1794 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1795 self.assertEqual(ERRORS.E10043, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1796
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1797 def test_str_minlen(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1798 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1799 "",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1800 {"$type": "string",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1801 "min-length": 0}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1802 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1803
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1804 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1805 "",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1806 {"$type": "string",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1807 "min-length": 1}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1808 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1809 self.assertEqual(ERRORS.E10006, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1810
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1811 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1812 "x",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1813 {"$type": "string",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1814 "min-length": 1}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1815 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1816
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1817 def test_str_maxlen(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1818 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1819 "",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1820 {"$type": "string",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1821 "max-length": 0}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1822 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1823
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1824 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1825 "x",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1826 {"$type": "string",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1827 "max-length": 0}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1828 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1829 self.assertEqual(ERRORS.E10007, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1830
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1831 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1832 "x",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1833 {"$type": "string",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1834 "max-length": 1}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1835 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1836
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1837 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1838 b"x",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1839 {"$type": "string",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1840 "max-length": 1}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1841 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1842 self.assertEqual(ERRORS.E10002, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1843
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1844 @staticmethod
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1845 def _pattern_check_function(obj, schema, context=None):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1846 if obj == " 5 ":
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1847 yield data_schema.ValidationProblem(code=ERRORS.E10009)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1848
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1849 def test_str_re(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1850 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1851 "abc",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1852 {"$type": "string",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1853 "pattern": r'\A[0-9]+\Z'}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1854 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1855 self.assertEqual(ERRORS.E10008, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1856
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1857 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1858 "123",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1859 {"$type": "string",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1860 "pattern": re.compile(r'\A[a-z]+\Z')}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1861 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1862 self.assertEqual(ERRORS.E10008, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1863
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1864 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1865 "123",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1866 {"$type": "string",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1867 "pattern": self._pattern_check_function}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1868 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1869
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1870 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1871 " 5 ",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1872 {"$type": "string",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1873 "pattern": self._pattern_check_function}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1874 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1875 self.assertEqual(ERRORS.E10009, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1876
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1877 def test_binary_basic(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1878 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1879 b"",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1880 {"$type": "binary"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1881 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1882
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1883 def test_str_is_not_binary(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1884 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1885 "",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1886 {"$type": "binary"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1887 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1888 self.assertEqual(ERRORS.E10035, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1889
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1890 @staticmethod
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1891 def _binary_pattern_check_function(obj, schema, context=None):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1892 if obj != b"\x00":
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1893 yield data_schema.ValidationProblem(code=ERRORS.E10009)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1894
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1895 def test_binary_pattern_check(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1896 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1897 b"\x00",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1898 {"$type": "binary",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1899 "pattern": self._binary_pattern_check_function}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1900 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1901
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1902 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1903 b"\x01",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1904 {"$type": "binary",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1905 "pattern": self._binary_pattern_check_function}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1906 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1907 self.assertEqual(ERRORS.E10009, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1908
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1909 def test_binary_re_str_match(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1910 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1911 b"\x00\x00\x00",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1912 {"$type": "binary",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1913 "pattern": u"\\x00+"}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1914 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1915
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1916 def test_binary_re_bytes_match(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1917 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1918 b"\x00\x00\x00",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1919 {"$type": "binary",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1920 "pattern": b"\x00+"}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1921 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1922
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1923 def test_binary_re_str_mismatch(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1924 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1925 b"\x00\x00\x00",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1926 {"$type": "binary",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1927 "pattern": u"\\x01+"}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1928 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1929 self.assertEqual(ERRORS.E10047, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1930
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1931 def test_binary_re_bytes_mismatch(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1932 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1933 b"\x00\x00\x00",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1934 {"$type": "binary",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1935 "pattern": b"\x01+"}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1936 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1937 self.assertEqual(ERRORS.E10047, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1938
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1939 def test_binary_length(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1940 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1941 b"",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1942 {"$type": "binary",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1943 "min-length": 1}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1944 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1945 self.assertEqual(ERRORS.E10036, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1946
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1947 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1948 b"1",
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1949 {"$type": "binary",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
1950 "max-length": 0}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1951 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1952 self.assertEqual(ERRORS.E10037, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1953
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1954 def test_deny(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1955 pr = list(data_schema.validate("abc", {"$type": "deny"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1956 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1957 self.assertEqual(ERRORS.E10010, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1958
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1959 def test_accept(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1960 pr = list(data_schema.validate("abc", {"$type": "accept"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1961 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1962
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1963 pr = list(data_schema.validate(None, {"$type": "accept"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1964 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1965
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1966 def test_null(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1967 pr = list(data_schema.validate(None, {"$type": "none"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1968 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1969
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1970 pr = list(data_schema.validate(None, {"$type": "null"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1971 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1972
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1973 pr = list(data_schema.validate(None, {"$type": "nil"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1974 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1975
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1976 pr = list(data_schema.validate(None, {"$type": None}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1977 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1978
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1979 pr = list(data_schema.validate({}, {"$type": None}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1980 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1981 self.assertEqual(ERRORS.E10011, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1982
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1983 def test_l1(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1984 pr = list(data_schema.validate([], {"$type": "list"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1985 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1986
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1987 pr = list(data_schema.validate(tuple(), {"$type": "list"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1988 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1989
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1990 def test_l1_not_nullable(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1991 pr = list(data_schema.validate(None, {"$type": "list"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1992 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
1993 self.assertEqual(ERRORS.E10001, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1994
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1995 def test_l1_nullable(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1996 pr = list(data_schema.validate(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
1997 None, {"$type": "list", "nullable": True}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1998 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1999
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2000 def test_l2_default_schema_for_items_is_deny(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2001 pr = list(data_schema.validate(["a", "b", "c"], {"$type": "list"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2002 self.assertEqual(3, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2003 for i in range(0, 3):
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2004 self.assertEqual(ERRORS.E10010, pr[i].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2005
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2006 def test_l3_schema_for_items(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2007 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2008 ["a", "b", "c"],
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2009 {"$type": "array",
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2010 "items": {"$type": "string"}}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2011 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2012
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2013 def test_t1(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2014 pr = list(data_schema.validate([], {"$type": "tuple"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2015 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2016
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2017 pr = list(data_schema.validate(tuple(), {"$type": "tuple"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2018 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2019
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2020 def test_t1_not_nullable(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2021 pr = list(data_schema.validate(None, {"$type": "tuple"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2022 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2023 self.assertEqual(ERRORS.E10014, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2024
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2025 def test_t1_nullable(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2026 pr = list(data_schema.validate(
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2027 None, {"$type": "tuple", "nullable": True}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2028 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2029
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2030 def test_t2(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2031 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2032 ["a", None, {"key": "value"}],
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2033 {"$type": "tuple",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2034 "items": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2035 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2036 {"$type": None},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2037 {"$type": "accept"}]}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2038 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2039
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2040 def test_t3(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2041 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2042 ["a", None, {"key": "value"}],
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2043 {"$type": "tuple",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2044 "items": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2045 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2046 {"$type": None},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2047 {"$type": "deny"}]}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2048 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2049 self.assertEqual(ERRORS.E10010, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2050 self.assertEqual(2, pr[0].context.index)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2051
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2052 def test_t4(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2053 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2054 ["a", None, {"key": "value"}],
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2055 {"$type": "tuple",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2056 "items": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2057 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2058 {"$type": None}]}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2059 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2060 self.assertEqual(ERRORS.E10017, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2061 self.assertEqual(2, pr[0].context.index)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2062
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2063 def test_t5(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2064 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2065 ["a", None, {"key": "value"}],
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2066 {"$type": "tuple",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2067 "items": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2068 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2069 {"$type": None}],
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2070 "additional-items": True}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2071 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2072
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2073 def test_t6(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2074 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2075 ["a", None, {"key": "value"}, {"key": "value"}],
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2076 {"$type": "tuple",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2077 "items": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2078 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2079 {"$type": None}],
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2080 "additional-items": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2081 "$type": "dict",
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2082 "keys": {"key": {"$type": "string"}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2083 }}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2084 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2085
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2086 def test_t7(self):
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2087 # do not check anything that exceeds max-length
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2088 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2089 ["a", None, {"key": "value"}, {"key": "value"}, {"key2": "value"}],
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2090 {"$type": "tuple",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2091 "max-length": 4,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2092 "items": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2093 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2094 {"$type": None}],
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2095 "additional-items": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2096 "$type": "dict",
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2097 "keys": {"key": {"$type": "string"}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2098 }}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2099 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2100 self.assertEqual(ERRORS.E10016, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2101
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2102 def test_t8(self):
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2103 # do not check anything that exceeds max-length
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2104 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2105 ["a", None, {"key": "value"}, {"key": "value"}, {"key2": "value"}],
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2106 {"$type": "tuple",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2107 "min-length": 6,
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2108 "max-length": 4,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2109 "items": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2110 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2111 {"$type": None}],
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2112 "additional-items": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2113 "$type": "dict",
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2114 "keys": {"key": {"$type": "string"}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2115 }}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2116 self.assertEqual(2, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2117 self.assertEqual(ERRORS.E10015, pr[0].code)
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2118 self.assertEqual(ERRORS.E10016, pr[1].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2119
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2120 def test_set1(self):
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2121 # do not check anything that exceeds max-length
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2122 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2123 set(["a", None, "b"]),
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2124 {"$type": "set",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2125 "min-length": 3,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2126 "items": {"any-of": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2127 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2128 {"$type": None}]}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2129 ))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2130 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2131
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2132 def test_set1_not_nullable(self):
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2133 # do not check anything that exceeds max-length
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2134 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2135 None,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2136 {"$type": "set"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2137 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2138 self.assertEqual(ERRORS.E10038, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2139
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2140 def test_set1_nullable(self):
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2141 # do not check anything that exceeds max-length
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2142 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2143 None,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2144 {"$type": "set", "nullable": True}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2145 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2146
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2147 def test_set2(self):
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2148 # do not check anything that exceeds max-length
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2149 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2150 set(["a", None, "b"]),
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2151 {"$type": "set",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2152 "min-length": 4,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2153 "items": {"any-of": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2154 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2155 {"$type": None}]}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2156 ))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2157 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2158 self.assertEqual(ERRORS.E10039, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2159
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2160 def test_set3(self):
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2161 # do not check anything that exceeds max-length
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2162 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2163 set(["a", None, "b"]),
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2164 {"$type": "set",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2165 "max-length": 2,
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2166 "items": {"any-of": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2167 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2168 {"$type": None}]}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2169 ))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2170 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2171 self.assertEqual(ERRORS.E10040, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2172
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2173 def test_set4_itemschema(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2174 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2175 set(["a", None, "b"]),
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2176 {"$type": "set",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2177 "items": {"any-of": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2178 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2179 {"$type": "int"}]}}
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2180 ))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2181 codes = set([p.code for p in pr])
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2182
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2183 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2184 self.assertEqual(ERRORS.E10055, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2185 self.assertEqual(2, len(pr[0].cause))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2186 self.assertEqual(ERRORS.E10056, pr[0].cause[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2187 self.assertEqual(1, len(pr[0].cause[0].cause))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2188 self.assertEqual(ERRORS.E10002, pr[0].cause[0].cause[0].code)
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2189 self.assertEqual(ERRORS.E10056, pr[0].cause[1].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2190 self.assertEqual(1, len(pr[0].cause[1].cause))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2191 self.assertEqual(ERRORS.E10020, pr[0].cause[1].cause[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2192
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2193 def test_empty(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2194 pr = list(data_schema.validate(None, {"$type": "empty"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2195 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2196
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2197 pr = list(data_schema.validate([], {"$type": "empty"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2198 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2199
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2200 pr = list(data_schema.validate(["a"], {"$type": "empty"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2201 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2202 self.assertEqual(ERRORS.E10018, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2203
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2204 pr = list(data_schema.validate(tuple(), {"$type": "empty"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2205 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2206
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2207 pr = list(data_schema.validate(set(), {"$type": "empty"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2208 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2209
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2210 pr = list(data_schema.validate(frozenset(), {"$type": "empty"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2211 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2212
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2213 pr = list(data_schema.validate(tuple(["a"]), {"$type": "empty"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2214 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2215 self.assertEqual(ERRORS.E10018, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2216
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2217 pr = list(data_schema.validate({}, {"$type": "empty"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2218 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2219
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2220 pr = list(data_schema.validate({"key": "value"}, {"$type": "empty"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2221 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2222 self.assertEqual(ERRORS.E10018, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2223
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2224 pr = list(data_schema.validate("", {"$type": "empty"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2225 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2226 self.assertEqual(ERRORS.E10018, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2227
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2228 def test_allOf(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2229 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2230 None,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2231 {"$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2232 "all-of": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2233 {"$type": None},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2234 {"$type": "accept"},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2235 ]
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2236 }}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2237 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2238
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2239 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2240 None,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2241 {"$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2242 "all-of": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2243 {"$type": None},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2244 {"$type": "accept"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2245 {"$type": "deny"},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2246 ]
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2247 }}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2248 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2249 self.assertEqual(ERRORS.E10057, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2250 self.assertEqual(1, len(pr[0].cause))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2251 self.assertEqual(ERRORS.E10058, pr[0].cause[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2252 self.assertEqual(1, len(pr[0].cause[0].cause))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2253 self.assertEqual(ERRORS.E10010, pr[0].cause[0].cause[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2254
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2255 def test_anyOf(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2256 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2257 None,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2258 {"$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2259 "any-of": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2260 {"$type": "deny"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2261 {"$type": None},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2262 ]
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2263 }}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2264 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2265
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2266 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2267 None,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2268 {"$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2269 "any-of": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2270 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2271 {"$type": "deny"},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2272 ]
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2273 }}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2274 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2275 self.assertEqual(ERRORS.E10055, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2276 self.assertEqual(2, len(pr[0].cause))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2277 self.assertEqual(ERRORS.E10056, pr[0].cause[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2278 self.assertEqual(1, len(pr[0].cause[0].cause))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2279 self.assertEqual(ERRORS.E10002, pr[0].cause[0].cause[0].code)
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2280 self.assertEqual(ERRORS.E10056, pr[0].cause[1].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2281 self.assertEqual(1, len(pr[0].cause[1].cause))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2282 self.assertEqual(ERRORS.E10010, pr[0].cause[1].cause[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2283
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2284 def test_anyOf_with_list(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2285 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2286 None,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2287 {"$type": [
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2288 {"$type": "deny"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2289 {"$type": None},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2290 ]}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2291 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2292
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2293 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2294 None,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2295 {"$type": [
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2296 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2297 {"$type": "deny"},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2298 ]}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2299 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2300 self.assertEqual(ERRORS.E10055, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2301 self.assertEqual(2, len(pr[0].cause))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2302 self.assertEqual(ERRORS.E10056, pr[0].cause[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2303 self.assertEqual(1, len(pr[0].cause[0].cause))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2304 self.assertEqual(ERRORS.E10002, pr[0].cause[0].cause[0].code)
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2305 self.assertEqual(ERRORS.E10056, pr[0].cause[1].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2306 self.assertEqual(1, len(pr[0].cause[1].cause))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2307 self.assertEqual(ERRORS.E10010, pr[0].cause[1].cause[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2308
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2309 def test_oneOf(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2310 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2311 None,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2312 {"$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2313 "one-of": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2314 {"$type": "deny"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2315 {"$type": None},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2316 ]
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2317 }}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2318 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2319
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2320 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2321 None,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2322 {"$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2323 "one-of": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2324 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2325 {"$type": "deny"},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2326 ]
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2327 }}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2328
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2329 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2330 self.assertEqual(ERRORS.E10053, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2331 self.assertEqual(2, len(pr[0].cause))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2332 self.assertEqual(ERRORS.E10054, pr[0].cause[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2333 self.assertEqual(1, len(pr[0].cause[0].cause))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2334 self.assertEqual(ERRORS.E10002, pr[0].cause[0].cause[0].code)
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2335 self.assertEqual(ERRORS.E10054, pr[0].cause[1].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2336 self.assertEqual(1, len(pr[0].cause[1].cause))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2337 self.assertEqual(ERRORS.E10010, pr[0].cause[1].cause[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2338
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2339 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2340 None,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2341 {"$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2342 "one-of": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2343 {"$type": "string"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2344 {"$type": "deny"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2345 {"$type": "empty"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2346 {"$type": None},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2347 ]
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2348 }}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2349 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2350 self.assertEqual(ERRORS.E10019, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2351 self.assertEqual("2,3", pr[0].hint)
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2352
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2353 def test_not(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2354 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2355 None,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2356 {"$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2357 "not": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2358 "$type": "empty"}}}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2359 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2360 self.assertEqual(ERRORS.E10029, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2361
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2362 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2363 None,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2364 {"$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2365 "not": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2366 "$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2367 "not": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2368 "$type": "empty"}}}}}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2369 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2370
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2371 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2372 2,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2373 {"$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2374 "not": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2375 "$type": "int"}}}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2376 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2377 self.assertEqual(ERRORS.E10029, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2378
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2379 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2380 1,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2381 {"$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2382 "not": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2383 "$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2384 "not": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2385 "$type": "int"}}}}}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2386 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2387
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2388 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2389 2.0,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2390 {"$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2391 "not": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2392 "$type": "int"}}}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2393 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2394
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2395 def test_not_shortcut(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2396 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2397 None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2398 {"not": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2399 "$type": "empty"}}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2400 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2401 self.assertEqual(ERRORS.E10029, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2402
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2403 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2404 None,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2405 {"not": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2406 "not": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2407 "$type": "empty"}}}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2408 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2409
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2410 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2411 2,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2412 {"not": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2413 "$type": "int"}}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2414 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2415 self.assertEqual(ERRORS.E10029, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2416
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2417 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2418 1,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2419 {"not": {
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2420 "not": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2421 "$type": "int"}}}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2422 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2423
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2424 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2425 2.0,
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2426 {"not": {
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2427 "$type": "int"}}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2428 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2429
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2430 def test_integer(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2431 pr = list(data_schema.validate(1, {"$type": "integer"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2432 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2433
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2434 pr = list(data_schema.validate(1, {"$type": "float"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2435 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2436 self.assertEqual(ERRORS.E10023, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2437
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2438 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2439 2,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2440 {"$type": "int",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2441 "min-value": 3,
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2442 "max-value": 1}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2443
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2444 self.assertEqual(2, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2445 self.assertEqual(ERRORS.E10021, pr[0].code)
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2446 self.assertEqual(ERRORS.E10022, pr[1].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2447
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2448 def test_float(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2449 pr = list(data_schema.validate(1.8, {"$type": "float"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2450 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2451
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2452 pr = list(data_schema.validate(1, {"$type": "float"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2453 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2454 self.assertEqual(ERRORS.E10023, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2455
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2456 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2457 2.0,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2458 {"$type": "real",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2459 "min-value": 2.1,
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2460 "max-value": 1.9}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2461
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2462 self.assertEqual(2, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2463 self.assertEqual(ERRORS.E10024, pr[0].code)
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2464 self.assertEqual(ERRORS.E10025, pr[1].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2465
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2466 def test_number(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2467 pr = list(data_schema.validate(1.8, {"$type": "number"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2468 self.assertEqual(0, len(pr))
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2469 pr = list(data_schema.validate(1, {"$type": "num"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2470 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2471
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2472 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2473 2.0,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2474 {"$type": "number",
19
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2475 "min-value": 3,
c3a0fe8d4587 Consistent casing of schema items: all lowercase with dash as separator
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
2476 "max-value": 1.3}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2477
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2478 self.assertEqual(2, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2479 self.assertEqual(ERRORS.E10031, pr[0].code)
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2480 self.assertEqual(ERRORS.E10032, pr[1].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2481
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2482 pr = list(data_schema.validate({}, {"$type": "number"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2483 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2484 self.assertEqual(ERRORS.E10030, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2485
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2486 def test_bool(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2487 pr = list(data_schema.validate(True, {"$type": "bool"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2488 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2489
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2490 pr = list(data_schema.validate(True, {"$type": "boolean",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2491 "value": True}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2492 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2493
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2494 pr = list(data_schema.validate(True, {"$type": "boolean",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2495 "value": False}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2496 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2497 self.assertEqual(ERRORS.E10028, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2498
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2499 pr = list(data_schema.validate(False, {"$type": "boolean"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2500 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2501
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2502 pr = list(data_schema.validate(False, {"$type": "boolean",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2503 "value": False}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2504 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2505
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2506 pr = list(data_schema.validate(False, {"$type": "boolean",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2507 "value": True}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2508 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2509 self.assertEqual(ERRORS.E10027, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2510
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2511 def test_bool_real(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2512 pr = list(data_schema.validate([1, 2], {"$type": "bool"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2513 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2514 self.assertEqual(ERRORS.E10026, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2515
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2516 pr = list(data_schema.validate([], {"$type": "bool"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2517 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2518 self.assertEqual(ERRORS.E10026, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2519
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2520 pr = list(data_schema.validate(None, {"$type": "bool"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2521 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2522 self.assertEqual(ERRORS.E10026, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2523
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2524 @staticmethod
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2525 def _check_value_ts(obj, schema, context):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2526 if obj == datetime.datetime.fromtimestamp(0):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2527 yield data_schema.ValidationProblem(
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2528 code=ERRORS.E10042, hint=obj, context=context)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2529
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2530 def test_timestamp(self):
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2531 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2532 datetime.datetime.utcnow(),
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2533 {"$type": "timestamp"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2534
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2535 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2536 datetime.datetime.fromtimestamp(180000),
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2537 {"$type": "datetime",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2538 "value": self._check_value_ts}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2539 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2540
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2541 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2542 datetime.datetime.fromtimestamp(0),
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2543 {"$type": "datetime",
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2544 "value": self._check_value_ts}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2545 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2546 self.assertEqual(ERRORS.E10042, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2547
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2548 def test_scalar(self):
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2549 pr = list(data_schema.validate(1, {"$type": "scalar"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2550 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2551
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2552 pr = list(data_schema.validate("", {"$type": "scalar"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2553 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2554
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2555 pr = list(data_schema.validate(False, {"$type": "scalar"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2556 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2557
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2558 pr = list(data_schema.validate(datetime.datetime.utcnow(),
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2559 {"$type": "scalar"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2560 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2561
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2562 pr = list(data_schema.validate(None, {"$type": "scalar"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2563 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2564 self.assertEqual(ERRORS.E10033, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2565
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2566 pr = list(data_schema.validate({}, {"$type": "scalar"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2567 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2568 self.assertEqual(ERRORS.E10033, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2569
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2570 pr = list(data_schema.validate([], {"$type": "scalar"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2571 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2572 self.assertEqual(ERRORS.E10033, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2573
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2574 pr = list(data_schema.validate(tuple(), {"$type": "scalar"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2575 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2576 self.assertEqual(ERRORS.E10033, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2577
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2578 pr = list(data_schema.validate(set(), {"$type": "scalar"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2579 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2580 self.assertEqual(ERRORS.E10033, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2581
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2582 pr = list(data_schema.validate(frozenset(), {"$type": "scalar"}))
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2583 self.assertEqual(1, len(pr))
13
940676a0de84 ERRORS and WARNINGS are now enums
Franz Glasner <fzglas.hg@dom66.de>
parents: 5
diff changeset
2584 self.assertEqual(ERRORS.E10033, pr[0].code)
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2585
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2586 pr = list(data_schema.validate(
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2587 None,
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2588 {"$type": {
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2589 "one-of": [
31
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2590 {"$type": "scalar"},
271ec3abdfa3 Use "$type" as the schema's type specifier instead of "type".
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 30
diff changeset
2591 {"$type": None},
5
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2592 ]}}))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2593 self.assertEqual(0, len(pr))
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2594
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2595
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2596 if __name__ == "__main__":
84dfd1a94926 Add the existing implementation.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2597 unittest.main()