Browse Source

test method get_main_radio_control_state_machine_state

Fabian Peter Hammerle 3 years ago
parent
commit
451ed77a85
2 changed files with 41 additions and 1 deletions
  1. 1 1
      .github/workflows/python.yml
  2. 40 0
      tests/test_state.py

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

@@ -50,7 +50,7 @@ jobs:
       env:
         PYTHON_VERSION: ${{ matrix.python-version }}
     - run: pipenv graph
-    - run: pipenv run pytest --cov=cc1101 --cov-report=term-missing --cov-fail-under=93
+    - run: pipenv run pytest --cov=cc1101 --cov-report=term-missing --cov-fail-under=94
     - run: pipenv run pylint --load-plugins=pylint_import_requirements cc1101
     # https://github.com/PyCQA/pylint/issues/352
     - run: pipenv run pylint tests/*

+ 40 - 0
tests/test_state.py

@@ -0,0 +1,40 @@
+# python-cc1101 - Python Library to Transmit RF Signals via CC1101 Transceivers
+#
+# Copyright (C) 2020 Fabian Peter Hammerle <fabian@hammerle.me>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+import pytest
+
+import cc1101
+
+
+# pylint: disable=protected-access
+
+
+@pytest.mark.parametrize(
+    "marcstate",
+    (
+        cc1101.MainRadioControlStateMachineState.IDLE,
+        cc1101.MainRadioControlStateMachineState.RX,
+    ),
+)
+def test_get_main_radio_control_state_machine_state(transceiver, marcstate):
+    transceiver._spi.xfer.return_value = [
+        0b0000111,  # chip status "idle", but irrelevant for retrieval of marcstate
+        marcstate.value,
+    ]
+    assert transceiver.get_main_radio_control_state_machine_state() == marcstate
+    transceiver._spi.xfer.assert_called_once_with([0x35 | 0xC0, 0])
+    assert transceiver.get_marc_state() == marcstate