Skip to content

Commit

Permalink
fixed small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
sanni-t committed Jan 6, 2025
1 parent d03069b commit 580f4da
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
17 changes: 12 additions & 5 deletions api/src/opentrons/protocol_api/core/engine/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ def load_liquid_class(

liquid_class_record = LiquidClassRecord(
liquidClassName=liquid_class.name,
pipetteModel=self.get_model(), # TODO: verify this is the correct 'model' to use
pipetteModel=pipette_load_name, # TODO: verify this is the correct 'model' to use
tiprack=tiprack_uri,
aspirate=transfer_props.aspirate.as_shared_data_model(),
singleDispense=transfer_props.dispense.as_shared_data_model(),
Expand All @@ -923,14 +923,16 @@ def get_next_tip(
self, tip_racks: List[LabwareCore], starting_well: Optional[str]
) -> Optional[NextTipInfo]:
"""Get the next tip to pick up."""
next_tip_info = self._engine_client.execute_command_without_recovery(
result = self._engine_client.execute_command_without_recovery(
cmd.GetNextTipParams(
pipetteId=self._pipette_id,
labwareIds=[tip_rack.labware_id for tip_rack in tip_racks],
startingTipWell=starting_well,
)
)
return next_tip_info if isinstance(next_tip_info, NextTipInfo) else None
return (
result.nextTipInfo if isinstance(result.nextTipInfo, NextTipInfo) else None
)

def transfer_liquid( # noqa: C901
self,
Expand Down Expand Up @@ -1001,7 +1003,7 @@ def _pick_up_tip() -> None:
tip_racks=[core for loc, core in tip_racks],
starting_well=None,
)
if not next_tip:
if next_tip is None:
raise RuntimeError(
f"No tip available among {tip_racks} for this transfer."
)
Expand Down Expand Up @@ -1081,7 +1083,12 @@ def _get_location_and_well_core_from_next_tip_info(
tiprack_loc = [
loc for loc, lw_core in tip_racks if lw_core == tiprack_labware_core
]
return _TipInfo(tiprack_loc[0], tiprack_labware_core.get_uri(), tip_well)

return _TipInfo(
Location(tip_well.get_top(0), tiprack_loc[0].labware),
tiprack_labware_core.get_uri(),
tip_well,
)

def aspirate_liquid_class(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from opentrons.hardware_control import SyncHardwareAPI
from opentrons.hardware_control.dev_types import PipetteDict
from opentrons.protocol_api._liquid_properties import TransferProperties
from opentrons.protocol_api.core.engine import transfer_components_executor
from opentrons.protocol_api.core.engine import transfer_components_executor, LabwareCore
from opentrons.protocol_api.core.engine.transfer_components_executor import (
TransferComponentsExecutor,
TransferType,
Expand All @@ -38,6 +38,7 @@
)
from opentrons.protocol_engine import commands as cmd
from opentrons.protocol_engine.clients.sync_client import SyncClient
from opentrons.protocol_engine.commands import GetNextTipResult
from opentrons.protocol_engine.errors.exceptions import TipNotAttachedError
from opentrons.protocol_engine.clients import SyncClient as EngineClient
from opentrons.protocol_engine.types import (
Expand All @@ -49,6 +50,9 @@
ColumnNozzleLayoutConfiguration,
AddressableOffsetVector,
LiquidClassRecord,
NextTipInfo,
NoTipAvailable,
NoTipReason,
)
from opentrons.protocol_api.disposal_locations import (
TrashBin,
Expand Down Expand Up @@ -109,6 +113,15 @@ def patch_mock_check_valid_volume_parameters(
monkeypatch.setattr(tx_commons, "check_valid_volume_parameters", mock)


@pytest.fixture(autouse=True)
def patch_mock_expand_for_volume_constraints(
decoy: Decoy, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Replace tx_commons.expand_for_volume_constraints() with a mock."""
mock = decoy.mock(func=tx_commons.expand_for_volume_constraints)
monkeypatch.setattr(tx_commons, "expand_for_volume_constraints", mock)


@pytest.fixture
def mock_transfer_components_executor(
decoy: Decoy,
Expand Down Expand Up @@ -1744,3 +1757,52 @@ def test_dispense_liquid_class(
),
)
assert result == [LiquidAndAirGapPair(air_gap=444, liquid=333)]


def test_get_next_tip(
decoy: Decoy,
mock_engine_client: EngineClient,
subject: InstrumentCore,
) -> None:
"""It should return the next tip result."""
tip_racks = [decoy.mock(cls=LabwareCore)]
expected_next_tip = NextTipInfo(labwareId="1234", tipStartingWell="BAR")
decoy.when(tip_racks[0].labware_id).then_return("tiprack-id")
decoy.when(
mock_engine_client.execute_command_without_recovery(
cmd.GetNextTipParams(
pipetteId="abc123", labwareIds=["tiprack-id"], startingTipWell="F00"
)
)
).then_return(GetNextTipResult(nextTipInfo=expected_next_tip))
result = subject.get_next_tip(
tip_racks=tip_racks,
starting_well="F00",
)
assert result == expected_next_tip


def test_get_next_tip_when_no_tip_available(
decoy: Decoy,
mock_engine_client: EngineClient,
subject: InstrumentCore,
) -> None:
"""It should return None when there's no next tip available."""
tip_racks = [decoy.mock(cls=LabwareCore)]
decoy.when(tip_racks[0].labware_id).then_return("tiprack-id")
decoy.when(
mock_engine_client.execute_command_without_recovery(
cmd.GetNextTipParams(
pipetteId="abc123", labwareIds=["tiprack-id"], startingTipWell="F00"
)
)
).then_return(
GetNextTipResult(
nextTipInfo=NoTipAvailable(noTipReason=NoTipReason.NO_AVAILABLE_TIPS)
)
)
result = subject.get_next_tip(
tip_racks=tip_racks,
starting_well="F00",
)
assert result is None

0 comments on commit 580f4da

Please sign in to comment.