Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-kulkarni committed Jul 1, 2024
1 parent 5b59440 commit 48d6d10
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
6 changes: 5 additions & 1 deletion api/src/opentrons/protocol_api/core/engine/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,11 @@ def find_liquid_level(self, well_core: WellCore) -> float:
pipetteId=self.pipette_id,
)
)
# result will either be a LiquidProbeResult or a LiquidNotFoundError
if (
result is None
): # this should probably only happen in testing with mock components
return 0
# for general cases, result will either be a float > 0 or an error
try:
return float(result.z_position)
except Exception:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1288,3 +1288,31 @@ def test_configure_for_volume_post_219(
)
)
)


@pytest.mark.parametrize("version", versions_at_or_above(APIVersion(2, 20)))
def test_find_liquid_level(
decoy: Decoy,
mock_engine_client: EngineClient,
mock_protocol_core: ProtocolCore,
subject: InstrumentCore,
version: APIVersion,
) -> None:
"""It should raise an exception on an empty well."""
well_core = WellCore(
name="my cool well", labware_id="123abc", engine_client=mock_engine_client
)
result = subject.find_liquid_level(well_core)
assert result == 0
decoy.verify(
mock_engine_client.execute_command_without_recovery(
cmd.LiquidProbeParams(
pipetteId=subject.pipette_id,
wellLocation=WellLocation(
origin=WellOrigin.TOP, offset=WellOffset(x=0, y=0, z=0)
),
wellName=well_core.get_name(),
labwareId=well_core.labware_id,
)
)
)
55 changes: 55 additions & 0 deletions api/tests/opentrons/protocol_api/test_instrument_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections import OrderedDict
import inspect

from opentrons.protocol_engine.commands.pipetting_common import LiquidNotFoundError
import pytest
from pytest_lazyfixture import lazy_fixture # type: ignore[import-untyped]
from decoy import Decoy
Expand Down Expand Up @@ -1268,3 +1269,57 @@ def test_aspirate_0_volume_means_aspirate_nothing(
),
times=1,
)


@pytest.mark.parametrize("api_version", [APIVersion(2, 20)])
def test_detect_liquid(
decoy: Decoy,
mock_instrument_core: InstrumentCore,
subject: InstrumentContext,
mock_protocol_core: ProtocolCore,
) -> None:
"""It should only return booleans. Not raise an exception."""
mock_well = decoy.mock(cls=Well)
decoy.when(mock_instrument_core.find_liquid_level(mock_well._core)).then_raise(
Exception(LiquidNotFoundError)
)
result = subject.detect_liquid(mock_well)
assert isinstance(result, bool)


@pytest.mark.parametrize("api_version", [APIVersion(2, 20)])
def test_require_liquid(
decoy: Decoy,
mock_instrument_core: InstrumentCore,
subject: InstrumentContext,
mock_protocol_core: ProtocolCore,
) -> None:
"""It should raise an exception when called on an."""
mock_well = decoy.mock(cls=Well)
decoy.when(mock_instrument_core.find_liquid_level(mock_well._core)).then_raise(
Exception(LiquidNotFoundError)
)
try:
subject.require_liquid(mock_well)
assert False
except Exception:
assert True


@pytest.mark.parametrize("api_version", [APIVersion(2, 20)])
def get_liquid_height(
decoy: Decoy,
mock_instrument_core: InstrumentCore,
subject: InstrumentContext,
mock_protocol_core: ProtocolCore,
) -> None:
"""It should return 0 on an empty well."""
mock_well = decoy.mock(cls=Well)
decoy.when(mock_instrument_core.find_liquid_level(mock_well._core)).then_raise(
Exception(LiquidNotFoundError)
)
try:
result = subject.get_liquid_height(mock_well)
assert False
except Exception:
assert result == 0

0 comments on commit 48d6d10

Please sign in to comment.