diff --git a/api/src/opentrons/types.py b/api/src/opentrons/types.py index 17b97fda5174..eeafa0636718 100644 --- a/api/src/opentrons/types.py +++ b/api/src/opentrons/types.py @@ -35,12 +35,6 @@ class Point(NamedTuple): y: float = 0.0 z: float = 0.0 - def __eq__(self, other: Any) -> bool: - if not isinstance(other, Point): - return False - pairs = ((self.x, other.x), (self.y, other.y), (self.z, other.z)) - return all(isclose(s, o, rel_tol=1e-05, abs_tol=1e-08) for s, o in pairs) - def __add__(self, other: Any) -> Point: if not isinstance(other, Point): return NotImplemented @@ -75,6 +69,12 @@ def magnitude_to(self, other: Any) -> float: z_diff = self.z - other.z return sqrt(x_diff**2 + y_diff**2 + z_diff**2) + def elementwise_isclose( + self, other: Point, *, rel_tol: float = 1e-05, abs_tol: float = 1e-08 + ) -> bool: + pairs = ((self.x, other.x), (self.y, other.y), (self.z, other.z)) + return all(isclose(s, o, rel_tol=rel_tol, abs_tol=abs_tol) for s, o in pairs) + LocationLabware = Union[ "Labware", diff --git a/api/tests/opentrons/protocol_engine/commands/calibration/test_calibrate_gripper.py b/api/tests/opentrons/protocol_engine/commands/calibration/test_calibrate_gripper.py index 4145e1f0b5c3..ed85a50c6223 100644 --- a/api/tests/opentrons/protocol_engine/commands/calibration/test_calibrate_gripper.py +++ b/api/tests/opentrons/protocol_engine/commands/calibration/test_calibrate_gripper.py @@ -5,7 +5,7 @@ import inspect import pytest from datetime import datetime -from decoy import Decoy +from decoy import Decoy, matchers from typing import TYPE_CHECKING from opentrons.hardware_control import ot3_calibration @@ -93,6 +93,7 @@ async def test_calibrate_gripper_saves_calibration( status=CalibrationStatus(markedBad=False), last_modified=datetime(year=3000, month=1, day=1), ) + saved_delta_captor = matchers.Captor() decoy.when( await ot3_calibration.calibrate_gripper_jaw( ot3_hardware_api, probe=GripperProbe.REAR @@ -100,11 +101,13 @@ async def test_calibrate_gripper_saves_calibration( ).then_return(Point(1.1, 2.2, 3.3)) decoy.when( await ot3_hardware_api.save_instrument_offset( - mount=OT3Mount.GRIPPER, delta=Point(x=2.75, y=3.85, z=4.95) + mount=OT3Mount.GRIPPER, delta=saved_delta_captor ) ).then_return(expected_calibration_data) result = await subject.execute(params) + saved_delta: Point = saved_delta_captor.value assert result.public.jawOffset == Vec3f(x=1.1, y=2.2, z=3.3) + assert saved_delta.elementwise_isclose(Point(x=2.75, y=3.85, z=4.95)) assert result.public.savedCalibration == expected_calibration_data diff --git a/api/tests/opentrons/protocol_engine/state/test_geometry_view.py b/api/tests/opentrons/protocol_engine/state/test_geometry_view.py index 93d3ce7dd560..d5467048c539 100644 --- a/api/tests/opentrons/protocol_engine/state/test_geometry_view.py +++ b/api/tests/opentrons/protocol_engine/state/test_geometry_view.py @@ -1390,10 +1390,12 @@ def test_get_well_position( result = subject.get_well_position("labware-id", "B2") - assert result == Point( - x=slot_pos[0] + 1 + well_def.x, - y=slot_pos[1] - 2 + well_def.y, - z=slot_pos[2] + 3 + well_def.z + well_def.depth, + assert result.elementwise_isclose( + Point( + x=slot_pos[0] + 1 + well_def.x, + y=slot_pos[1] - 2 + well_def.y, + z=slot_pos[2] + 3 + well_def.z + well_def.depth, + ) ) @@ -1473,10 +1475,12 @@ def test_get_module_labware_well_position( ).then_return(OverlapOffset(x=0, y=0, z=0)) result = subject.get_well_position("labware-id", "B2") - assert result == Point( - x=slot_pos[0] + 1 + well_def.x + 4, - y=slot_pos[1] - 2 + well_def.y + 5, - z=slot_pos[2] + 3 + well_def.z + well_def.depth + 6, + assert result.elementwise_isclose( + Point( + x=slot_pos[0] + 1 + well_def.x + 4, + y=slot_pos[1] - 2 + well_def.y + 5, + z=slot_pos[2] + 3 + well_def.z + well_def.depth + 6, + ) ) @@ -1522,10 +1526,12 @@ def test_get_well_position_with_top_offset( ), ) - assert result == Point( - x=slot_pos[0] + 1 + well_def.x + 1, - y=slot_pos[1] - 2 + well_def.y + 2, - z=slot_pos[2] + 3 + well_def.z + well_def.depth + 3, + assert result.elementwise_isclose( + Point( + x=slot_pos[0] + 1 + well_def.x + 1, + y=slot_pos[1] - 2 + well_def.y + 2, + z=slot_pos[2] + 3 + well_def.z + well_def.depth + 3, + ) )