Skip to content

Commit

Permalink
fix(api): represent Location correctly in log (#7565)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
amitlissack authored Mar 30, 2021
1 parent e3222bc commit be091a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions api/src/opentrons/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
23 changes: 22 additions & 1 deletion api/tests/opentrons/test_types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from opentrons.types import Point
from opentrons.types import Point, Location


def test_point_mul():
Expand All @@ -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)"

0 comments on commit be091a3

Please sign in to comment.