/
coveragetests.py
executable file
·126 lines (87 loc) · 4.39 KB
/
coveragetests.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
115
116
117
118
119
120
121
122
123
124
125
126
import opencor as oc
import sys
sys.dont_write_bytecode = True
from basictests import *
def test_data_store_values(values, name, indent=''):
print('%s - Test %s:' % (indent, name))
print('%s - Size: %d' % (indent, len(values)))
for uri, value in values.items():
print('%s - %s:' % (indent, uri))
print('%s - URI: %s' % (indent, value.uri()))
print('%s - Value: %f' % (indent, value.value()))
test_value = 123.456789
value.set_value(test_value)
print('%s - Test value properly set: %s' % (indent, "yes" if value.value() == test_value else "no"))
def edge_test_data_store_variable_index(variable, index, indent):
print('%s - value(%d): %f' % (indent, index, variable.value(index)))
for run in range(variable.runs_count() + 3):
print('%s - value(%d, %d): %f' % (indent, index, run - 2, variable.value(index, run - 2)))
def edge_test_data_store_variable(variable, name, indent=''):
print('%s - Test %s:' % (indent, name))
print('%s - Name: %s' % (indent, variable.name()))
print('%s - Unit: %s' % (indent, variable.unit()))
print('%s - URI: %s' % (indent, variable.uri()))
values_count = variable.values_count()
edge_test_data_store_variable_index(variable, -1, indent)
edge_test_data_store_variable_index(variable, 0, indent)
edge_test_data_store_variable_index(variable, values_count - 1, indent)
edge_test_data_store_variable_index(variable, values_count, indent)
for run in range(variable.runs_count() + 3):
print('%s - values(%d): ' % (indent, run - 2), end='')
print_values(variable.values(run - 2))
def edge_test_data_store_variables(variables, name, indent=''):
print('%s - Test %s:' % (indent, name))
print('%s - Size: %d' % (indent, len(variables)))
for uri, variable in variables.items():
edge_test_data_store_variable(variable, uri, indent + ' ')
if __name__ == '__main__':
# Test for no file name or URL provided
try:
test_simulation('No file name or URL provided', '')
except Exception as e:
print(' - %s' % repr(e))
# Test for an unknown local/remote file
try:
test_simulation('Unknown local file', 'unknown')
except Exception as e:
print(' - %s' % repr(e))
try:
test_simulation('Unknown remote file',
'https://unknown', False)
except Exception as e:
print(' - %s' % repr(e))
# Test for an invalid local/remote file
try:
test_simulation('Invalid local file', 'cellml/underconstrained_model.cellml', False)
except Exception as e:
print(' - %s' % repr(e))
try:
test_simulation('Invalid remote file',
'https://raw.githubusercontent.com/opencor/opencor/master/models/tests/cellml/underconstrained_model.cellml',
False)
except Exception as e:
print(' - %s' % repr(e))
# Coverage tests for SimulationData
header('SimulationData coverage tests', False)
simulation = open_simulation('sedml/lorenz.sedml')
data = simulation.data()
edge_test_data_store_values(data.constants(), 'SimulationData.constants()')
edge_test_data_store_values(data.states(), 'SimulationData.states()')
edge_test_data_store_values(data.rates(), 'SimulationData.rates()')
edge_test_data_store_values(data.algebraic(), 'SimulationData.algebraic()')
# Coverage tests for SimulationResults
header('SimulationResults coverage tests', False)
simulation.reset()
simulation.run()
results = simulation.results()
edge_test_data_store_variable(results.voi(), 'SimulationResults.voi()')
edge_test_data_store_variables(results.constants(), 'SimulationResults.constants()')
edge_test_data_store_variables(results.states(), 'SimulationResults.states()')
edge_test_data_store_variables(results.rates(), 'SimulationResults.rates()')
edge_test_data_store_variables(results.algebraic(), 'SimulationResults.algebraic()')
print(' - Test SimulationResults.data_store():')
data_store = results.data_store()
edge_test_data_store_variable(data_store.voi(), 'DataStore.voi()', ' ')
edge_test_data_store_variables(data_store.variables(), 'DataStore.variables()', ' ')
edge_test_data_store_variables(data_store.voi_and_variables(), 'DataStore.voi_and_variables()', ' ')
oc.close_simulation(simulation)