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

add test for CC1101.asynchronous_transmission()

Fabian Peter Hammerle 8 місяців тому
батько
коміт
3536e25c86
2 змінених файлів з 22 додано та 1 видалено
  1. 1 1
      .github/workflows/python.yml
  2. 21 0
      tests/test_transmit.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=98
+    - run: pipenv run pytest --cov="$(cat *.egg-info/top_level.txt)" --cov-report=term-missing --cov-fail-under=99
     - run: pipenv run pylint "$(cat *.egg-info/top_level.txt)"
     # https://github.com/PyCQA/pylint/issues/352
     - run: pipenv run pylint tests/*

+ 21 - 0
tests/test_transmit.py

@@ -3,6 +3,7 @@ import unittest.mock
 
 import pytest
 
+import cc1101.addresses
 import cc1101.options
 
 # pylint: disable=protected-access
@@ -128,3 +129,23 @@ def test_transmit_variable(transceiver, payload):
         unittest.mock.call([0x3F | 0x40] + [len(payload)] + list(payload)),
         unittest.mock.call([0x35]),  # start transmission
     ]
+
+
+def test_asynchronous_transmission(transceiver: cc1101.CC1101) -> None:
+    with unittest.mock.patch.object(
+        transceiver, "_set_transceive_mode"
+    ) as set_mode_mock, unittest.mock.patch.object(
+        transceiver, "_command_strobe"
+    ) as command_mock:
+        with transceiver.asynchronous_transmission() as input_pin:
+            set_mode_mock.assert_called_once_with(
+                cc1101.options._TransceiveMode.ASYNCHRONOUS_SERIAL
+            )
+            set_mode_mock.reset_mock()
+            command_mock.assert_called_once_with(cc1101.addresses.StrobeAddress.STX)
+            command_mock.reset_mock()
+            transceiver._spi.xfer.assert_not_called()
+            assert input_pin == cc1101.Pin.GDO0
+        set_mode_mock.assert_called_once_with(cc1101.options._TransceiveMode.FIFO)
+        command_mock.assert_called_once_with(cc1101.addresses.StrobeAddress.SIDLE)
+        transceiver._spi.xfer.assert_not_called()