From d887d037bef9395fd05f92c502186cedbb4ee4f5 Mon Sep 17 00:00:00 2001 From: Laura Cox <31892318+Laura-Danielle@users.noreply.github.com> Date: Thu, 29 Feb 2024 21:36:13 +0200 Subject: [PATCH] fix(api): Add proper tip mismatch for flex (#14563) # Overview Turns out we never actually updated the tiprack mismatch warning in the python api to handle flex pipette capabilities. Adds in the proper tip types and a test. --- .../protocols/api_support/instrument.py | 19 ++++++---- .../protocols/api_support/test_instrument.py | 36 ++++++++++++++++++- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/api/src/opentrons/protocols/api_support/instrument.py b/api/src/opentrons/protocols/api_support/instrument.py index 297cd3d456b..d6d9613b1cf 100644 --- a/api/src/opentrons/protocols/api_support/instrument.py +++ b/api/src/opentrons/protocols/api_support/instrument.py @@ -73,11 +73,14 @@ def tip_length_for( VALID_PIP_TIPRACK_VOL = { - "p10": [10, 20], - "p20": [10, 20], - "p50": [50, 200, 300], - "p300": [200, 300], - "p1000": [1000], + "FLEX": {"p50": [50], "p1000": [50, 200, 1000]}, + "OT2": { + "p10": [10, 20], + "p20": [10, 20], + "p50": [50, 200, 300], + "p300": [200, 300], + "p1000": [1000], + }, } @@ -92,7 +95,11 @@ def validate_tiprack( # tipracks to the pipette as a refactor if tip_rack.uri.startswith("opentrons/"): tiprack_vol = tip_rack.wells()[0].max_volume - valid_vols = VALID_PIP_TIPRACK_VOL[instrument_name.split("_")[0]] + instr_metadata = instrument_name.split("_") + gen_lookup = ( + "FLEX" if ("flex" in instr_metadata or "96" in instr_metadata) else "OT2" + ) + valid_vols = VALID_PIP_TIPRACK_VOL[gen_lookup][instrument_name.split("_")[0]] if tiprack_vol not in valid_vols: log.warning( f"The pipette {instrument_name} and its tip rack {tip_rack.load_name}" diff --git a/api/tests/opentrons/protocols/api_support/test_instrument.py b/api/tests/opentrons/protocols/api_support/test_instrument.py index 3e8391cc512..304ef97f0a6 100644 --- a/api/tests/opentrons/protocols/api_support/test_instrument.py +++ b/api/tests/opentrons/protocols/api_support/test_instrument.py @@ -1,6 +1,11 @@ import pytest +import logging +from typing import Optional from opentrons.protocol_api import ProtocolContext -from opentrons.protocols.api_support.instrument import validate_takes_liquid +from opentrons.protocols.api_support.instrument import ( + validate_takes_liquid, + validate_tiprack, +) from opentrons.types import Location, Point @@ -125,3 +130,32 @@ def test_validate_takes_liquid_adapter(ctx): reject_module=False, reject_adapter=True, ) + + +@pytest.mark.parametrize( + argnames=["pipette_name", "log_value"], + argvalues=[ + ["p1000_96", None], + [ + "p50_single_flex", + "The pipette p50_single_flex and its tip rack opentrons_flex_96_tiprack_200ul appear to be mismatched. Please check your protocol.", + ], + [ + "p20_single_gen2", + "The pipette p20_single_gen2 and its tip rack opentrons_flex_96_tiprack_200ul appear to be mismatched. Please check your protocol.", + ], + ], +) +def test_validate_tiprack( + ctx: ProtocolContext, caplog, pipette_name: str, log_value: Optional[str] +): + tip_rack = ctx.load_labware("opentrons_flex_96_tiprack_200ul", 2) + + with caplog.at_level(logging.WARNING): + log = logging.getLogger(__name__) + validate_tiprack(pipette_name, tip_rack, log=log) + + if log_value: + assert caplog.messages[0] == log_value + else: + assert caplog.records == []