|
3 | 3 |
|
4 | 4 | import pytest |
5 | 5 |
|
| 6 | +from bec_lib.messages import ( |
| 7 | + AvailableBeamlineStatesMessage, |
| 8 | + ScanInterlockModifyStateTableMessage, |
| 9 | + ScanInterlockStateTableContent, |
| 10 | +) |
6 | 11 | from bec_server.actors.builtin_actor_manager import BuiltinActorManager |
7 | 12 |
|
8 | 13 |
|
@@ -148,3 +153,42 @@ def test_shutdown_stops_all_and_shuts_down_client(mocked_manager): |
148 | 153 | assert mock_stop.call_count == 2 |
149 | 154 |
|
150 | 155 | mock_client.shutdown.assert_called_once() |
| 156 | + |
| 157 | + |
| 158 | +def _req_msg(action, state_name, status): |
| 159 | + return { |
| 160 | + "data": ScanInterlockModifyStateTableMessage( |
| 161 | + action=action, state_name=state_name, status=status |
| 162 | + ) |
| 163 | + } |
| 164 | + |
| 165 | + |
| 166 | +INITIAL_STATES = {"initial_state_1": "valid", "initial_state_2": "valid"} |
| 167 | + |
| 168 | + |
| 169 | +@pytest.mark.parametrize( |
| 170 | + ["modification_request", "new_watched_states"], |
| 171 | + [ |
| 172 | + (_req_msg("add", "test_state", "valid"), {**INITIAL_STATES, "test_state": "valid"}), |
| 173 | + (_req_msg("remove", "initial_state_1", None), {"initial_state_2": "valid"}), |
| 174 | + (_req_msg("remove_all", None, None), {}), |
| 175 | + (_req_msg("remove", "missing_state", None), INITIAL_STATES), |
| 176 | + ], |
| 177 | +) |
| 178 | +def test_modify_interlock_table(mocked_manager, modification_request, new_watched_states): |
| 179 | + manager, mock_client = mocked_manager |
| 180 | + mock_client.connector.get.return_value = ScanInterlockStateTableContent( |
| 181 | + states_watched=INITIAL_STATES |
| 182 | + ) |
| 183 | + manager._modify_interlock_table(modification_request) |
| 184 | + assert mock_client.connector.set.call_args.args[1].states_watched == new_watched_states |
| 185 | + |
| 186 | + |
| 187 | +def test_handle_state_update(mocked_manager): |
| 188 | + manager, _ = mocked_manager |
| 189 | + manager._current_watched_states = lambda: {"test_state": "valid"} |
| 190 | + manager._modify_interlock_table = MagicMock() |
| 191 | + manager._handle_state_update({"data": AvailableBeamlineStatesMessage(states=[])}) |
| 192 | + manager._modify_interlock_table.assert_called_with( |
| 193 | + {"data": ScanInterlockModifyStateTableMessage(action="remove", state_name="test_state")} |
| 194 | + ) |
0 commit comments