|
10 | 10 | _add_attr_pvi_info, |
11 | 11 | _add_pvi_info, |
12 | 12 | _add_sub_controller_pvi_info, |
| 13 | + _create_and_link_read_pv, |
| 14 | + _create_and_link_write_pv, |
13 | 15 | _get_input_record, |
14 | 16 | _get_output_record, |
15 | 17 | ) |
|
25 | 27 | ONOFF_STATES = {"ZRST": "disabled", "ONST": "enabled"} |
26 | 28 |
|
27 | 29 |
|
| 30 | +@pytest.mark.asyncio |
| 31 | +async def test_create_and_link_read_pv(mocker: MockerFixture): |
| 32 | + 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") |
| 34 | + attr_is_enum = mocker.patch("fastcs.backends.epics.ioc.attr_is_enum") |
| 35 | + record = get_input_record.return_value |
| 36 | + |
| 37 | + attribute = mocker.MagicMock() |
| 38 | + |
| 39 | + attr_is_enum.return_value = False |
| 40 | + _create_and_link_read_pv("PREFIX", "PV", "attr", attribute) |
| 41 | + |
| 42 | + get_input_record.assert_called_once_with("PREFIX:PV", attribute) |
| 43 | + add_attr_pvi_info.assert_called_once_with(record, "PREFIX", "attr", "r") |
| 44 | + |
| 45 | + # Extract the callback generated and set in the function and call it |
| 46 | + attribute.set_update_callback.assert_called_once_with(mocker.ANY) |
| 47 | + record_set_callback = attribute.set_update_callback.call_args[0][0] |
| 48 | + await record_set_callback(1) |
| 49 | + |
| 50 | + record.set.assert_called_once_with(1) |
| 51 | + |
| 52 | + |
| 53 | +@pytest.mark.asyncio |
| 54 | +async def test_create_and_link_read_pv_enum(mocker: MockerFixture): |
| 55 | + get_input_record = mocker.patch("fastcs.backends.epics.ioc._get_input_record") |
| 56 | + add_attr_pvi_info = mocker.patch("fastcs.backends.epics.ioc._add_attr_pvi_info") |
| 57 | + attr_is_enum = mocker.patch("fastcs.backends.epics.ioc.attr_is_enum") |
| 58 | + record = get_input_record.return_value |
| 59 | + enum_value_to_index = mocker.patch("fastcs.backends.epics.ioc.enum_value_to_index") |
| 60 | + |
| 61 | + attribute = mocker.MagicMock() |
| 62 | + |
| 63 | + attr_is_enum.return_value = True |
| 64 | + _create_and_link_read_pv("PREFIX", "PV", "attr", attribute) |
| 65 | + |
| 66 | + get_input_record.assert_called_once_with("PREFIX:PV", attribute) |
| 67 | + add_attr_pvi_info.assert_called_once_with(record, "PREFIX", "attr", "r") |
| 68 | + |
| 69 | + # Extract the callback generated and set in the function and call it |
| 70 | + attribute.set_update_callback.assert_called_once_with(mocker.ANY) |
| 71 | + record_set_callback = attribute.set_update_callback.call_args[0][0] |
| 72 | + await record_set_callback(1) |
| 73 | + |
| 74 | + enum_value_to_index.assert_called_once_with(attribute, 1) |
| 75 | + record.set.assert_called_once_with(enum_value_to_index.return_value) |
| 76 | + |
| 77 | + |
28 | 78 | @pytest.mark.parametrize( |
29 | 79 | "attribute,record_type,kwargs", |
30 | 80 | ( |
@@ -57,6 +107,75 @@ def test_get_input_record_raises(mocker: MockerFixture): |
57 | 107 | _get_input_record("PV", mocker.MagicMock()) |
58 | 108 |
|
59 | 109 |
|
| 110 | +@pytest.mark.asyncio |
| 111 | +async def test_create_and_link_write_pv(mocker: MockerFixture): |
| 112 | + get_output_record = mocker.patch("fastcs.backends.epics.ioc._get_output_record") |
| 113 | + add_attr_pvi_info = mocker.patch("fastcs.backends.epics.ioc._add_attr_pvi_info") |
| 114 | + attr_is_enum = mocker.patch("fastcs.backends.epics.ioc.attr_is_enum") |
| 115 | + record = get_output_record.return_value |
| 116 | + |
| 117 | + attribute = mocker.MagicMock() |
| 118 | + attribute.process_without_display_update = mocker.AsyncMock() |
| 119 | + |
| 120 | + attr_is_enum.return_value = False |
| 121 | + _create_and_link_write_pv("PREFIX", "PV", "attr", attribute) |
| 122 | + |
| 123 | + get_output_record.assert_called_once_with( |
| 124 | + "PREFIX:PV", attribute, on_update=mocker.ANY |
| 125 | + ) |
| 126 | + add_attr_pvi_info.assert_called_once_with(record, "PREFIX", "attr", "w") |
| 127 | + |
| 128 | + # Extract the write update callback generated and set in the function and call it |
| 129 | + attribute.set_write_display_callback.assert_called_once_with(mocker.ANY) |
| 130 | + write_display_callback = attribute.set_write_display_callback.call_args[0][0] |
| 131 | + await write_display_callback(1) |
| 132 | + |
| 133 | + record.set.assert_called_once_with(1, process=False) |
| 134 | + |
| 135 | + # Extract the on update callback generated and set in the function and call it |
| 136 | + on_update_callback = get_output_record.call_args[1]["on_update"] |
| 137 | + await on_update_callback(1) |
| 138 | + |
| 139 | + attribute.process_without_display_update.assert_called_once_with(1) |
| 140 | + |
| 141 | + |
| 142 | +@pytest.mark.asyncio |
| 143 | +async def test_create_and_link_write_pv_enum(mocker: MockerFixture): |
| 144 | + get_output_record = mocker.patch("fastcs.backends.epics.ioc._get_output_record") |
| 145 | + add_attr_pvi_info = mocker.patch("fastcs.backends.epics.ioc._add_attr_pvi_info") |
| 146 | + attr_is_enum = mocker.patch("fastcs.backends.epics.ioc.attr_is_enum") |
| 147 | + enum_value_to_index = mocker.patch("fastcs.backends.epics.ioc.enum_value_to_index") |
| 148 | + enum_index_to_value = mocker.patch("fastcs.backends.epics.ioc.enum_index_to_value") |
| 149 | + record = get_output_record.return_value |
| 150 | + |
| 151 | + attribute = mocker.MagicMock() |
| 152 | + attribute.process_without_display_update = mocker.AsyncMock() |
| 153 | + |
| 154 | + attr_is_enum.return_value = True |
| 155 | + _create_and_link_write_pv("PREFIX", "PV", "attr", attribute) |
| 156 | + |
| 157 | + get_output_record.assert_called_once_with( |
| 158 | + "PREFIX:PV", attribute, on_update=mocker.ANY |
| 159 | + ) |
| 160 | + add_attr_pvi_info.assert_called_once_with(record, "PREFIX", "attr", "w") |
| 161 | + |
| 162 | + # Extract the write update callback generated and set in the function and call it |
| 163 | + attribute.set_write_display_callback.assert_called_once_with(mocker.ANY) |
| 164 | + write_display_callback = attribute.set_write_display_callback.call_args[0][0] |
| 165 | + await write_display_callback(1) |
| 166 | + |
| 167 | + enum_value_to_index.assert_called_once_with(attribute, 1) |
| 168 | + record.set.assert_called_once_with(enum_value_to_index.return_value, process=False) |
| 169 | + |
| 170 | + # Extract the on update callback generated and set in the function and call it |
| 171 | + on_update_callback = get_output_record.call_args[1]["on_update"] |
| 172 | + await on_update_callback(1) |
| 173 | + |
| 174 | + attribute.process_without_display_update.assert_called_once_with( |
| 175 | + enum_index_to_value.return_value |
| 176 | + ) |
| 177 | + |
| 178 | + |
60 | 179 | @pytest.mark.parametrize( |
61 | 180 | "attribute,record_type,kwargs", |
62 | 181 | ( |
|
0 commit comments