Skip to content

Commit d213fd7

Browse files
committed
Linted tests directory
1 parent c04f4c3 commit d213fd7

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

.pre-commit-config.yaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ repos:
2323
- id: pylint
2424
name: pylint (library code)
2525
types: [python]
26-
exclude: "^(docs/|examples/|setup.py$)"
26+
exclude: "^(docs/|tests/|examples/|setup.py$)"
2727
- repo: local
2828
hooks:
2929
- id: pylint_examples
@@ -32,3 +32,11 @@ repos:
3232
entry: /usr/bin/env bash -c
3333
args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)']
3434
language: system
35+
- repo: local
36+
hooks:
37+
- id: pylint_tests
38+
name: pylint (tests code)
39+
description: Run pylint rules on "tests/*.py" files
40+
entry: /usr/bin/env bash -c
41+
args: ['([[ ! -d "tests" ]] || for test in $(find . -path "./tests/*.py"); do pylint --disable=missing-docstring $test; done)']
42+
language: system

tests/conftest.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ def mock_imported_modules():
3131
can be imported with modules which may not be available.
3232
"""
3333
module_paths = set()
34-
for m in MOCK_MODULES:
35-
namespaces = m.split(".")
36-
ns = []
34+
for mock in MOCK_MODULES:
35+
namespaces = mock.split(".")
36+
namespace = []
3737
for n in namespaces:
38-
ns.append(n)
39-
module_paths.add(".".join(ns))
38+
namespace.append(n)
39+
module_paths.add(".".join(namespace))
4040
for m_path in module_paths:
4141
sys.modules[m_path] = MagicMock()
4242

4343

44-
def pytest_runtest_setup(item):
44+
def pytest_runtest_setup():
4545
"""
4646
Called immediately before any test function is called.
4747

tests/test_adafruit_radio.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
found in the testconf.py file. See comments therein for explanation of how it
88
works.
99
"""
10-
import adafruit_ble_radio
11-
import pytest
1210
import struct
1311
import time
1412
from unittest import mock
13+
import pytest
14+
import adafruit_ble_radio
1515

1616

1717
@pytest.fixture
@@ -35,25 +35,25 @@ def test_radio_init_default():
3535
assert r.ble == adafruit_ble_radio.BLERadio()
3636
assert r.uid == 0
3737
assert r.msg_pool == set()
38-
assert r._channel == 42
38+
assert r._channel == 42 # pylint: disable=protected-access
3939

4040

4141
def test_radio_init_channel():
4242
"""
4343
If a channel argument is passed to initialisation, this is correctly set.
4444
"""
4545
r = adafruit_ble_radio.Radio(channel=7)
46-
assert r._channel == 7
46+
assert r._channel == 7 # pylint: disable=protected-access
4747

4848

4949
def test_radio_configure_channel(radio):
5050
"""
5151
If a valid channel argument is passed to the configure method, the Radio
5252
instance's channel is updated to reflect this.
5353
"""
54-
assert radio._channel == 42
54+
assert radio._channel == 42 # pylint: disable=protected-access
5555
radio.configure(channel=7)
56-
assert radio._channel == 7
56+
assert radio._channel == 7 # pylint: disable=protected-access
5757

5858

5959
def test_radio_configure_channel_out_of_bounds(radio):
@@ -67,9 +67,9 @@ def test_radio_configure_channel_out_of_bounds(radio):
6767
radio.configure(channel=256)
6868
# Add just-in-bounds checks too.
6969
radio.configure(channel=0)
70-
assert radio._channel == 0
70+
assert radio._channel == 0 # pylint: disable=protected-access
7171
radio.configure(channel=255)
72-
assert radio._channel == 255
72+
assert radio._channel == 255 # pylint: disable=protected-access
7373

7474

7575
def test_radio_send(radio):
@@ -102,8 +102,10 @@ def test_radio_send_bytes(radio):
102102
with mock.patch("adafruit_ble_radio.time.sleep") as mock_sleep:
103103
radio.send_bytes(msg)
104104
mock_sleep.assert_called_once_with(adafruit_ble_radio.AD_DURATION)
105-
spy_advertisement = adafruit_ble_radio.AdafruitRadio()
106-
chan = struct.pack("<B", radio._channel)
105+
spy_advertisement = (
106+
adafruit_ble_radio._RadioAdvertisement()
107+
) # pylint: disable=protected-access
108+
chan = struct.pack("<B", radio._channel) # pylint: disable=protected-access
107109
uid = struct.pack("<B", 255)
108110
assert spy_advertisement.msg == chan + uid + msg
109111
radio.ble.start_advertising.assert_called_once_with(spy_advertisement)
@@ -140,7 +142,10 @@ def test_radio_receive_full_no_messages(radio):
140142
radio.ble.start_scan.return_value = []
141143
assert radio.receive_full() is None
142144
radio.ble.start_scan.assert_called_once_with(
143-
adafruit_ble_radio.AdafruitRadio, minimum_rssi=-255, timeout=1, extended=True
145+
adafruit_ble_radio._RadioAdvertisement,
146+
minimum_rssi=-255,
147+
timeout=1,
148+
extended=True,
144149
)
145150
radio.ble.stop_scan.assert_called_once_with()
146151

0 commit comments

Comments
 (0)