annotate tests/test_schema.py @ 44:ea8c2d01a9d9

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