From 82ba1bfef9c6c06e697929d8f1453fdc932466cb Mon Sep 17 00:00:00 2001 From: Christopher Peplin Date: Sat, 3 Aug 2024 11:50:02 -0400 Subject: [PATCH] Fix formatting and deprecation warnings --- pygatt/backends/bgapi/bgapi.py | 2 +- pygatt/backends/gatttool/gatttool.py | 5 +++-- tests/bgapi/test_bgapi.py | 2 +- tests/bgapi/test_device.py | 4 ++-- tests/gatttool/test_backend.py | 4 ++-- tests/gatttool/test_device.py | 4 +++- tests/test_device.py | 10 +++++----- 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/pygatt/backends/bgapi/bgapi.py b/pygatt/backends/bgapi/bgapi.py index 6f4ea2d..e4f10e2 100755 --- a/pygatt/backends/bgapi/bgapi.py +++ b/pygatt/backends/bgapi/bgapi.py @@ -519,7 +519,7 @@ def _get_uuid_type(uuid): if uuid in constants.gatt_characteristic_type_uuid.values(): return UUIDType.characteristic - log.warn("Unrecognized 4 byte UUID %s", hexlify(uuid)) + log.warning("Unrecognized 4 byte UUID %s", hexlify(uuid)) return UUIDType.nonstandard def _scan_rsp_data(self, data): diff --git a/pygatt/backends/gatttool/gatttool.py b/pygatt/backends/gatttool/gatttool.py index b1e29b1..3c06d5d 100644 --- a/pygatt/backends/gatttool/gatttool.py +++ b/pygatt/backends/gatttool/gatttool.py @@ -548,13 +548,14 @@ def discover_characteristics(self, timeout=5): def _handle_notification_string(self, event): msg = event["after"] if not msg: - log.warn("Blank message received in notification, ignored") + log.warning("Blank message received in notification, ignored") return match_obj = re.match(r'.* handle = (0x[0-9a-f]+) value:(.*)', msg.decode('utf-8')) if match_obj is None: - log.warn("Unable to parse notification string, ignoring: %s", msg) + log.warning( + "Unable to parse notification string, ignoring: %s", msg) return handle = int(match_obj.group(1), 16) diff --git a/tests/bgapi/test_bgapi.py b/tests/bgapi/test_bgapi.py index 9784dd6..3743b43 100644 --- a/tests/bgapi/test_bgapi.py +++ b/tests/bgapi/test_bgapi.py @@ -80,7 +80,7 @@ def test_reset_and_reconnect(self): with self.assertRaises(NotConnectedError): self.backend.start() self.assertEqual(MAX_CONNECTION_ATTEMPTS + 1, - self.mock_device.mocked_serial.read.call_count) + self.mock_device.mocked_serial.read.call_count) self.assertTrue(self.mock_device.mocked_serial.write.called) def test_scan_and_get_devices_discovered(self): diff --git a/tests/bgapi/test_device.py b/tests/bgapi/test_device.py index 324f065..68aa813 100644 --- a/tests/bgapi/test_device.py +++ b/tests/bgapi/test_device.py @@ -157,5 +157,5 @@ def test_discover_characteristics(self): uuid_desc, handle_desc]) characteristics = device.discover_characteristics() assert characteristics[uuid_char].handle == handle_char - assert (characteristics[uuid_char].descriptors[uuid16_to_uuid(0x2902)] - == handle_desc) + assert characteristics[uuid_char].descriptors[uuid16_to_uuid(0x2902)] \ + == handle_desc diff --git a/tests/gatttool/test_backend.py b/tests/gatttool/test_backend.py index 4a07cde..66f4396 100644 --- a/tests/gatttool/test_backend.py +++ b/tests/gatttool/test_backend.py @@ -164,8 +164,8 @@ def test_multi_byte_notification(self): device._backend._handle_notification_string(event) assert device.receive_notification.called assert 0x24 == device.receive_notification.call_args[0][0] - assert (bytearray([0x64, 0x46, 0x72]) - == device.receive_notification.call_args[0][1]) + assert bytearray([0x64, 0x46, 0x72]) == \ + device.receive_notification.call_args[0][1] def test_empty_notification(self): event = { diff --git a/tests/gatttool/test_device.py b/tests/gatttool/test_device.py index bd706fa..8f81c82 100644 --- a/tests/gatttool/test_device.py +++ b/tests/gatttool/test_device.py @@ -74,7 +74,9 @@ def test_write_after_disconnect(self): def test_get_handle(self): handle = self.device.get_handle(self.char_uuid) assert self.backend.discover_characteristics.called - assert self.device == self.backend.discover_characteristics.call_args[0][0] + assert ( + self.device == self.backend.discover_characteristics.call_args[0][0] + ) assert self.expected_handle == handle def test_get_cached_handle(self): diff --git a/tests/test_device.py b/tests/test_device.py index 75087a4..4632b50 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -6,7 +6,7 @@ from pygatt.backends import Characteristic -class TestBLEDevice(BLEDevice): +class MockBLEDevice(BLEDevice): CHAR_UUID = uuid.uuid4() EXPECTED_HANDLE = 99 @@ -21,7 +21,7 @@ def setUp(self): super(BLEDeviceTest, self).setUp() self.address = "11:22:33:44:55:66" self.backend = MagicMock() - self.device = TestBLEDevice(self.address) + self.device = MockBLEDevice(self.address) def _subscribe(self): callback = MagicMock() @@ -58,16 +58,16 @@ def test_subscribe_another_callback(self): def test_receive_notification(self): callback = self._subscribe() value = bytearray([24]) - self.device.receive_notification(TestBLEDevice.EXPECTED_HANDLE, value) + self.device.receive_notification(MockBLEDevice.EXPECTED_HANDLE, value) assert callback.called - assert TestBLEDevice.EXPECTED_HANDLE == callback.call_args[0][0] + assert MockBLEDevice.EXPECTED_HANDLE == callback.call_args[0][0] assert value == callback.call_args[0][1] def test_ignore_notification_for_another_handle(self): callback = self._subscribe() value = bytearray([24]) self.device.receive_notification( - TestBLEDevice.EXPECTED_HANDLE + 1, value) + MockBLEDevice.EXPECTED_HANDLE + 1, value) assert not callback.called def test_unicode_get_handle(self):