Skip to content

Commit

Permalink
Fix formatting and deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
peplin committed Aug 3, 2024
1 parent b666b62 commit 82ba1bf
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pygatt/backends/bgapi/bgapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions pygatt/backends/gatttool/gatttool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/bgapi/test_bgapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/bgapi/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tests/gatttool/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 3 additions & 1 deletion tests/gatttool/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pygatt.backends import Characteristic


class TestBLEDevice(BLEDevice):
class MockBLEDevice(BLEDevice):
CHAR_UUID = uuid.uuid4()
EXPECTED_HANDLE = 99

Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 82ba1bf

Please sign in to comment.