77from fastcs .backends .epics .ioc import (
88 EPICS_MAX_NAME_LENGTH ,
99 EpicsIOC ,
10+ _add_attr_pvi_info ,
1011 _add_pvi_info ,
12+ _add_sub_controller_pvi_info ,
13+ _create_and_link_read_pv ,
14+ _create_and_link_write_pv ,
1115 _get_input_record ,
1216 _get_output_record ,
1317)
2327ONOFF_STATES = {"ZRST" : "disabled" , "ONST" : "enabled" }
2428
2529
26- @pytest .fixture
27- def ioc_without_mapping (mocker : MockerFixture , mapping : Mapping ):
28- mocker .patch ("fastcs.backends.epics.ioc.builder" )
29- mocker .patch ("fastcs.backends.epics.ioc.EpicsIOC._create_and_link_attribute_pvs" )
30- mocker .patch ("fastcs.backends.epics.ioc.EpicsIOC._create_and_link_command_pvs" )
31-
32- return EpicsIOC (DEVICE , mapping )
33-
34-
3530@pytest .mark .asyncio
36- async def test_create_and_link_read_pv (
37- mocker : MockerFixture , ioc_without_mapping : EpicsIOC
38- ):
31+ async def test_create_and_link_read_pv (mocker : MockerFixture ):
3932 get_input_record = mocker .patch ("fastcs.backends.epics.ioc._get_input_record" )
33+ add_attr_pvi_info = mocker .patch ("fastcs.backends.epics.ioc._add_attr_pvi_info" )
4034 attr_is_enum = mocker .patch ("fastcs.backends.epics.ioc.attr_is_enum" )
41- mocker .patch ("fastcs.backends.epics.ioc._add_pvi_info" )
42- add_attr_pvi_info = mocker .patch (
43- "fastcs.backends.epics.ioc.EpicsIOC._add_attr_pvi_info"
44- )
4535 record = get_input_record .return_value
4636
4737 attribute = mocker .MagicMock ()
48- attr_is_enum .return_value = False
4938
50- ioc_without_mapping ._create_and_link_read_pv ("PREFIX" , "PV" , "attr" , attribute )
39+ attr_is_enum .return_value = False
40+ _create_and_link_read_pv ("PREFIX" , "PV" , "attr" , attribute )
5141
5242 get_input_record .assert_called_once_with ("PREFIX:PV" , attribute )
5343 add_attr_pvi_info .assert_called_once_with (record , "PREFIX" , "attr" , "r" )
@@ -61,21 +51,17 @@ async def test_create_and_link_read_pv(
6151
6252
6353@pytest .mark .asyncio
64- async def test_create_and_link_read_pv_enum (
65- mocker : MockerFixture , ioc_without_mapping : EpicsIOC
66- ):
54+ async def test_create_and_link_read_pv_enum (mocker : MockerFixture ):
6755 get_input_record = mocker .patch ("fastcs.backends.epics.ioc._get_input_record" )
68- add_attr_pvi_info = mocker .patch (
69- "fastcs.backends.epics.ioc.EpicsIOC._add_attr_pvi_info"
70- )
56+ add_attr_pvi_info = mocker .patch ("fastcs.backends.epics.ioc._add_attr_pvi_info" )
7157 attr_is_enum = mocker .patch ("fastcs.backends.epics.ioc.attr_is_enum" )
7258 record = get_input_record .return_value
7359 enum_value_to_index = mocker .patch ("fastcs.backends.epics.ioc.enum_value_to_index" )
7460
7561 attribute = mocker .MagicMock ()
7662
7763 attr_is_enum .return_value = True
78- ioc_without_mapping . _create_and_link_read_pv ("PREFIX" , "PV" , "attr" , attribute )
64+ _create_and_link_read_pv ("PREFIX" , "PV" , "attr" , attribute )
7965
8066 get_input_record .assert_called_once_with ("PREFIX:PV" , attribute )
8167 add_attr_pvi_info .assert_called_once_with (record , "PREFIX" , "attr" , "r" )
@@ -122,21 +108,17 @@ def test_get_input_record_raises(mocker: MockerFixture):
122108
123109
124110@pytest .mark .asyncio
125- async def test_create_and_link_write_pv (
126- mocker : MockerFixture , ioc_without_mapping : EpicsIOC
127- ):
111+ async def test_create_and_link_write_pv (mocker : MockerFixture ):
128112 get_output_record = mocker .patch ("fastcs.backends.epics.ioc._get_output_record" )
129- add_attr_pvi_info = mocker .patch (
130- "fastcs.backends.epics.ioc.EpicsIOC._add_attr_pvi_info"
131- )
113+ add_attr_pvi_info = mocker .patch ("fastcs.backends.epics.ioc._add_attr_pvi_info" )
132114 attr_is_enum = mocker .patch ("fastcs.backends.epics.ioc.attr_is_enum" )
133115 record = get_output_record .return_value
134116
135117 attribute = mocker .MagicMock ()
136118 attribute .process_without_display_update = mocker .AsyncMock ()
137119
138120 attr_is_enum .return_value = False
139- ioc_without_mapping . _create_and_link_write_pv ("PREFIX" , "PV" , "attr" , attribute )
121+ _create_and_link_write_pv ("PREFIX" , "PV" , "attr" , attribute )
140122
141123 get_output_record .assert_called_once_with (
142124 "PREFIX:PV" , attribute , on_update = mocker .ANY
@@ -158,13 +140,9 @@ async def test_create_and_link_write_pv(
158140
159141
160142@pytest .mark .asyncio
161- async def test_create_and_link_write_pv_enum (
162- mocker : MockerFixture , ioc_without_mapping : EpicsIOC
163- ):
143+ async def test_create_and_link_write_pv_enum (mocker : MockerFixture ):
164144 get_output_record = mocker .patch ("fastcs.backends.epics.ioc._get_output_record" )
165- add_attr_pvi_info = mocker .patch (
166- "fastcs.backends.epics.ioc.EpicsIOC._add_attr_pvi_info"
167- )
145+ add_attr_pvi_info = mocker .patch ("fastcs.backends.epics.ioc._add_attr_pvi_info" )
168146 attr_is_enum = mocker .patch ("fastcs.backends.epics.ioc.attr_is_enum" )
169147 enum_value_to_index = mocker .patch ("fastcs.backends.epics.ioc.enum_value_to_index" )
170148 enum_index_to_value = mocker .patch ("fastcs.backends.epics.ioc.enum_index_to_value" )
@@ -174,7 +152,7 @@ async def test_create_and_link_write_pv_enum(
174152 attribute .process_without_display_update = mocker .AsyncMock ()
175153
176154 attr_is_enum .return_value = True
177- ioc_without_mapping . _create_and_link_write_pv ("PREFIX" , "PV" , "attr" , attribute )
155+ _create_and_link_write_pv ("PREFIX" , "PV" , "attr" , attribute )
178156
179157 get_output_record .assert_called_once_with (
180158 "PREFIX:PV" , attribute , on_update = mocker .ANY
@@ -237,28 +215,22 @@ def test_ioc(mocker: MockerFixture, mapping: Mapping):
237215 builder = mocker .patch ("fastcs.backends.epics.ioc.builder" )
238216 add_pvi_info = mocker .patch ("fastcs.backends.epics.ioc._add_pvi_info" )
239217 add_sub_controller_pvi_info = mocker .patch (
240- "fastcs.backends.epics.ioc.EpicsIOC. _add_sub_controller_pvi_info"
218+ "fastcs.backends.epics.ioc._add_sub_controller_pvi_info"
241219 )
242220
243221 EpicsIOC (DEVICE , mapping )
244222
245223 # Check records are created
246224 builder .boolIn .assert_called_once_with (f"{ DEVICE } :ReadBool" , ZNAM = "OFF" , ONAM = "ON" )
247- builder .longIn .assert_any_call (f"{ DEVICE } :ReadInt" , EGU = None )
248- builder .aIn .assert_called_once_with (
249- f"{ DEVICE } :ReadWriteFloat_RBV" , EGU = None , PREC = 2
250- )
225+ builder .longIn .assert_any_call (f"{ DEVICE } :ReadInt" )
226+ builder .aIn .assert_called_once_with (f"{ DEVICE } :ReadWriteFloat_RBV" , PREC = 2 )
251227 builder .aOut .assert_any_call (
252- f"{ DEVICE } :ReadWriteFloat" ,
253- always_update = True ,
254- on_update = mocker .ANY ,
255- EGU = None ,
256- PREC = 2 ,
228+ f"{ DEVICE } :ReadWriteFloat" , always_update = True , on_update = mocker .ANY , PREC = 2
257229 )
258- builder .longIn .assert_any_call (f"{ DEVICE } :BigEnum" , EGU = None )
259- builder .longIn .assert_any_call (f"{ DEVICE } :ReadWriteInt_RBV" , EGU = None )
230+ builder .longIn .assert_any_call (f"{ DEVICE } :BigEnum" )
231+ builder .longIn .assert_any_call (f"{ DEVICE } :ReadWriteInt_RBV" )
260232 builder .longOut .assert_called_with (
261- f"{ DEVICE } :ReadWriteInt" , always_update = True , on_update = mocker .ANY , EGU = None
233+ f"{ DEVICE } :ReadWriteInt" , always_update = True , on_update = mocker .ANY
262234 )
263235 builder .mbbIn .assert_called_once_with (
264236 f"{ DEVICE } :StringEnum_RBV" , ZRST = "red" , ONST = "green" , TWST = "blue"
@@ -351,27 +323,25 @@ def test_add_pvi_info_with_parent(mocker: MockerFixture):
351323 )
352324
353325
354- def test_add_sub_controller_pvi_info (
355- mocker : MockerFixture , ioc_without_mapping : EpicsIOC
356- ):
326+ def test_add_sub_controller_pvi_info (mocker : MockerFixture ):
357327 add_pvi_info = mocker .patch ("fastcs.backends.epics.ioc._add_pvi_info" )
358328 controller = mocker .MagicMock ()
359329 controller .path = []
360330 child = mocker .MagicMock ()
361331 child .path = ["Child" ]
362332 controller .get_sub_controllers .return_value = {"d" : child }
363333
364- ioc_without_mapping . _add_sub_controller_pvi_info (DEVICE , controller )
334+ _add_sub_controller_pvi_info (DEVICE , controller )
365335
366336 add_pvi_info .assert_called_once_with (
367337 f"{ DEVICE } :Child:PVI" , f"{ DEVICE } :PVI" , "child"
368338 )
369339
370340
371- def test_add_attr_pvi_info (mocker : MockerFixture , ioc_without_mapping : EpicsIOC ):
341+ def test_add_attr_pvi_info (mocker : MockerFixture ):
372342 record = mocker .MagicMock ()
373343
374- ioc_without_mapping . _add_attr_pvi_info (record , DEVICE , "attr" , "r" )
344+ _add_attr_pvi_info (record , DEVICE , "attr" , "r" )
375345
376346 record .add_info .assert_called_once_with (
377347 "Q:group" ,
@@ -417,9 +387,13 @@ def test_long_pv_names_discarded(mocker: MockerFixture):
417387
418388 short_pv_name = "attr_rw_short_name" .title ().replace ("_" , "" )
419389 builder .longOut .assert_called_once_with (
420- f"{ DEVICE } :{ short_pv_name } " , always_update = True , on_update = mocker .ANY , EGU = None
390+ f"{ DEVICE } :{ short_pv_name } " ,
391+ always_update = True ,
392+ on_update = mocker .ANY ,
393+ )
394+ builder .longIn .assert_called_once_with (
395+ f"{ DEVICE } :{ short_pv_name } _RBV" ,
421396 )
422- builder .longIn .assert_called_once_with (f"{ DEVICE } :{ short_pv_name } _RBV" , EGU = None )
423397
424398 long_pv_name = long_attr_name .title ().replace ("_" , "" )
425399 with pytest .raises (AssertionError ):
0 commit comments