@@ -69,6 +69,7 @@ async def test_initialize(
69
69
assert runs_publisher ._engine_state_slice .current_command is None
70
70
assert runs_publisher ._engine_state_slice .recovery_target_command is None
71
71
assert runs_publisher ._engine_state_slice .state_summary_status is None
72
+ assert runs_publisher ._engine_state_slice .state_summary_labware_offset_count is None
72
73
73
74
notification_client .publish_advise_refetch .assert_any_call (topic = topics .RUNS )
74
75
notification_client .publish_advise_refetch .assert_any_call (
@@ -171,10 +172,10 @@ async def test_handle_recovery_target_command_change(
171
172
)
172
173
173
174
174
- async def test_handle_engine_status_change (
175
+ async def test_handle_relevant_engine_change (
175
176
runs_publisher : RunsPublisher , notification_client : Mock
176
177
) -> None :
177
- """It should handle engine status changes appropriately."""
178
+ """It should handle relevant engine changes appropriately."""
178
179
runs_publisher .start_publishing_for_run (
179
180
run_id = "1234" ,
180
181
get_current_command = lambda _ : make_command_pointer ("command1" ),
@@ -189,26 +190,68 @@ async def test_handle_engine_status_change(
189
190
190
191
runs_publisher ._run_hooks .run_id = "1234"
191
192
runs_publisher ._run_hooks .get_state_summary = MagicMock (
192
- return_value = MagicMock (status = EngineStatus .IDLE )
193
+ return_value = MagicMock (status = EngineStatus .IDLE , labwareOffsets = [] )
193
194
)
194
195
runs_publisher ._engine_state_slice .state_summary_status = EngineStatus .IDLE
196
+ runs_publisher ._engine_state_slice .state_summary_labware_offset_count = 0
195
197
196
- await runs_publisher ._handle_engine_status_change ()
198
+ await runs_publisher ._handle_relevant_engine_change ()
197
199
198
200
assert notification_client .publish_advise_refetch .call_count == 2
199
201
200
202
runs_publisher ._run_hooks .get_state_summary .return_value = MagicMock (
201
- status = EngineStatus .RUNNING
203
+ status = EngineStatus .RUNNING , labwareOffsets = []
202
204
)
203
205
204
- await runs_publisher ._handle_engine_status_change ()
206
+ await runs_publisher ._handle_relevant_engine_change ()
205
207
206
208
notification_client .publish_advise_refetch .assert_any_call (topic = topics .RUNS )
207
209
notification_client .publish_advise_refetch .assert_any_call (
208
210
topic = f"{ topics .RUNS } /1234"
209
211
)
210
212
211
213
214
+ async def test_handle_labware_offset_count_change (
215
+ runs_publisher : RunsPublisher , notification_client : Mock
216
+ ) -> None :
217
+ """It should handle labware offset count changes appropriately."""
218
+ runs_publisher .start_publishing_for_run (
219
+ run_id = "1234" ,
220
+ get_current_command = lambda _ : make_command_pointer ("command1" ),
221
+ get_recovery_target_command = AsyncMock (),
222
+ get_state_summary = AsyncMock (),
223
+ )
224
+
225
+ # todo(mm, 2024-05-21): We should test through the public interface of the subject,
226
+ # not through its private attributes.
227
+ assert runs_publisher ._run_hooks
228
+ assert runs_publisher ._engine_state_slice
229
+
230
+ initial_offsets = ["offset1" , "offset2" ]
231
+ runs_publisher ._run_hooks .run_id = "1234"
232
+ runs_publisher ._run_hooks .get_state_summary = MagicMock (
233
+ return_value = MagicMock (status = EngineStatus .IDLE , labwareOffsets = initial_offsets )
234
+ )
235
+ runs_publisher ._engine_state_slice .state_summary_status = EngineStatus .IDLE
236
+ runs_publisher ._engine_state_slice .state_summary_labware_offset_count = 2
237
+
238
+ await runs_publisher ._handle_relevant_engine_change ()
239
+ assert notification_client .publish_advise_refetch .call_count == 2
240
+
241
+ new_offsets = ["offset1" , "offset2" , "offset3" ]
242
+ runs_publisher ._run_hooks .get_state_summary .return_value = MagicMock (
243
+ status = EngineStatus .IDLE , labwareOffsets = new_offsets
244
+ )
245
+
246
+ await runs_publisher ._handle_relevant_engine_change ()
247
+
248
+ notification_client .publish_advise_refetch .assert_any_call (topic = topics .RUNS )
249
+ notification_client .publish_advise_refetch .assert_any_call (
250
+ topic = f"{ topics .RUNS } /1234"
251
+ )
252
+ assert runs_publisher ._engine_state_slice .state_summary_labware_offset_count == 3
253
+
254
+
212
255
async def test_publish_pre_serialized_commannds_notif (
213
256
runs_publisher : RunsPublisher , notification_client : Mock
214
257
) -> None :
0 commit comments