forked from heremaps/flatdata
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_backward_compatibility.py
More file actions
107 lines (85 loc) · 4.31 KB
/
test_backward_compatibility.py
File metadata and controls
107 lines (85 loc) · 4.31 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from flatdata.generator.engine import Engine
from common import *
import pytest
def check_signed_struct(s):
assert -0x1 == s.a
assert 0x01234567 == s.b
assert -0x28 == s.c
assert 0 == s.d
def check_simple_struct(s):
assert 0xFFFFFFFF == s.a
assert 0xDEADBEEF == s.b
def test_instance_reading():
module = Engine(INSTANCE_TEST_SCHEMA).render_python_module()
valid_data = {
"Archive.archive": ARCHIVE_SIGNATURE_PAYLOAD,
"Archive.archive.schema": module.backward_compatibility_Archive.schema().encode(),
"resource": RESOURCE_PAYLOAD,
"resource.schema": module.backward_compatibility_Archive.resource_schema('resource').encode()
}
archive = module.backward_compatibility_Archive(DictResourceStorage(valid_data))
check_signed_struct(archive.resource)
check_signed_struct(archive.resource[0])
def test_multi_namespace_instance_reading():
root_namespace = "backward_compatibility"
module = Engine(MULTI_NAMESPACE_TEST_SCHEMA).render_python_module(None, None, root_namespace)
valid_data = {
"Archive.archive": ARCHIVE_SIGNATURE_PAYLOAD,
"Archive.archive.schema": module.backward_compatibility_Archive.schema().encode(),
"resource": RESOURCE_PAYLOAD,
"resource.schema": module.backward_compatibility_Archive.resource_schema('resource').encode()
}
archive = module.backward_compatibility_Archive(DictResourceStorage(valid_data))
check_signed_struct(archive.resource)
check_signed_struct(archive.resource[0])
def test_vector_reading():
module = Engine(VECTOR_TEST_SCHEMA).render_python_module()
valid_data = {
"Archive.archive": ARCHIVE_SIGNATURE_PAYLOAD,
"Archive.archive.schema": module.backward_compatibility_Archive.schema().encode(),
"resource": RESOURCE_VECTOR_PAYLOAD,
"resource.schema": module.backward_compatibility_Archive.resource_schema('resource').encode()
}
archive = module.backward_compatibility_Archive(DictResourceStorage(valid_data))
assert 2 == len(archive.resource)
check_signed_struct(archive.resource[0])
check_signed_struct(archive.resource[1])
def test_multivector_reading():
module = Engine(MULTIVECTOR_TEST_SCHEMA).render_python_module()
valid_data = {
"Archive.archive": ARCHIVE_SIGNATURE_PAYLOAD,
"Archive.archive.schema": module.backward_compatibility_Archive.schema().encode(),
"resource": MULTIVECTOR_RESOURCE_DATA,
"resource.schema": module.backward_compatibility_Archive.resource_schema('resource').encode(),
"resource_index": MULTIVECTOR_RESOURCE_INDEX,
"resource_index.schema": module.backward_compatibility_Archive.resource_schema('resource').encode()
}
archive = module.backward_compatibility_Archive(DictResourceStorage(valid_data))
assert 4 == len(archive.resource)
assert 2 == len(archive.resource[0])
assert isinstance(archive.resource[0][0], module.backward_compatibility_SignedStruct)
check_signed_struct(archive.resource[0][0])
assert isinstance(archive.resource[0][1], module.backward_compatibility_SimpleStruct)
check_simple_struct(archive.resource[0][1])
assert 0 == len(archive.resource[1])
assert 2 == len(archive.resource[2])
assert isinstance(archive.resource[2][0], module.backward_compatibility_SimpleStruct)
check_simple_struct(archive.resource[2][0])
assert isinstance(archive.resource[2][1], module.backward_compatibility_SignedStruct)
check_signed_struct(archive.resource[2][1])
assert 1 == len(archive.resource[3])
assert isinstance(archive.resource[3][0], module.backward_compatibility_SimpleStruct)
check_simple_struct(archive.resource[3][0])
def test_raw_data_reading():
module = Engine(RAW_DATA_TEST_SCHEMA).render_python_module()
valid_data = {
"Archive.archive": ARCHIVE_SIGNATURE_PAYLOAD,
"Archive.archive.schema": module.backward_compatibility_Archive.schema().encode(),
"resource": RAW_DATA_RESOURCE_DATA,
"resource.schema": module.backward_compatibility_Archive.resource_schema('resource').encode(),
}
archive = module.backward_compatibility_Archive(DictResourceStorage(valid_data))
assert 5 == len(archive.resource)
assert b"\xff" == archive.resource[0]
assert b"\xde" == archive.resource[4]
assert b"\xff\xef\xbe\xad\xde" == archive.resource[0:5]