diff --git a/robot/board.py b/robot/board.py index 2bfa218..a2595c5 100644 --- a/robot/board.py +++ b/robot/board.py @@ -155,8 +155,11 @@ def close(self): """ self.socket.detach() + def __repr__(self): + return "<{}>".format(self) + def __str__(self): - return "{} - {}".format(self.__name__, self.serial) + return "{} - {}".format(self.__class__.__name__, self.serial) __del__ = close diff --git a/robot/markers.py b/robot/markers.py index a8306b8..636b241 100644 --- a/robot/markers.py +++ b/robot/markers.py @@ -168,9 +168,12 @@ def spherical(self) -> SphericalCoord: """ return SphericalCoord(*self._raw_data['spherical']) + def __repr__(self): + return "<{}>".format(self) + def __str__(self): bearing = self.spherical.rot_y_degrees - return "".format( + return "Marker {}: {:.0f}° {}, {:.2f}m away".format( self.id, abs(bearing), "right" if bearing > 0 else "left", diff --git a/tests/test_markers.py b/tests/test_markers.py index 632594b..8e48a8f 100644 --- a/tests/test_markers.py +++ b/tests/test_markers.py @@ -37,7 +37,7 @@ def test_str_left(self): } self.assertEqual( str(Marker(data)), - "", + "Marker 13: 12° left, 0.12m away", ) def test_str_right(self): @@ -51,5 +51,5 @@ def test_str_right(self): } self.assertEqual( str(Marker(data)), - "", + "Marker 13: 12° right, 0.12m away", )