forked from intel-iot-devkit/python-cv-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_json_serialization.py
114 lines (104 loc) · 2.86 KB
/
test_json_serialization.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
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
108
109
110
111
112
113
114
from analog_gauge_reader import GaugeOption
def test_read_GaugeOption():
json_text = """
{
"name": "Vorlauf",
"rect": {
"x": 814,
"y": 128,
"width": 518,
"height": 503
},
"angles": {
"min": 50,
"max": 317
},
"values": {
"min": 0,
"max": 120
},
"location": "Bockholz 2",
"unit": "Celsius",
"rotation": "ROTATE_180"
}"""
opt = GaugeOption.from_json(json_text)
assert opt is not None
assert opt.name == 'Vorlauf'
assert opt.angles.min == 50
assert opt.angles.max == 317
assert opt.values.min == 0
assert opt.values.max == 120
assert opt.location == 'Bockholz 2'
assert opt.unit == 'Celsius'
assert opt.rotation == 'ROTATE_180'
def test_read_array_of_GaugeOption():
json_text = """
[
{
"name": "Vorlauf",
"rect": {
"x": 814,
"y": 128,
"width": 518,
"height": 503
},
"angles": {
"min": 50,
"max": 317
},
"values": {
"min": 0,
"max": 120
},
"location": "Bockholz 2",
"unit": "Celsius",
"rotation": "ROTATE_180"
},
{
"name": "Ruecklauf",
"rect": {
"x": 368,
"y": 363,
"width": 505,
"height": 495
},
"angles": {
"min": 40,
"max": 315
},
"values": {
"min": 0,
"max": 120
},
"location": "Bockholz 2",
"unit": "Celsius",
"rotation": "ROTATE_180"
}
]"""
opt: list[GaugeOption] = GaugeOption.schema().loads(json_text, many=True)
assert opt is not None
assert len(opt) == 2
assert opt[0].name == 'Vorlauf'
assert opt[0].rect.x == 814
assert opt[0].rect.y == 128
assert opt[0].rect.width == 518
assert opt[0].rect.height == 503
assert opt[0].angles.min == 50
assert opt[0].angles.max == 317
assert opt[0].values.min == 0
assert opt[0].values.max == 120
assert opt[0].location == 'Bockholz 2'
assert opt[0].unit == 'Celsius'
assert opt[0].rotation == 'ROTATE_180'
assert opt[1].name == 'Ruecklauf'
assert opt[1].rect.x == 368
assert opt[1].rect.y == 363
assert opt[1].rect.width == 505
assert opt[1].rect.height == 495
assert opt[1].angles.min == 40
assert opt[1].angles.max == 315
assert opt[1].values.min == 0
assert opt[1].values.max == 120
assert opt[1].location == 'Bockholz 2'
assert opt[1].unit == 'Celsius'
assert opt[1].rotation == 'ROTATE_180'