Browse Source

refactor: move some tests from test_config.py to config/test_0x10_mdmcfg4.py

Fabian Peter Hammerle 3 years ago
parent
commit
e135b455da
3 changed files with 43 additions and 39 deletions
  1. 5 1
      cc1101/__init__.py
  2. 38 0
      tests/config/test_0x10_mdmcfg4.py
  3. 0 38
      tests/test_config.py

+ 5 - 1
cc1101/__init__.py

@@ -270,9 +270,13 @@ class CC1101:
 
     def _get_filter_bandwidth_hertz(self) -> float:
         """
+        MDMCFG4.CHANBW_E & MDMCFG4.CHANBW_M
+
+        > [...] decimation ratio for the delta-sigma ADC input stream
+        > and thus the channel bandwidth.
+
         See "13 Receiver Channel Filter Bandwidth"
 
-        MDMCFG4.CHANBW_E & MDMCFG4.CHANBW_M
         """
         mdmcfg4 = self._read_single_byte(ConfigurationRegisterAddress.MDMCFG4)
         return self._filter_bandwidth_floating_point_to_real(

+ 38 - 0
tests/config/test_0x10_mdmcfg4.py

@@ -22,6 +22,44 @@ import pytest
 # pylint: disable=protected-access
 
 
+@pytest.mark.parametrize(
+    ("mdmcfg4", "real"),
+    [
+        (0b10001100, 203e3),
+        (0b10001010, 203e3),
+        (0b10001110, 203e3),
+        (0b11111100, 58e3),
+        (0b01011100, 325e3),
+    ],
+)
+def test__get_filter_bandwidth_hertz(transceiver, mdmcfg4, real):
+    transceiver._spi.xfer.return_value = [15, mdmcfg4]
+    assert transceiver._get_filter_bandwidth_hertz() == pytest.approx(real, rel=1e-3)
+    transceiver._spi.xfer.assert_called_once_with([0x10 | 0x80, 0])
+
+
+@pytest.mark.parametrize(
+    ("mdmcfg4_before", "mdmcfg4_after", "exponent", "mantissa"),
+    [
+        (0b00001010, 0b10111010, 0b10, 0b11),
+        (0b00001100, 0b01001100, 0b01, 0b00),
+        (0b00001100, 0b10111100, 0b10, 0b11),
+        (0b00001100, 0b11011100, 0b11, 0b01),
+        (0b01011100, 0b11011100, 0b11, 0b01),
+        (0b11111100, 0b11011100, 0b11, 0b01),
+    ],
+)
+def test__set_filter_bandwidth(
+    transceiver, mdmcfg4_before, mdmcfg4_after, exponent, mantissa
+):
+    transceiver._spi.xfer.return_value = [15, 15]
+    with unittest.mock.patch.object(
+        transceiver, "_read_single_byte", return_value=mdmcfg4_before
+    ):
+        transceiver._set_filter_bandwidth(mantissa=mantissa, exponent=exponent)
+    transceiver._spi.xfer.assert_called_once_with([0x10 | 0x40, mdmcfg4_after])
+
+
 @pytest.mark.parametrize(
     ("mdmcfg4", "exponent"),
     (

+ 0 - 38
tests/test_config.py

@@ -74,44 +74,6 @@ def test__filter_bandwidth_floating_point_to_real(mantissa, exponent, real):
     ) == pytest.approx(real, rel=1e-3)
 
 
-@pytest.mark.parametrize(
-    ("mdmcfg4", "real"),
-    [
-        (0b10001100, 203e3),
-        (0b10001010, 203e3),
-        (0b10001110, 203e3),
-        (0b11111100, 58e3),
-        (0b01011100, 325e3),
-    ],
-)
-def test__get_filter_bandwidth_hertz(transceiver, mdmcfg4, real):
-    transceiver._spi.xfer.return_value = [15, mdmcfg4]
-    assert transceiver._get_filter_bandwidth_hertz() == pytest.approx(real, rel=1e-3)
-    transceiver._spi.xfer.assert_called_once_with([0x10 | 0x80, 0])
-
-
-@pytest.mark.parametrize(
-    ("mdmcfg4_before", "mdmcfg4_after", "exponent", "mantissa"),
-    [
-        (0b00001010, 0b10111010, 0b10, 0b11),
-        (0b00001100, 0b01001100, 0b01, 0b00),
-        (0b00001100, 0b10111100, 0b10, 0b11),
-        (0b00001100, 0b11011100, 0b11, 0b01),
-        (0b01011100, 0b11011100, 0b11, 0b01),
-        (0b11111100, 0b11011100, 0b11, 0b01),
-    ],
-)
-def test__set_filter_bandwidth(
-    transceiver, mdmcfg4_before, mdmcfg4_after, exponent, mantissa
-):
-    transceiver._spi.xfer.return_value = [15, 15]
-    with unittest.mock.patch.object(
-        transceiver, "_read_single_byte", return_value=mdmcfg4_before
-    ):
-        transceiver._set_filter_bandwidth(mantissa=mantissa, exponent=exponent)
-    transceiver._spi.xfer.assert_called_once_with([0x10 | 0x40, mdmcfg4_after])
-
-
 @pytest.mark.parametrize(
     ("mdmcfg3", "symbol_rate_mantissa"), [(0b00100010, 34), (0b10101010, 170)]
 )