diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 354c761..cce4c7b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: - id: pylint name: pylint (library code) types: [python] - exclude: "^(docs/|examples/|setup.py$)" + exclude: "^(docs/|tests/|examples/|setup.py$)" - repo: local hooks: - id: pylint_examples @@ -32,3 +32,11 @@ repos: entry: /usr/bin/env bash -c args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] language: system +- repo: local + hooks: + - id: pylint_tests + name: pylint (tests code) + description: Run pylint rules on "tests/*.py" files + entry: /usr/bin/env bash -c + args: ['([[ ! -d "tests" ]] || for test in $(find . -path "./tests/*.py"); do pylint --disable=missing-docstring $test; done)'] + language: system diff --git a/tests/conftest.py b/tests/conftest.py index d5ae717..a9cc773 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -31,17 +31,17 @@ def mock_imported_modules(): can be imported with modules which may not be available. """ module_paths = set() - for m in MOCK_MODULES: - namespaces = m.split(".") - ns = [] + for mock in MOCK_MODULES: + namespaces = mock.split(".") + namespace = [] for n in namespaces: - ns.append(n) - module_paths.add(".".join(ns)) + namespace.append(n) + module_paths.add(".".join(namespace)) for m_path in module_paths: sys.modules[m_path] = MagicMock() -def pytest_runtest_setup(item): +def pytest_runtest_setup(): """ Called immediately before any test function is called. diff --git a/tests/test_adafruit_radio.py b/tests/test_adafruit_radio.py index ae7e684..3f4ac65 100644 --- a/tests/test_adafruit_radio.py +++ b/tests/test_adafruit_radio.py @@ -7,11 +7,11 @@ found in the testconf.py file. See comments therein for explanation of how it works. """ -import adafruit_ble_radio -import pytest import struct import time from unittest import mock +import pytest +import adafruit_ble_radio @pytest.fixture @@ -35,7 +35,7 @@ def test_radio_init_default(): assert r.ble == adafruit_ble_radio.BLERadio() assert r.uid == 0 assert r.msg_pool == set() - assert r._channel == 42 + assert r._channel == 42 # pylint: disable=protected-access def test_radio_init_channel(): @@ -43,7 +43,7 @@ def test_radio_init_channel(): If a channel argument is passed to initialisation, this is correctly set. """ r = adafruit_ble_radio.Radio(channel=7) - assert r._channel == 7 + assert r._channel == 7 # pylint: disable=protected-access def test_radio_configure_channel(radio): @@ -51,9 +51,9 @@ def test_radio_configure_channel(radio): If a valid channel argument is passed to the configure method, the Radio instance's channel is updated to reflect this. """ - assert radio._channel == 42 + assert radio._channel == 42 # pylint: disable=protected-access radio.configure(channel=7) - assert radio._channel == 7 + assert radio._channel == 7 # pylint: disable=protected-access def test_radio_configure_channel_out_of_bounds(radio): @@ -67,9 +67,9 @@ def test_radio_configure_channel_out_of_bounds(radio): radio.configure(channel=256) # Add just-in-bounds checks too. radio.configure(channel=0) - assert radio._channel == 0 + assert radio._channel == 0 # pylint: disable=protected-access radio.configure(channel=255) - assert radio._channel == 255 + assert radio._channel == 255 # pylint: disable=protected-access def test_radio_send(radio): @@ -102,8 +102,10 @@ def test_radio_send_bytes(radio): with mock.patch("adafruit_ble_radio.time.sleep") as mock_sleep: radio.send_bytes(msg) mock_sleep.assert_called_once_with(adafruit_ble_radio.AD_DURATION) - spy_advertisement = adafruit_ble_radio.AdafruitRadio() - chan = struct.pack("