Skip to content

Commit

Permalink
fix(api): teardown non-existing tip detector shouldn't raise an error (
Browse files Browse the repository at this point in the history
…#13921)

* either return a TipDetector or raise an error
* fix tests
  • Loading branch information
ahiuchingau authored Nov 6, 2023
1 parent 02ba7e5 commit 52dc84a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,17 @@ def _unsubscribe() -> None:
unsub()
self.set_unsub(mount, None)

detector = self.get_detector(mount)
if detector:
_unsubscribe()
try:
detector = self.get_detector(mount)
detector.cleanup()
except TipDetectorNotFound:
pass
finally:
_unsubscribe()
self.set_detector(mount, None)

async def build_detector(self, mount: OT3Mount, sensor_count: int) -> None:
assert self.get_detector(mount) is None
assert self._detectors.get(self._get_key(mount), None) is None
# set up and subscribe to the detector
d = TipDetector(self._messenger, _mount_to_node(mount), sensor_count)
# listens to the detector so we can immediately notify listeners
Expand All @@ -106,7 +109,7 @@ def _handle_tip_update(
def current_tip_state(self, mount: OT3Mount) -> Optional[bool]:
state = self._last_state[self._get_key(mount)]
if state is None:
log.warning("Tip state for {mount} is unknown")
log.warning(f"Tip state for {mount} is unknown")
return state

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
types as tp_types,
)
from opentrons_hardware.firmware_bindings.constants import SensorId
from opentrons_hardware.drivers import can_bus
from opentrons_hardware.drivers.can_bus import CanMessenger

from opentrons_shared_data.errors.exceptions import UnmatchedTipPresenceStates


@pytest.fixture
def can_messenger(decoy: Decoy) -> can_bus.CanMessenger:
def can_messenger(decoy: Decoy) -> CanMessenger:
"""Build a decoyed can messenger."""
return decoy.mock(cls=can_bus.CanMessenger)
return decoy.mock(cls=CanMessenger)


@pytest.fixture
Expand Down Expand Up @@ -58,7 +58,7 @@ def tip_detector_controller(

@pytest.fixture
async def subject(
can_messenger: can_bus.CanMessenger,
can_messenger: CanMessenger,
tip_detector: TipDetector,
) -> AsyncIterator[TipPresenceManager]:
"""Build a test subject using decoyed can messenger and tip detector."""
Expand Down
13 changes: 9 additions & 4 deletions api/tests/opentrons/hardware_control/test_instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def dummy_instruments_ot3():


@pytest.fixture
def mock_api_verify_tip_presence() -> Iterator[mock.AsyncMock]:
def mock_api_verify_tip_presence_ot3(request) -> Iterator[mock.AsyncMock]:
if request.config.getoption("--ot2-only"):
pytest.skip("testing ot2 only")
from opentrons.hardware_control.ot3api import OT3API

with mock.patch.object(OT3API, "verify_tip_presence") as mock_tip_presence:
Expand All @@ -70,11 +72,14 @@ def mock_api_verify_tip_presence() -> Iterator[mock.AsyncMock]:
def wrap_build_ot3_sim():
from opentrons.hardware_control.ot3api import OT3API

return OT3API.build_hardware_simulator
with mock.patch.object(
OT3API, "verify_tip_presence"
) as mock_tip_presence: # noqa: F841
return OT3API.build_hardware_simulator


@pytest.fixture
def ot3_api_obj(request, mock_api_verify_tip_presence):
def ot3_api_obj(request, mock_api_verify_tip_presence_ot3):
if request.config.getoption("--ot2-only"):
pytest.skip("testing ot2 only")
from opentrons.hardware_control.ot3api import OT3API
Expand All @@ -89,7 +94,7 @@ def ot3_api_obj(request, mock_api_verify_tip_presence):
],
ids=["ot2", "ot3"],
)
def sim_and_instr(request, mock_api_verify_tip_presence):
def sim_and_instr(request):
if (
request.node.get_closest_marker("ot2_only")
and request.param[0] == wrap_build_ot3_sim
Expand Down
71 changes: 0 additions & 71 deletions hardware/opentrons_hardware/hardware_control/tip_presence.py

This file was deleted.

This file was deleted.

0 comments on commit 52dc84a

Please sign in to comment.