From 6834cda641bde30012e63a625006bb84adf4e213 Mon Sep 17 00:00:00 2001 From: Gonzalo Ribera Date: Fri, 20 May 2022 08:48:37 -0300 Subject: [PATCH 1/4] Fix fileno error on Windows (robotell bus) --- can/interfaces/robotell.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/can/interfaces/robotell.py b/can/interfaces/robotell.py index 88cee26d1..cbf11a417 100644 --- a/can/interfaces/robotell.py +++ b/can/interfaces/robotell.py @@ -2,6 +2,7 @@ Interface for Chinese Robotell compatible interfaces (win32/linux). """ +import io import time import logging @@ -367,10 +368,12 @@ def shutdown(self): self.serialPortOrig.close() def fileno(self): - if hasattr(self.serialPortOrig, "fileno"): + try: return self.serialPortOrig.fileno() - # Return an invalid file descriptor on Windows - return -1 + except io.UnsupportedOperation: + raise NotImplementedError("fileno is not implemented using current CAN bus on this platform") + except Exception as exception: + raise CanOperationError("Cannot fetch fileno") from exception def get_serial_number(self, timeout): """Get serial number of the slcan interface. From 90c6f835ab908eb5be62b7ff6a98a38e54ddb6bd Mon Sep 17 00:00:00 2001 From: Gonzalo Ribera Date: Sat, 21 May 2022 15:34:12 -0300 Subject: [PATCH 2/4] Fix format --- can/interfaces/robotell.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/can/interfaces/robotell.py b/can/interfaces/robotell.py index cbf11a417..709fad78d 100644 --- a/can/interfaces/robotell.py +++ b/can/interfaces/robotell.py @@ -371,7 +371,9 @@ def fileno(self): try: return self.serialPortOrig.fileno() except io.UnsupportedOperation: - raise NotImplementedError("fileno is not implemented using current CAN bus on this platform") + raise NotImplementedError( + "fileno is not implemented using current CAN bus on this platform" + ) except Exception as exception: raise CanOperationError("Cannot fetch fileno") from exception From 5247f45ef8e06c8ce2db52481cb9727aaf404552 Mon Sep 17 00:00:00 2001 From: Gonzalo Ribera Date: Mon, 23 May 2022 12:05:23 -0300 Subject: [PATCH 3/4] Add test --- test/test_robotell.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_robotell.py b/test/test_robotell.py index 86e053f2d..419b46758 100644 --- a/test/test_robotell.py +++ b/test/test_robotell.py @@ -940,6 +940,9 @@ def test_set_hw_filter(self): ), ) + def test_when_no_fileno(self): + with self.assertRaises(NotImplementedError): + self.bus.fileno() if __name__ == "__main__": unittest.main() From 7c034a452318b4d8d378416f43797215a0ac6451 Mon Sep 17 00:00:00 2001 From: Gonzalo Ribera Date: Tue, 24 May 2022 18:27:10 -0300 Subject: [PATCH 4/4] format --- test/test_robotell.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_robotell.py b/test/test_robotell.py index 419b46758..8250b7ada 100644 --- a/test/test_robotell.py +++ b/test/test_robotell.py @@ -944,5 +944,6 @@ def test_when_no_fileno(self): with self.assertRaises(NotImplementedError): self.bus.fileno() + if __name__ == "__main__": unittest.main()