Skip to content

Commit

Permalink
broken test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-kulkarni committed Jul 1, 2024
1 parent f0ac17a commit 3902a9c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
7 changes: 4 additions & 3 deletions api/src/opentrons/protocol_api/core/engine/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from opentrons.protocol_engine.clients import SyncClient as EngineClient
from opentrons.protocols.api_support.definitions import MAX_SUPPORTED_VERSION

from opentrons_shared_data.errors.exceptions import PipetteLiquidNotFoundError
from opentrons_shared_data.pipette.dev_types import PipetteNameType
from opentrons.protocol_api._nozzle_layout import NozzleLayout
from opentrons.hardware_control.nozzle_manager import NozzleConfigurationType
Expand Down Expand Up @@ -862,8 +863,8 @@ def find_liquid_level(self, well_core: WellCore) -> float:
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
# for general cases, result will either be a float > 0 or a PipetteLiquidNotFoundError
try:
return float(result.z_position)
except Exception:
raise BaseException(result)
except KeyError:
raise PipetteLiquidNotFoundError()
11 changes: 6 additions & 5 deletions api/src/opentrons/protocol_api/instrument_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from opentrons_shared_data.errors.exceptions import (
CommandPreconditionViolated,
CommandParameterLimitViolated,
PipetteLiquidNotFoundError,
UnexpectedTipRemovalError,
)
from opentrons.protocol_engine.errors.exceptions import WellDoesNotExistError
Expand Down Expand Up @@ -2055,14 +2056,14 @@ def detect_liquid(self, well: labware.Well) -> bool:
:returns: A boolean.
"""
if well is None:
raise WellDoesNotExistError()
raise WellDoesNotExistError() from BaseException

try:
height = self._core.find_liquid_level(well._core)
if height > 0:
return True
return False # it should never get here
except Exception:
except PipetteLiquidNotFoundError:
return False

@requires_version(2, 20)
Expand All @@ -2072,11 +2073,11 @@ def require_liquid(self, well: labware.Well) -> None:
:returns: None.
"""
if well is None:
raise WellDoesNotExistError()
raise WellDoesNotExistError("Well type was none.")

try:
self._core.find_liquid_level(well._core)
except Exception as e:
except PipetteLiquidNotFoundError as e:
raise e

@requires_version(2, 20)
Expand All @@ -2091,5 +2092,5 @@ def get_liquid_height(self, well: labware.Well) -> float:
try:
height = self._core.find_liquid_level(well._core)
return float(height)
except Exception:
except PipetteLiquidNotFoundError:
return 0
15 changes: 7 additions & 8 deletions api/tests/opentrons/protocol_api/test_instrument_context.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Tests for the InstrumentContext public interface."""
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 @@ -40,6 +38,7 @@

from opentrons_shared_data.errors.exceptions import (
CommandPreconditionViolated,
PipetteLiquidNotFoundError,
)


Expand Down Expand Up @@ -1281,7 +1280,7 @@ def test_detect_liquid(
"""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)
Exception(PipetteLiquidNotFoundError)
)
result = subject.detect_liquid(mock_well)
assert isinstance(result, bool)
Expand All @@ -1297,17 +1296,17 @@ def test_require_liquid(
"""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)
Exception(PipetteLiquidNotFoundError)
)
try:
subject.require_liquid(mock_well)
assert False
except Exception:
except PipetteLiquidNotFoundError:
assert True


@pytest.mark.parametrize("api_version", [APIVersion(2, 20)])
def get_liquid_height(
def test_get_liquid_height(
decoy: Decoy,
mock_instrument_core: InstrumentCore,
subject: InstrumentContext,
Expand All @@ -1316,10 +1315,10 @@ def get_liquid_height(
"""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)
Exception(PipetteLiquidNotFoundError)
)
try:
result = subject.get_liquid_height(mock_well)
assert False
except Exception:
except PipetteLiquidNotFoundError:
assert result == 0

0 comments on commit 3902a9c

Please sign in to comment.