4
4
5
5
from datetime import datetime
6
6
from typing import TYPE_CHECKING , Union , Optional
7
- from unittest .mock import sentinel
8
7
9
8
from decoy import Decoy , matchers
10
9
import pytest
11
10
11
+ from opentrons_shared_data .labware .labware_definition import LabwareDefinition2
12
+
12
13
from opentrons .protocol_engine .execution import EquipmentHandler , MovementHandler
13
14
from opentrons .hardware_control import HardwareControlAPI
14
15
from opentrons .types import DeckSlotName , Point
@@ -89,8 +90,17 @@ def heater_shaker_movement_flagger(decoy: Decoy) -> HeaterShakerMovementFlagger:
89
90
return decoy .mock (cls = HeaterShakerMovementFlagger )
90
91
91
92
93
+ @pytest .fixture
94
+ def labware_def (decoy : Decoy ) -> LabwareDefinition2 :
95
+ """Get a mocked out LabwareDefinition2 instance."""
96
+ return decoy .mock (cls = LabwareDefinition2 )
97
+
98
+
92
99
async def set_up_decoy_hardware_gripper (
93
- decoy : Decoy , ot3_hardware_api : OT3API , state_store : StateStore
100
+ decoy : Decoy ,
101
+ ot3_hardware_api : OT3API ,
102
+ state_store : StateStore ,
103
+ labware_def : LabwareDefinition2 ,
94
104
) -> None :
95
105
"""Shared hardware gripper decoy setup."""
96
106
decoy .when (state_store .config .use_virtual_gripper ).then_return (False )
@@ -111,9 +121,7 @@ async def set_up_decoy_hardware_gripper(
111
121
112
122
decoy .when (ot3_hardware_api .hardware_gripper .jaw_width ).then_return (89 )
113
123
114
- decoy .when (
115
- state_store .labware .get_grip_force (sentinel .my_teleporting_labware_def )
116
- ).then_return (100 )
124
+ decoy .when (state_store .labware .get_grip_force (labware_def )).then_return (100 )
117
125
118
126
decoy .when (state_store .labware .get_labware_offset ("new-offset-id" )).then_return (
119
127
LabwareOffset (
@@ -156,13 +164,16 @@ async def test_raise_error_if_gripper_pickup_failed(
156
164
state_store : StateStore ,
157
165
thermocycler_plate_lifter : ThermocyclerPlateLifter ,
158
166
ot3_hardware_api : OT3API ,
167
+ labware_def : LabwareDefinition2 ,
159
168
subject : LabwareMovementHandler ,
160
169
) -> None :
161
170
"""Test that the gripper position check is called at the right time."""
162
171
# This function should only be called when after the gripper opens,
163
172
# and then closes again. This is when we expect the labware to be
164
173
# in the gripper jaws.
165
- await set_up_decoy_hardware_gripper (decoy , ot3_hardware_api , state_store )
174
+ await set_up_decoy_hardware_gripper (
175
+ decoy , ot3_hardware_api , state_store , labware_def
176
+ )
166
177
assert ot3_hardware_api .hardware_gripper
167
178
168
179
user_pick_up_offset = Point (x = 123 , y = 234 , z = 345 )
@@ -175,9 +186,11 @@ async def test_raise_error_if_gripper_pickup_failed(
175
186
starting_location = DeckSlotLocation (slotName = DeckSlotName .SLOT_1 )
176
187
to_location = DeckSlotLocation (slotName = DeckSlotName .SLOT_2 )
177
188
189
+ labware_def .parameters .quirks = []
190
+
178
191
decoy .when (
179
192
state_store .labware .get_definition ("my-teleporting-labware" )
180
- ).then_return (sentinel . my_teleporting_labware_def )
193
+ ).then_return (labware_def )
181
194
182
195
mock_tc_context_manager = decoy .mock (name = "mock_tc_context_manager" )
183
196
decoy .when (
@@ -202,21 +215,19 @@ async def test_raise_error_if_gripper_pickup_failed(
202
215
203
216
decoy .when (
204
217
state_store .geometry .get_labware_grip_point (
205
- labware_definition = sentinel . my_teleporting_labware_def ,
218
+ labware_definition = labware_def ,
206
219
location = starting_location ,
207
220
)
208
221
).then_return (Point (101 , 102 , 119.5 ))
209
222
210
223
decoy .when (
211
224
state_store .geometry .get_labware_grip_point (
212
- labware_definition = sentinel . my_teleporting_labware_def , location = to_location
225
+ labware_definition = labware_def , location = to_location
213
226
)
214
227
).then_return (Point (201 , 202 , 219.5 ))
215
228
216
229
decoy .when (
217
- state_store .labware .get_gripper_width_specs (
218
- labware_definition = sentinel .my_teleporting_labware_def
219
- )
230
+ state_store .labware .get_gripper_width_specs (labware_definition = labware_def )
220
231
).then_return (GripSpecs (targetY = 100 , uncertaintyNarrower = 5 , uncertaintyWider = 10 ))
221
232
222
233
await subject .move_labware_with_gripper (
@@ -238,18 +249,21 @@ async def test_raise_error_if_gripper_pickup_failed(
238
249
expected_grip_width = 100 ,
239
250
grip_width_uncertainty_wider = 10 ,
240
251
grip_width_uncertainty_narrower = 5 ,
252
+ disable_geometry_grip_check = False ,
241
253
),
242
254
await ot3_hardware_api .grip (force_newtons = 100 ),
243
255
ot3_hardware_api .raise_error_if_gripper_pickup_failed (
244
256
expected_grip_width = 100 ,
245
257
grip_width_uncertainty_wider = 10 ,
246
258
grip_width_uncertainty_narrower = 5 ,
259
+ disable_geometry_grip_check = False ,
247
260
),
248
261
await ot3_hardware_api .grip (force_newtons = 100 ),
249
262
ot3_hardware_api .raise_error_if_gripper_pickup_failed (
250
263
expected_grip_width = 100 ,
251
264
grip_width_uncertainty_wider = 10 ,
252
265
grip_width_uncertainty_narrower = 5 ,
266
+ disable_geometry_grip_check = False ,
253
267
),
254
268
await ot3_hardware_api .disengage_axes ([Axis .Z_G ]),
255
269
await ot3_hardware_api .ungrip (),
@@ -292,6 +306,7 @@ async def test_move_labware_with_gripper(
292
306
thermocycler_plate_lifter : ThermocyclerPlateLifter ,
293
307
ot3_hardware_api : OT3API ,
294
308
subject : LabwareMovementHandler ,
309
+ labware_def : LabwareDefinition2 ,
295
310
from_location : Union [DeckSlotLocation , ModuleLocation , OnLabwareLocation ],
296
311
to_location : Union [DeckSlotLocation , ModuleLocation , OnLabwareLocation ],
297
312
slide_offset : Optional [Point ],
@@ -300,11 +315,14 @@ async def test_move_labware_with_gripper(
300
315
# TODO (spp, 2023-07-26): this test does NOT stub out movement waypoints in order to
301
316
# keep this as the semi-smoke test that it previously was. We should add a proper
302
317
# smoke test for gripper labware movement with actual labware and make this a unit test.
303
- await set_up_decoy_hardware_gripper (decoy , ot3_hardware_api , state_store )
318
+ labware_def .parameters .quirks = []
319
+ await set_up_decoy_hardware_gripper (
320
+ decoy , ot3_hardware_api , state_store , labware_def
321
+ )
304
322
305
323
decoy .when (
306
324
state_store .labware .get_definition ("my-teleporting-labware" )
307
- ).then_return (sentinel . my_teleporting_labware_def )
325
+ ).then_return (labware_def )
308
326
309
327
user_pick_up_offset = Point (x = 123 , y = 234 , z = 345 )
310
328
user_drop_offset = Point (x = 111 , y = 222 , z = 333 )
@@ -329,26 +347,22 @@ async def test_move_labware_with_gripper(
329
347
) # TODO: Is this used for anything? Could this have been a sentinel? Are sentinels appropriate here?
330
348
331
349
decoy .when (
332
- state_store .labware .get_dimensions (
333
- labware_definition = sentinel .my_teleporting_labware_def
334
- )
350
+ state_store .labware .get_dimensions (labware_definition = labware_def )
335
351
).then_return (Dimensions (x = 100 , y = 85 , z = 0 ))
336
352
337
353
decoy .when (
338
- state_store .labware .get_well_bbox (
339
- labware_definition = sentinel .my_teleporting_labware_def
340
- )
354
+ state_store .labware .get_well_bbox (labware_definition = labware_def )
341
355
).then_return (Dimensions (x = 99 , y = 80 , z = 1 ))
342
356
343
357
decoy .when (
344
358
state_store .geometry .get_labware_grip_point (
345
- labware_definition = sentinel . my_teleporting_labware_def ,
359
+ labware_definition = labware_def ,
346
360
location = from_location ,
347
361
)
348
362
).then_return (Point (101 , 102 , 119.5 ))
349
363
decoy .when (
350
364
state_store .geometry .get_labware_grip_point (
351
- labware_definition = sentinel . my_teleporting_labware_def , location = to_location
365
+ labware_definition = labware_def , location = to_location
352
366
)
353
367
).then_return (Point (201 , 202 , 219.5 ))
354
368
mock_tc_context_manager = decoy .mock (name = "mock_tc_context_manager" )
@@ -359,9 +373,7 @@ async def test_move_labware_with_gripper(
359
373
).then_return (mock_tc_context_manager )
360
374
361
375
decoy .when (
362
- state_store .labware .get_gripper_width_specs (
363
- labware_definition = sentinel .my_teleporting_labware_def
364
- )
376
+ state_store .labware .get_gripper_width_specs (labware_definition = labware_def )
365
377
).then_return (GripSpecs (targetY = 100 , uncertaintyNarrower = 5 , uncertaintyWider = 10 ))
366
378
367
379
expected_waypoints = [
0 commit comments