Skip to content

Commit 4cbdb94

Browse files
Refactor tests to split value tests into own file
Also cleaned up sim_records - the test_records test was failing due to test reorganization - there's issues with creating records during a module import so now we have a method to create the required records.
1 parent 8d30a64 commit 4cbdb94

File tree

4 files changed

+868
-861
lines changed

4 files changed

+868
-861
lines changed

tests/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77

88
import pytest
99

10+
# Must import softioc before epicsdbbuilder
11+
from softioc.device_core import RecordLookup
12+
from epicsdbbuilder import ResetRecords
13+
14+
requires_cothread = pytest.mark.skipif(
15+
sys.platform.startswith("win"), reason="Cothread doesn't work on windows"
16+
)
17+
1018
class SubprocessIOC:
1119
def __init__(self, ioc_py):
1220
self.pv_prefix = "".join(
@@ -59,3 +67,18 @@ def asyncio_ioc_override():
5967
yield ioc
6068
ioc.kill()
6169
aioca_cleanup()
70+
71+
def _clear_records():
72+
# Remove any records created at epicsdbbuilder layer
73+
ResetRecords()
74+
# And at pythonSoftIoc level
75+
# TODO: Remove this hack and use use whatever comes out of
76+
# https://github.com/dls-controls/pythonSoftIOC/issues/56
77+
RecordLookup._RecordDirectory.clear()
78+
79+
@pytest.fixture
80+
def clear_records():
81+
"""Fixture to delete all records before and after a test."""
82+
_clear_records()
83+
yield
84+
_clear_records()

tests/sim_records.py

Lines changed: 45 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -22,67 +22,54 @@ def on_update(value):
2222
def on_update_name(value, name):
2323
print('on_update', name, ':', repr(value))
2424

25-
t_ai = aIn('AI', initial_value=12.34)
26-
t_boolin = boolIn('BOOLIN', 'True', 'False', initial_value=False)
27-
t_longin = longIn('LONGIN', initial_value=33)
28-
t_stringin = stringIn('STRINGIN', initial_value="Testing string")
29-
t_mbbi = mbbIn(
30-
'MBBI', ('One', alarm.MAJOR_ALARM), 'Two', ('Three', "MINOR"),
31-
initial_value=2)
32-
33-
t_ao = aOut('AO', initial_value=12.45, on_update_name=on_update_name)
34-
t_boolout = boolOut(
35-
'BOOLOUT', 'Zero', 'One', initial_value=True, on_update=on_update)
36-
t_longout = longOut('LONGOUT', initial_value=2008, on_update=on_update)
37-
t_stringout = stringOut(
38-
'STRINGOUT', initial_value='watevah', on_update=on_update)
39-
t_mbbo = mbbOut(
40-
'MBBO', 'Ein', 'Zwei', 'Drei', initial_value=1)
41-
42-
def update_sin_wf(value):
43-
print('update_sin_wf', value)
44-
sin_wf.set(numpy.sin(
45-
numpy.linspace(0, 2*numpy.pi*sin_ph.get(), sin_len.get())))
46-
sin_wf = Waveform('SIN', datatype = float, length = 1024)
47-
# Check we can update its value before iocInit as per #22
48-
sin_wf.set([1, 2, 3])
49-
sin_len = longOut(
50-
'SINN', 0, 1024, initial_value=1024, on_update=update_sin_wf)
51-
sin_ph = aOut('SINP', initial_value = 0.0, on_update = update_sin_wf)
52-
53-
54-
wf_len = 32
55-
wf = numpy.sin(numpy.linspace(0, 2*numpy.pi, wf_len))
56-
t_waveform_in = Waveform('WAVEFORM', wf)
57-
t_waveform_out = WaveformOut('WAVEFORM_OUT', wf, on_update = on_update)
58-
t_waveform_in2 = Waveform('WAVEFORM2', length = 10)
59-
60-
t_longstring_in = longStringIn('LONGSTRING', length = 256)
61-
62-
63-
def Update():
64-
t_ai.set(3.14159)
65-
t_boolin.set(True)
66-
t_longin.set(365)
67-
t_stringin.set('Another different string')
68-
t_mbbi.set(0)
69-
70-
def UpdateOut():
71-
t_ao.set(3.14159)
72-
t_boolout.set(True)
73-
t_longout.set(365)
74-
t_stringout.set('Another different string')
75-
t_mbbo.set(2)
25+
# The publicly accessible records.
26+
t_ai = None
27+
t_ao = None
28+
29+
def create_records():
30+
global t_ai, t_ao
31+
32+
t_ai = aIn('AI', initial_value=12.34)
33+
34+
boolIn('BOOLIN', 'True', 'False', initial_value=False)
35+
longIn('LONGIN', initial_value=33)
36+
stringIn('STRINGIN', initial_value="Testing string")
37+
mbbIn(
38+
'MBBI', ('One', alarm.MAJOR_ALARM), 'Two', ('Three', "MINOR"),
39+
initial_value=2)
40+
41+
t_ao = aOut('AO', initial_value=12.45, on_update_name=on_update_name)
42+
43+
boolOut('BOOLOUT', 'Zero', 'One', initial_value=True, on_update=on_update)
44+
longOut('LONGOUT', initial_value=2008, on_update=on_update)
45+
stringOut('STRINGOUT', initial_value='watevah', on_update=on_update)
46+
mbbOut('MBBO', 'Ein', 'Zwei', 'Drei', initial_value=1)
47+
48+
def update_sin_wf(value):
49+
print('update_sin_wf', value)
50+
sin_wf.set(numpy.sin(
51+
numpy.linspace(0, 2*numpy.pi*sin_ph.get(), sin_len.get())))
52+
sin_wf = Waveform('SIN', datatype = float, length = 1024)
53+
# Check we can update its value before iocInit as per #22
54+
sin_wf.set([1, 2, 3])
55+
sin_len = longOut(
56+
'SINN', 0, 1024, initial_value=1024, on_update=update_sin_wf)
57+
sin_ph = aOut('SINP', initial_value = 0.0, on_update = update_sin_wf)
58+
59+
60+
wf_len = 32
61+
wf = numpy.sin(numpy.linspace(0, 2*numpy.pi, wf_len))
62+
Waveform('WAVEFORM', wf)
63+
WaveformOut('WAVEFORM_OUT', wf, on_update = on_update)
64+
Waveform('WAVEFORM2', length = 10)
65+
66+
longStringIn('LONGSTRING', length = 256)
67+
68+
create_records()
7669

7770
softioc.devIocStats(ioc_name)
7871

79-
__all__ = [
80-
't_ai', 't_boolin', 't_longin', 't_stringin', 't_mbbi',
81-
't_ao', 't_boolout', 't_longout', 't_stringout', 't_mbbo',
82-
't_waveform_in', 't_waveform_in2', 't_waveform_out', 't_longstring_in',
83-
'wf_len',
84-
'Update', 'UpdateOut'
85-
]
72+
__all__ = ['t_ai', 't_ao', ]
8673

8774
if __name__ == "__main__":
8875
WriteRecords("expected_records.db")

0 commit comments

Comments
 (0)