Skip to content

Commit 35efafd

Browse files
committed
Fix test for Radio.send_bytes()
1 parent bcb4637 commit 35efafd

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

adafruit_ble_radio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def send_bytes(self, message: bytes) -> None:
146146
# Concatenate the bytes that make up the advertised message.
147147
advertisement.msg = struct.pack("<BB", self._channel, self.uid) + message
148148

149-
self.uid = (self.uid + 1) % 255
149+
self.uid = (self.uid + 1) % 256
150150
# Advertise (block) for AD_DURATION period of time.
151151
self.ble.start_advertising(advertisement)
152152
time.sleep(AD_DURATION)

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# CircuitPython but not standard Python.
2222
MOCK_MODULES = [
2323
"adafruit_ble",
24+
"adafruit_ble.advertising",
2425
"adafruit_ble.advertising.standard",
2526
"adafruit_ble.advertising.adafruit",
2627
"_bleio",

tests/test_adafruit_radio.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import time
1212
from unittest import mock
1313
import pytest
14+
from adafruit_ble.advertising import Advertisement
1415
import adafruit_ble_radio
1516

1617

@@ -97,7 +98,6 @@ def test_radio_send_bytes_too_long(radio_obj):
9798
radio_obj.send_bytes(msg)
9899

99100

100-
@pytest.mark.xfail(reason="Test should be checked and possibly updated")
101101
def test_radio_send_bytes(radio_obj):
102102
"""
103103
Ensure the expected message is set on an instance of AdafruitRadio, and
@@ -108,9 +108,7 @@ def test_radio_send_bytes(radio_obj):
108108
with mock.patch("adafruit_ble_radio.time.sleep") as mock_sleep:
109109
radio_obj.send_bytes(msg)
110110
mock_sleep.assert_called_once_with(adafruit_ble_radio.AD_DURATION)
111-
spy_advertisement = (
112-
adafruit_ble_radio._RadioAdvertisement() # pylint: disable=protected-access
113-
) # pylint: disable=protected-access
111+
spy_advertisement = Advertisement
114112
chan = struct.pack("<B", radio_obj._channel) # pylint: disable=protected-access
115113
uid = struct.pack("<B", 255)
116114
assert spy_advertisement.msg == chan + uid + msg

0 commit comments

Comments
 (0)