/
test_systems.py
84 lines (63 loc) · 1.9 KB
/
test_systems.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
from math import isclose
import matplotlib.pyplot as plt
import pytest
from ..system import (System, _ConstantsDict, _MeasurementsDict,
_CoordinatesDict, _StatesDict)
def test_nonvalid_parameters_key():
p = _ConstantsDict({})
with pytest.raises(ValueError):
p['ben stiller'] = 12.0
with pytest.raises(ValueError):
p['time'] = 12.0
with pytest.raises(ValueError):
p['time__hist'] = 12.0
p['a'] = 1.0
if 'a' in p:
pass
del p['a']
def test_setting_measurements_item():
m = _MeasurementsDict({})
# not allowed to set measurements
with pytest.raises(ValueError):
m['a'] = 12.0
def test_setting_coordinates_item():
m = _CoordinatesDict({})
with pytest.raises(ValueError):
m['a '] = 12.0
with pytest.raises(ValueError):
m['time'] = 12.0
with pytest.raises(ValueError):
m['time__hist'] = 12.0
m['first_key'] = 12.0
with pytest.raises(ValueError):
m['second_key'] = 12.0
if 'first_key' in m:
pass
del m['first_key']
def test_setting_state_item():
s = _StatesDict({})
with pytest.raises(ValueError):
s['a'] = 0.0
def test_system():
sys = System()
sys.constants['a'] = 1.0
assert isclose(sys._time['t'], 0.0)
assert isclose(sys._get_par_vals('time'), 0.0)
def plot(a):
fig, ax = plt.subplots(1, 1)
return fig
def update(a):
pass
sys.config_plot_func = None
sys.config_plot_update_func = None
with pytest.raises(ValueError):
sys.animate_configuration()
sys.config_plot_func = plot
sys.config_plot_update_func = None
with pytest.raises(ValueError):
sys.animate_configuration()
# no trajectory computed
sys.config_plot_func = plot
sys.config_plot_update_func = update
with pytest.raises(AttributeError):
sys.animate_configuration()