From be091a3e57080dc42dbba6de8ba7217c59525001 Mon Sep 17 00:00:00 2001 From: amitlissack Date: Tue, 30 Mar 2021 15:09:04 -0400 Subject: [PATCH] fix(api): represent Location correctly in log (#7565) Location used to be a namedtuple instead of a class. There's no __repr__ function so Location objects are meaningless in run logging. closes #7564 --- api/src/opentrons/types.py | 3 +++ api/tests/opentrons/test_types.py | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/api/src/opentrons/types.py b/api/src/opentrons/types.py index 4c1c914ee93..dae27df1c00 100644 --- a/api/src/opentrons/types.py +++ b/api/src/opentrons/types.py @@ -135,6 +135,9 @@ def move(self, point: Point) -> 'Location': return Location(point=self.point + point, labware=self._labware.object) + def __repr__(self) -> str: + return f"Location(point={repr(self._point)}, labware={self._labware})" + # TODO(mc, 2020-10-22): use MountType implementation for Mount class Mount(enum.Enum): diff --git a/api/tests/opentrons/test_types.py b/api/tests/opentrons/test_types.py index 3db108ec3ef..7d5abfacd5e 100644 --- a/api/tests/opentrons/test_types.py +++ b/api/tests/opentrons/test_types.py @@ -1,5 +1,5 @@ import pytest -from opentrons.types import Point +from opentrons.types import Point, Location def test_point_mul(): @@ -21,3 +21,24 @@ def test_point_rmul(): b = 3.1 assert b * a == Point(3.1, 6.2, 9.3) + + +def test_location_repr_labware(min_lw): + """It should represent labware as Labware""" + loc = Location(point=Point(x=1.1, y=2.1, z=3.5), labware=min_lw) + assert f'{loc}' ==\ + "Location(point=Point(x=1.1, y=2.1, z=3.5), labware=minimal labware on deck)" + + +def test_location_repr_well(min_lw): + """It should represent labware as Well""" + loc = Location(point=Point(x=1, y=2, z=3), labware=min_lw.wells()[0]) + assert f'{loc}' == \ + "Location(point=Point(x=1, y=2, z=3), labware=A1 of minimal labware on deck)" + + +def test_location_repr_slot(): + """It should represent labware as a slot""" + loc = Location(point=Point(x=-1, y=2, z=3), labware="1") + assert f'{loc}' == \ + "Location(point=Point(x=-1, y=2, z=3), labware=1)"