test_0x10_mdmcfg4.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # python-cc1101 - Python Library to Transmit RF Signals via CC1101 Transceivers
  2. #
  3. # Copyright (C) 2020 Fabian Peter Hammerle <fabian@hammerle.me>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. import unittest.mock
  18. import pytest
  19. # pylint: disable=protected-access
  20. @pytest.mark.parametrize(
  21. ("mdmcfg4", "exponent"),
  22. (
  23. (0b10001100, 12),
  24. (0b10001001, 9),
  25. (0b10001111, 15),
  26. (0b10000000, 0),
  27. (0b10111100, 12),
  28. (0b10111111, 15),
  29. (0b10110000, 0),
  30. ),
  31. )
  32. def test__get_symbol_rate_exponent(transceiver, mdmcfg4, exponent):
  33. transceiver._spi.xfer.return_value = [15, mdmcfg4]
  34. assert transceiver._get_symbol_rate_exponent() == exponent
  35. transceiver._spi.xfer.assert_called_once_with([0x10 | 0x80, 0])
  36. @pytest.mark.parametrize(
  37. ("mdmcfg4_before", "mdmcfg4_after", "exponent"),
  38. (
  39. (0b10001100, 0b10001100, 12),
  40. (0b10001100, 0b10001111, 15),
  41. (0b10001100, 0b10000000, 0),
  42. (0b10001100, 0b10001010, 0b1010),
  43. (0b01111100, 0b01111100, 12),
  44. (0b01111100, 0b01111111, 15),
  45. (0b01111100, 0b01110000, 0),
  46. (0b01110001, 0b01111100, 12),
  47. ),
  48. )
  49. def test__set_symbol_rate_exponent(
  50. transceiver, mdmcfg4_before, mdmcfg4_after, exponent
  51. ):
  52. transceiver._spi.xfer.return_value = [0x0F, 0x0F]
  53. with unittest.mock.patch.object(
  54. transceiver, "_read_single_byte", return_value=mdmcfg4_before
  55. ):
  56. transceiver._set_symbol_rate_exponent(exponent)
  57. transceiver._spi.xfer.assert_called_once_with([0x10 | 0x40, mdmcfg4_after])