Browse Source

test _set_symbol_rate_exponent

Fabian Peter Hammerle 3 years ago
parent
commit
fc92881323
3 changed files with 65 additions and 10 deletions
  1. 1 1
      .github/workflows/python.yml
  2. 64 0
      tests/config/test_0x10_mdmcfg4.py
  3. 0 9
      tests/test_config.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=90
+    - run: pipenv run pytest --cov=cc1101 --cov-report=term-missing --cov-fail-under=91
     - run: pipenv run pylint --load-plugins=pylint_import_requirements cc1101
     # https://github.com/PyCQA/pylint/issues/352
     - run: pipenv run pylint tests/*

+ 64 - 0
tests/config/test_0x10_mdmcfg4.py

@@ -0,0 +1,64 @@
+# 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 unittest.mock
+
+import pytest
+
+# pylint: disable=protected-access
+
+
+@pytest.mark.parametrize(
+    ("mdmcfg4", "exponent"),
+    (
+        (0b10001100, 12),
+        (0b10001001, 9),
+        (0b10001111, 15),
+        (0b10000000, 0),
+        (0b10111100, 12),
+        (0b10111111, 15),
+        (0b10110000, 0),
+    ),
+)
+def test__get_symbol_rate_exponent(transceiver, mdmcfg4, exponent):
+    transceiver._spi.xfer.return_value = [15, mdmcfg4]
+    assert transceiver._get_symbol_rate_exponent() == exponent
+    transceiver._spi.xfer.assert_called_once_with([0x10 | 0x80, 0])
+
+
+@pytest.mark.parametrize(
+    ("mdmcfg4_before", "mdmcfg4_after", "exponent"),
+    (
+        (0b10001100, 0b10001100, 12),
+        (0b10001100, 0b10001111, 15),
+        (0b10001100, 0b10000000, 0),
+        (0b10001100, 0b10001010, 0b1010),
+        (0b01111100, 0b01111100, 12),
+        (0b01111100, 0b01111111, 15),
+        (0b01111100, 0b01110000, 0),
+        (0b01110001, 0b01111100, 12),
+    ),
+)
+def test__set_symbol_rate_exponent(
+    transceiver, mdmcfg4_before, mdmcfg4_after, exponent
+):
+    transceiver._spi.xfer.return_value = [0x0F, 0x0F]
+    with unittest.mock.patch.object(
+        transceiver, "_read_single_byte", return_value=mdmcfg4_before
+    ):
+        transceiver._set_symbol_rate_exponent(exponent)
+    transceiver._spi.xfer.assert_called_once_with([0x10 | 0x40, mdmcfg4_after])

+ 0 - 9
tests/test_config.py

@@ -112,15 +112,6 @@ def test__set_filter_bandwidth(
     transceiver._spi.xfer.assert_called_once_with([0x10 | 0x40, mdmcfg4_after])
 
 
-@pytest.mark.parametrize(
-    ("mdmcfg4", "symbol_rate_exponent"), [(0b1001100, 12), (0b10011001, 9)]
-)
-def test__get_symbol_rate_exponent(transceiver, mdmcfg4, symbol_rate_exponent):
-    transceiver._spi.xfer.return_value = [15, mdmcfg4]
-    assert transceiver._get_symbol_rate_exponent() == symbol_rate_exponent
-    transceiver._spi.xfer.assert_called_once_with([0x10 | 0x80, 0])
-
-
 @pytest.mark.parametrize(
     ("mdmcfg3", "symbol_rate_mantissa"), [(0b00100010, 34), (0b10101010, 170)]
 )