Skip to content

Commit

Permalink
add cmd tests
Browse files Browse the repository at this point in the history
  • Loading branch information
caila-marashaj committed Jan 21, 2025
1 parent b2225cd commit e877d9d
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ..types import CurrentWell, DeckPoint

if TYPE_CHECKING:
from ..execution import MovementHandler, PipettingHandler, GantryMover
from ..execution import PipettingHandler, GantryMover
from ..resources import ModelUtils
from ..state.state import StateView
from ..notes import CommandNoteAdder
Expand Down Expand Up @@ -72,7 +72,6 @@ def __init__(
pipetting: PipettingHandler,
state_view: StateView,
hardware_api: HardwareControlAPI,
movement: MovementHandler,
command_note_adder: CommandNoteAdder,
model_utils: ModelUtils,
gantry_mover: GantryMover,
Expand All @@ -81,7 +80,6 @@ def __init__(
self._pipetting = pipetting
self._state_view = state_view
self._hardware_api = hardware_api
self._movement = movement
self._command_note_adder = command_note_adder
self._model_utils = model_utils
self._gantry_mover = gantry_mover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
)

if TYPE_CHECKING:
from ..execution import MovementHandler, PipettingHandler, GantryMover
from ..execution import PipettingHandler, GantryMover
from ..resources import ModelUtils
from ..state.state import StateView

Expand Down Expand Up @@ -79,14 +79,12 @@ class DispenseWhileTrackingImplementation(
def __init__(
self,
state_view: StateView,
movement: MovementHandler,
pipetting: PipettingHandler,
model_utils: ModelUtils,
gantry_mover: GantryMover,
**kwargs: object,
) -> None:
self._state_view = state_view
self._movement = movement
self._pipetting = pipetting
self._model_utils = model_utils
self._gantry_mover = gantry_mover
Expand Down
1 change: 1 addition & 0 deletions api/src/opentrons/protocol_engine/execution/pipetting.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ async def liquid_probe_in_place(
) -> float:
"""Detect liquid level."""
well_def = self._state_view.labware.get_well_definition(labware_id, well_name)
# raise ValueError(f"returning liquid height {well_def.depth}")
return well_def.depth

def _validate_tip_attached(self, pipette_id: str, command_name: str) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
CurrentAddressableArea,
AspiratedFluid,
FluidKind,
LiquidHandlingWellLocation,
WellOrigin,
WellOffset,
DeckPoint,
)
from opentrons.protocol_engine.state import update_types

Expand Down Expand Up @@ -71,6 +75,7 @@ def subject(


@pytest.mark.parametrize(
# add a well location
"location,stateupdateLabware,stateupdateWell",
[
(
Expand All @@ -82,8 +87,11 @@ def subject(
"labware-id-1",
"well-name-1",
),
(None, None, None),
(CurrentAddressableArea("pipette-id-abc", "addressable-area-1"), None, None),
(
CurrentAddressableArea("pipette-id-abc", "addressable-area-1"),
"funky-labware",
"funky-well",
),
],
)
async def test_aspirate_while_tracking_implementation(
Expand All @@ -99,8 +107,15 @@ async def test_aspirate_while_tracking_implementation(
stateupdateWell: str,
) -> None:
"""It should aspirate in place."""
well_location = LiquidHandlingWellLocation(
origin=WellOrigin.MENISCUS,
offset=WellOffset(x=0, y=0, z=1),
)
data = AspirateWhileTrackingParams(
pipetteId="pipette-id-abc",
labwareId=stateupdateLabware,
wellName=stateupdateWell,
wellLocation=well_location,
volume=123,
flowRate=1.234,
)
Expand Down Expand Up @@ -129,6 +144,8 @@ async def test_aspirate_while_tracking_implementation(
volume=123,
flow_rate=1.234,
command_note_adder=mock_command_note_adder,
labware_id=stateupdateLabware,
well_name=stateupdateWell,
)
).then_return(123)

Expand All @@ -142,7 +159,9 @@ async def test_aspirate_while_tracking_implementation(

if isinstance(location, CurrentWell):
assert result == SuccessData(
public=AspirateWhileTrackingResult(volume=123),
public=AspirateWhileTrackingResult(
volume=123, position=DeckPoint(x=1, y=2, z=3)
),
state_update=update_types.StateUpdate(
liquid_operated=update_types.LiquidOperatedUpdate(
labware_id=stateupdateLabware,
Expand All @@ -157,7 +176,9 @@ async def test_aspirate_while_tracking_implementation(
)
else:
assert result == SuccessData(
public=AspirateWhileTrackingResult(volume=123),
public=AspirateWhileTrackingResult(
volume=123, position=DeckPoint(x=1, y=2, z=3)
),
state_update=update_types.StateUpdate(
pipette_aspirated_fluid=update_types.PipetteAspiratedFluidUpdate(
pipette_id="pipette-id-abc",
Expand All @@ -176,8 +197,15 @@ async def test_handle_aspirate_while_tracking_request_not_ready_to_aspirate(
subject: AspirateWhileTrackingImplementation,
) -> None:
"""Should raise an exception for not ready to aspirate."""
well_location = LiquidHandlingWellLocation(
origin=WellOrigin.MENISCUS,
offset=WellOffset(x=0, y=0, z=1),
)
data = AspirateWhileTrackingParams(
pipetteId="pipette-id-abc",
labwareId="funky-labware",
wellName="funky-well",
wellLocation=well_location,
volume=123,
flowRate=1.234,
)
Expand Down Expand Up @@ -205,22 +233,36 @@ async def test_aspirate_raises_volume_error(
subject: AspirateWhileTrackingImplementation,
mock_command_note_adder: CommandNoteAdder,
gantry_mover: GantryMover,
state_store: StateStore,
) -> None:
"""Should raise an assertion error for volume larger than working volume."""
well_location = LiquidHandlingWellLocation(
origin=WellOrigin.MENISCUS,
offset=WellOffset(x=0, y=0, z=1),
)
data = AspirateWhileTrackingParams(
pipetteId="abc",
pipetteId="pipette-id-abc",
labwareId="funky-labware",
wellName="funky-well",
wellLocation=well_location,
volume=50,
flowRate=1.23,
)
decoy.when(await gantry_mover.get_position("abc")).then_return(Point(x=1, y=2, z=3))
decoy.when(pipetting.get_is_ready_to_aspirate(pipette_id="abc")).then_return(True)
decoy.when(await gantry_mover.get_position("pipette-id-abc")).then_return(
Point(x=1, y=2, z=3)
)
decoy.when(
pipetting.get_is_ready_to_aspirate(pipette_id="pipette-id-abc")
).then_return(True)

decoy.when(
await pipetting.aspirate_while_tracking(
pipette_id="abc",
pipette_id="pipette-id-abc",
volume=50,
flow_rate=1.23,
command_note_adder=mock_command_note_adder,
labware_id="funky-labware",
well_name="funky-well",
)
).then_raise(AssertionError("blah blah"))

Expand Down Expand Up @@ -276,8 +318,15 @@ async def test_overpressure_error(
stateupdateLabware, stateupdateWell, "pipette-id"
)
).then_return(["A3", "A4"])
well_location = LiquidHandlingWellLocation(
origin=WellOrigin.MENISCUS,
offset=WellOffset(x=0, y=0, z=1),
)
data = AspirateWhileTrackingParams(
pipetteId=pipette_id,
labwareId="funky-labware",
wellName="funky-well",
wellLocation=well_location,
volume=50,
flowRate=1.23,
)
Expand All @@ -292,6 +341,8 @@ async def test_overpressure_error(
volume=50,
flow_rate=1.23,
command_note_adder=mock_command_note_adder,
labware_id="funky-labware",
well_name="funky-well",
),
).then_raise(PipetteOverpressureError())

Expand Down
Loading

0 comments on commit e877d9d

Please sign in to comment.