forked from singer-io/singer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_schema.py
More file actions
79 lines (58 loc) · 2.48 KB
/
test_schema.py
File metadata and controls
79 lines (58 loc) · 2.48 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
import unittest
from singer.schema import Schema
class TestSchema(unittest.TestCase):
# Raw data structures for several schema types
string_dict = {
'type': 'string',
'maxLength': 32
}
integer_dict = {
'type': 'integer',
'maximum': 1000000
}
array_dict = {
'type': 'array',
'items': integer_dict
}
object_dict = {
'type': 'object',
'properties': {
'a_string': string_dict,
'an_array': array_dict
},
'inclusion': 'whatever',
}
# Schema object forms of the same schemas as above
string_obj = Schema(type='string', maxLength=32)
integer_obj = Schema(type='integer', maximum=1000000)
array_obj = Schema(type='array', items=integer_obj)
object_obj = Schema(type='object',
properties={'a_string': string_obj,
'an_array': array_obj},
inclusion='whatever')
def test_string_to_dict(self):
self.assertEquals(self.string_dict, self.string_obj.to_dict())
def test_integer_to_dict(self):
self.assertEquals(self.integer_dict, self.integer_obj.to_dict())
def test_array_to_dict(self):
self.assertEquals(self.array_dict, self.array_obj.to_dict())
def test_object_to_dict(self):
self.assertEquals(self.object_dict, self.object_obj.to_dict())
def test_string_from_dict(self):
self.assertEquals(self.string_obj, Schema.from_dict(self.string_dict))
def test_integer_from_dict(self):
self.assertEquals(self.integer_obj, Schema.from_dict(self.integer_dict))
def test_array_from_dict(self):
self.assertEquals(self.array_obj, Schema.from_dict(self.array_dict))
def test_object_from_dict(self):
self.assertEquals(self.object_obj, Schema.from_dict(self.object_dict))
def test_repr_atomic(self):
self.assertEquals(self.string_obj, eval(repr(self.string_obj)))
def test_repr_recursive(self):
self.assertEquals(self.object_obj, eval(repr(self.object_obj)))
def test_object_from_dict_with_defaults(self):
schema = Schema.from_dict(self.object_dict, inclusion='automatic')
self.assertEquals('whatever', schema.inclusion,
msg='The schema value should override the default')
self.assertEquals('automatic', schema.properties['a_string'].inclusion)
self.assertEquals('automatic', schema.properties['an_array'].items.inclusion)