|
@@ -38,14 +38,19 @@ def set_test_db():
|
38
|
38
|
os.unlink(tmpdb)
|
39
|
39
|
|
40
|
40
|
|
41
|
|
-def test_last_update(set_test_db):
|
42
|
|
- for _, var_type in VariableType.getall().items():
|
|
41
|
+@pytest.fixture
|
|
42
|
+def var_types():
|
|
43
|
+ return VariableType.getall()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+def test_last_update(set_test_db, var_types):
|
|
47
|
+ for _, var_type in var_types.items():
|
43
|
48
|
for _, variable in var_type.get_variables().items():
|
44
|
49
|
try:
|
45
|
50
|
if not variable.last_update:
|
46
|
51
|
continue
|
47
|
52
|
time = datetime.fromtimestamp(variable.last_update)
|
48
|
|
-
|
|
53
|
+
|
49
|
54
|
val = VariableValue.get(variable.type,
|
50
|
55
|
variable.address,
|
51
|
56
|
time)
|
|
@@ -53,3 +58,50 @@ def test_last_update(set_test_db):
|
53
|
58
|
assert variable.last_update == val.time
|
54
|
59
|
except StopIteration:
|
55
|
60
|
assert False
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+def test_var_value_getval(set_test_db, var_types):
|
|
64
|
+ var_type = var_types['Analog']
|
|
65
|
+ for _, variable in var_type.get_variables().items():
|
|
66
|
+ try:
|
|
67
|
+ if not variable.last_update:
|
|
68
|
+ continue
|
|
69
|
+ time = datetime.fromtimestamp(variable.last_update)
|
|
70
|
+
|
|
71
|
+ value = VariableValue.get(variable.type,
|
|
72
|
+ variable.address,
|
|
73
|
+ time).get_value()
|
|
74
|
+ assert type(value) == float
|
|
75
|
+ except StopIteration:
|
|
76
|
+ assert False
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+ var_type = var_types['Integer']
|
|
80
|
+ for _, variable in var_type.get_variables().items():
|
|
81
|
+ try:
|
|
82
|
+ if not variable.last_update:
|
|
83
|
+ continue
|
|
84
|
+ time = datetime.fromtimestamp(variable.last_update)
|
|
85
|
+
|
|
86
|
+ value = VariableValue.get(variable.type,
|
|
87
|
+ variable.address,
|
|
88
|
+ time).get_value()
|
|
89
|
+ assert type(value) == int
|
|
90
|
+ except StopIteration:
|
|
91
|
+ assert False
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+ var_type = var_types['Digital']
|
|
95
|
+ for _, variable in var_type.get_variables().items():
|
|
96
|
+ try:
|
|
97
|
+ if not variable.last_update:
|
|
98
|
+ continue
|
|
99
|
+ time = datetime.fromtimestamp(variable.last_update)
|
|
100
|
+
|
|
101
|
+ value = VariableValue.get(variable.type,
|
|
102
|
+ variable.address,
|
|
103
|
+ time).get_value()
|
|
104
|
+ assert type(value) == bool
|
|
105
|
+ except StopIteration:
|
|
106
|
+ assert False
|
|
107
|
+
|