Переглянути джерело

add tests for CC1101._set_transceive_mode()

Fabian Peter Hammerle 8 місяців тому
батько
коміт
a20c0f2dd3
2 змінених файлів з 25 додано та 1 видалено
  1. 1 1
      .github/workflows/python.yml
  2. 24 0
      tests/config/test_0x08_pktctrl0.py

+ 1 - 1
.github/workflows/python.yml

@@ -57,7 +57,7 @@ jobs:
       env:
         PYTHON_VERSION: ${{ matrix.python-version }}
     - run: pipenv graph
-    - run: pipenv run pytest --cov="$(cat *.egg-info/top_level.txt)" --cov-report=term-missing --cov-fail-under=97
+    - run: pipenv run pytest --cov="$(cat *.egg-info/top_level.txt)" --cov-report=term-missing --cov-fail-under=98
     - run: pipenv run pylint "$(cat *.egg-info/top_level.txt)"
     # https://github.com/PyCQA/pylint/issues/352
     - run: pipenv run pylint tests/*

+ 24 - 0
tests/config/test_0x08_pktctrl0.py

@@ -55,6 +55,30 @@ def test__get_transceive_mode(transceiver: cc1101.CC1101) -> None:
     assert transceiver._get_transceive_mode() == _TransceiveMode.ASYNCHRONOUS_SERIAL
 
 
+@pytest.mark.parametrize(
+    ("pktctrl0_before", "mode", "pktctrl0_after"),
+    [
+        (0b01000101, _TransceiveMode.FIFO, 0b01000101),
+        (0b01000101, _TransceiveMode.SYNCHRONOUS_SERIAL, 0b01010101),
+        (0b01000101, _TransceiveMode.ASYNCHRONOUS_SERIAL, 0b01110101),
+        (0b11111111, _TransceiveMode.FIFO, 0b11001111),
+    ],
+)
+def test__set_transceive_mode(
+    transceiver: cc1101.CC1101,
+    pktctrl0_before: int,
+    mode: _TransceiveMode,
+    pktctrl0_after: int,
+) -> None:
+    xfer_mock = transceiver._spi.xfer
+    xfer_mock.return_value = [0xFF] * 2  # chip status byte
+    with unittest.mock.patch.object(
+        transceiver, "_read_single_byte", return_value=pktctrl0_before
+    ):
+        transceiver._set_transceive_mode(mode)
+    xfer_mock.assert_called_once_with([0x08 | 0x40, pktctrl0_after])
+
+
 @pytest.mark.parametrize(
     ("pktctrl0_before", "pktctrl0_after"),
     (