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