forked from wolverdude/GenSON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_seed_schema.py
66 lines (55 loc) · 2.68 KB
/
test_seed_schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from . import base
class TestSeedTuple(base.SchemaNodeTestCase):
def test_tuple(self):
self.add_schema({'type': 'array', 'items': []})
self.add_object([None])
self.assertResult({'type': 'array', 'items': [{'type': 'null'}]})
class TestPatternProperties(base.SchemaNodeTestCase):
def test_single_pattern(self):
self.add_schema({'type': 'object', 'patternProperties': {
r'^\d$': None}})
self.add_object({'0': 0, '1': 1, '2': 2})
self.assertResult({'type': 'object', 'patternProperties': {
r'^\d$': {'type': 'integer'}}})
def test_multi_pattern(self):
self.add_schema({'type': 'object', 'patternProperties': {
r'^\d$': None,
r'^[a-z]$': None}})
self.add_object({'0': 0, '1': 1, 'a': True, 'b': False})
self.assertResult({'type': 'object', 'patternProperties': {
r'^\d$': {'type': 'integer'},
r'^[a-z]$': {'type': 'boolean'}}})
def test_multi_pattern_multi_object(self):
self.add_schema({'type': 'object', 'patternProperties': {
r'^\d$': None,
r'^[a-z]$': None}})
self.add_object({'0': 0})
self.add_object({'1': 1})
self.add_object({'a': True})
self.add_object({'b': False})
self.assertResult({'type': 'object', 'patternProperties': {
r'^\d$': {'type': 'integer'},
r'^[a-z]$': {'type': 'boolean'}}})
def test_existing_schema(self):
self.add_schema({'type': 'object', 'patternProperties': {
r'^\d$': {'type': 'boolean'}}})
self.add_object({'0': 0, '1': 1, '2': 2})
self.assertResult({'type': 'object', 'patternProperties': {
r'^\d$': {'type': ['boolean', 'integer']}}})
def test_prefers_existing_properties(self):
self.add_schema({'type': 'object',
'properties': {'0': None},
'patternProperties': {r'^\d$': None}})
self.add_object({'0': 0, '1': 1, '2': 2})
self.assertResult({'type': 'object',
'properties': {'0': {'type': 'integer'}},
'patternProperties': {r'^\d$': {'type': 'integer'}},
'required': ['0']})
def test_keeps_unrecognized_properties(self):
self.add_schema({'type': 'object',
'patternProperties': {r'^\d$': None}})
self.add_object({'0': 0, '1': 1, '2': 2, 'a': True})
self.assertResult({'type': 'object',
'properties': {'a': {'type': 'boolean'}},
'patternProperties': {r'^\d$': {'type': 'integer'}},
'required': ['a']})