1
1
"""
2
- Simple unit tests for the adafruit_radio module. Uses experimental mocking
2
+ Simple unit tests for the adafruit_ble_radio module. Uses experimental mocking
3
3
found in the testconf.py file. See comments therein for explanation of how it
4
4
works.
5
5
"""
6
- import adafruit_radio
6
+ import adafruit_ble_radio
7
7
import pytest
8
8
import struct
9
9
import time
@@ -15,7 +15,7 @@ def radio():
15
15
"""
16
16
A fixture to recreate a new Radio instance for each test that needs it.
17
17
"""
18
- return adafruit_radio .Radio ()
18
+ return adafruit_ble_radio .Radio ()
19
19
20
20
21
21
def test_radio_init_default ():
@@ -27,8 +27,8 @@ def test_radio_init_default():
27
27
* The self.msg_pool is initialised as an empty set.
28
28
* The channel is set to the default 42.
29
29
"""
30
- r = adafruit_radio .Radio ()
31
- assert r .ble == adafruit_radio .BLERadio ()
30
+ r = adafruit_ble_radio .Radio ()
31
+ assert r .ble == adafruit_ble_radio .BLERadio ()
32
32
assert r .uid == 0
33
33
assert r .msg_pool == set ()
34
34
assert r ._channel == 42
@@ -38,7 +38,7 @@ def test_radio_init_channel():
38
38
"""
39
39
If a channel argument is passed to initialisation, this is correctly set.
40
40
"""
41
- r = adafruit_radio .Radio (channel = 7 )
41
+ r = adafruit_ble_radio .Radio (channel = 7 )
42
42
assert r ._channel == 7
43
43
44
44
@@ -83,7 +83,7 @@ def test_radio_send_bytes_too_long(radio):
83
83
A ValueError is raised if the message to be sent is too long (defined by
84
84
MAX_LENGTH).
85
85
"""
86
- msg = bytes (adafruit_radio .MAX_LENGTH + 1 )
86
+ msg = bytes (adafruit_ble_radio .MAX_LENGTH + 1 )
87
87
with pytest .raises (ValueError ):
88
88
radio .send_bytes (msg )
89
89
@@ -95,10 +95,10 @@ def test_radio_send_bytes(radio):
95
95
"""
96
96
radio .uid = 255 # set up for cycle back to 0.
97
97
msg = b"Hello"
98
- with mock .patch ("adafruit_radio .time.sleep" ) as mock_sleep :
98
+ with mock .patch ("adafruit_ble_radio .time.sleep" ) as mock_sleep :
99
99
radio .send_bytes (msg )
100
- mock_sleep .assert_called_once_with (adafruit_radio .AD_DURATION )
101
- spy_advertisement = adafruit_radio .AdafruitRadio ()
100
+ mock_sleep .assert_called_once_with (adafruit_ble_radio .AD_DURATION )
101
+ spy_advertisement = adafruit_ble_radio .AdafruitRadio ()
102
102
chan = struct .pack ("<B" , radio ._channel )
103
103
uid = struct .pack ("<B" , 255 )
104
104
assert spy_advertisement .msg == chan + uid + msg
@@ -136,7 +136,7 @@ def test_radio_receive_full_no_messages(radio):
136
136
radio .ble .start_scan .return_value = []
137
137
assert radio .receive_full () is None
138
138
radio .ble .start_scan .assert_called_once_with (
139
- adafruit_radio .AdafruitRadio , minimum_rssi = - 255 , timeout = 1 , extended = True
139
+ adafruit_ble_radio .AdafruitRadio , minimum_rssi = - 255 , timeout = 1 , extended = True
140
140
)
141
141
radio .ble .stop_scan .assert_called_once_with ()
142
142
@@ -169,7 +169,7 @@ def test_radio_receive_full_and_remove_expired_message_metadata(radio):
169
169
mock_entry .address .address_bytes = b"adr2"
170
170
mock_entry .rssi = - 40
171
171
radio .ble .start_scan .return_value = [mock_entry ]
172
- radio .msg_pool .add ((time .monotonic () - adafruit_radio .AD_DURATION - 1 , 42 , 0 , b"addr" ))
172
+ radio .msg_pool .add ((time .monotonic () - adafruit_ble_radio .AD_DURATION - 1 , 42 , 0 , b"addr" ))
173
173
result = radio .receive_full ()
174
174
assert result [0 ] == b"Hello"
175
175
assert result [1 ] == - 40
0 commit comments