Skip to content

Commit d39ad2b

Browse files
authored
Merge pull request #25 from tekktrik/dev/fix-pytests
Fix tests
2 parents 557086a + 35efafd commit d39ad2b

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
# should be mocked away. For instance, modules which are available in
2121
# CircuitPython but not standard Python.
2222
MOCK_MODULES = [
23-
"adafruit_ble.BLERadio",
24-
"adafruit_ble.advertising.adafruit.AdafruitRadio",
23+
"adafruit_ble",
24+
"adafruit_ble.advertising",
25+
"adafruit_ble.advertising.standard",
26+
"adafruit_ble.advertising.adafruit",
27+
"_bleio",
2528
]
2629

2730

tests/test_adafruit_radio.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
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

18+
# pylint: disable=redefined-outer-name
19+
20+
1721
@pytest.fixture
18-
def radio():
22+
def radio_obj():
1923
"""
2024
A fixture to recreate a new Radio instance for each test that needs it.
2125
"""
@@ -104,9 +108,7 @@ def test_radio_send_bytes(radio_obj):
104108
with mock.patch("adafruit_ble_radio.time.sleep") as mock_sleep:
105109
radio_obj.send_bytes(msg)
106110
mock_sleep.assert_called_once_with(adafruit_ble_radio.AD_DURATION)
107-
spy_advertisement = (
108-
adafruit_ble_radio._RadioAdvertisement() # pylint: disable=protected-access
109-
) # pylint: disable=protected-access
111+
spy_advertisement = Advertisement
110112
chan = struct.pack("<B", radio_obj._channel) # pylint: disable=protected-access
111113
uid = struct.pack("<B", 255)
112114
assert spy_advertisement.msg == chan + uid + msg
@@ -122,7 +124,7 @@ def test_radio_receive_no_message(radio_obj):
122124
"""
123125
radio_obj.receive_full = mock.MagicMock(return_value=None)
124126
assert radio_obj.receive() is None
125-
radio_obj.receive_full.assert_called_once_with()
127+
radio_obj.receive_full.assert_called_once_with(timeout=1.0)
126128

127129

128130
def test_radio_receive(radio_obj):

0 commit comments

Comments
 (0)