From 5b5b002e6a36aba72094f8540d4e7fa15cd9a076 Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Tue, 6 Mar 2018 22:06:26 +0000 Subject: [PATCH 1/9] add __repr__ for Board class --- robot/board.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/robot/board.py b/robot/board.py index 2bfa218..5aad270 100644 --- a/robot/board.py +++ b/robot/board.py @@ -155,6 +155,9 @@ def close(self): """ self.socket.detach() + def __repr__(self): + return "<{}>".format(self.__str__()) + def __str__(self): return "{} - {}".format(self.__name__, self.serial) From 2e6e65db145fe7763ea61224a0982568341aad50 Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Tue, 6 Mar 2018 20:55:23 +0000 Subject: [PATCH 2/9] add marker __repr__ functions, make __str__ formal --- robot/markers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/robot/markers.py b/robot/markers.py index a8306b8..ab53ab3 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.__str__()) + 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", From 99cb3b39eb66990aff6daab110c7708b1b946d7f Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Wed, 7 Mar 2018 00:53:44 +0000 Subject: [PATCH 3/9] fix tests --- tests/test_markers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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", ) From ac2266c0216aae1f2610eb69af5dbb9a25786151 Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Wed, 7 Mar 2018 00:56:38 +0000 Subject: [PATCH 4/9] call str() instead of __str__() --- robot/board.py | 2 +- robot/markers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/robot/board.py b/robot/board.py index 5aad270..27b9f52 100644 --- a/robot/board.py +++ b/robot/board.py @@ -156,7 +156,7 @@ def close(self): self.socket.detach() def __repr__(self): - return "<{}>".format(self.__str__()) + return "<{}>".format(str(self)) def __str__(self): return "{} - {}".format(self.__name__, self.serial) diff --git a/robot/markers.py b/robot/markers.py index ab53ab3..c14de6a 100644 --- a/robot/markers.py +++ b/robot/markers.py @@ -169,7 +169,7 @@ def spherical(self) -> SphericalCoord: return SphericalCoord(*self._raw_data['spherical']) def __repr__(self): - return "".format(self.__str__()) + return "".format(str(self)) def __str__(self): bearing = self.spherical.rot_y_degrees From 8b485a51d7b8c99c6bf2e921d0da5928d2cb816d Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Wed, 7 Mar 2018 09:15:37 +0000 Subject: [PATCH 5/9] remove 'robot.markers' from Markers __repr__ --- robot/markers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robot/markers.py b/robot/markers.py index c14de6a..c268e6b 100644 --- a/robot/markers.py +++ b/robot/markers.py @@ -169,7 +169,7 @@ def spherical(self) -> SphericalCoord: return SphericalCoord(*self._raw_data['spherical']) def __repr__(self): - return "".format(str(self)) + return "<{}>".format(str(self)) def __str__(self): bearing = self.spherical.rot_y_degrees From dada805f15a2d8fb864b4eb3b1a83a70efbe2455 Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Wed, 7 Mar 2018 14:30:02 +0000 Subject: [PATCH 6/9] use __class__ to properly get classnames --- robot/board.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robot/board.py b/robot/board.py index 27b9f52..f8144e9 100644 --- a/robot/board.py +++ b/robot/board.py @@ -159,7 +159,7 @@ def __repr__(self): return "<{}>".format(str(self)) def __str__(self): - return "{} - {}".format(self.__name__, self.serial) + return "{} - {}".format(self.__class__.__name__, self.serial) __del__ = close From 7f9cfee58b2ffb4f084d7c704c5c0128699d0671 Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Fri, 9 Mar 2018 13:06:52 +0000 Subject: [PATCH 7/9] remove redundant str calls --- robot/board.py | 2 +- robot/markers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/robot/board.py b/robot/board.py index f8144e9..46355df 100644 --- a/robot/board.py +++ b/robot/board.py @@ -44,7 +44,7 @@ def _connect(self): self.socket.settimeout(self.SEND_TIMEOUT_SECS) try: - self.socket.connect(str(self.socket_path)) + self.socket.connect(self.socket_path) except ConnectionRefusedError as e: LOGGER.exception("Error connecting to: '%s'", self.socket_path) raise diff --git a/robot/markers.py b/robot/markers.py index c268e6b..636b241 100644 --- a/robot/markers.py +++ b/robot/markers.py @@ -169,7 +169,7 @@ def spherical(self) -> SphericalCoord: return SphericalCoord(*self._raw_data['spherical']) def __repr__(self): - return "<{}>".format(str(self)) + return "<{}>".format(self) def __str__(self): bearing = self.spherical.rot_y_degrees From 515e0a30caaaac486c39a5af4494fad288333eb3 Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Thu, 29 Mar 2018 23:51:51 +0100 Subject: [PATCH 8/9] undo mistake --- robot/board.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robot/board.py b/robot/board.py index 46355df..f8144e9 100644 --- a/robot/board.py +++ b/robot/board.py @@ -44,7 +44,7 @@ def _connect(self): self.socket.settimeout(self.SEND_TIMEOUT_SECS) try: - self.socket.connect(self.socket_path) + self.socket.connect(str(self.socket_path)) except ConnectionRefusedError as e: LOGGER.exception("Error connecting to: '%s'", self.socket_path) raise From d4e364eaf6e50438e9ab2bb2b53e05063b9ee71f Mon Sep 17 00:00:00 2001 From: Andrew Barrett-Sprot Date: Thu, 29 Mar 2018 23:53:43 +0100 Subject: [PATCH 9/9] remove redundant str call in board --- robot/board.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robot/board.py b/robot/board.py index f8144e9..a2595c5 100644 --- a/robot/board.py +++ b/robot/board.py @@ -156,7 +156,7 @@ def close(self): self.socket.detach() def __repr__(self): - return "<{}>".format(str(self)) + return "<{}>".format(self) def __str__(self): return "{} - {}".format(self.__class__.__name__, self.serial)