test_0x22_frend0.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # python-cc1101 - Python Library to Transmit RF Signals via C1101 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. ("frend0_before", "frend0_after", "setting_index"),
  22. [
  23. (0b01000, 0b01000, 0),
  24. (0b01000, 0b01001, 1),
  25. (0b01000, 0b01111, 7),
  26. (0b10000, 0b10000, 0),
  27. (0b10000, 0b10001, 1),
  28. (0b10000, 0b10111, 7),
  29. ],
  30. )
  31. def test__set_power_amplifier_setting_index(
  32. transceiver, frend0_before, frend0_after, setting_index
  33. ):
  34. transceiver._spi.xfer.return_value = [15, 15]
  35. with unittest.mock.patch.object(
  36. transceiver, "_read_single_byte", return_value=frend0_before
  37. ):
  38. transceiver._set_power_amplifier_setting_index(setting_index)
  39. transceiver._spi.xfer.assert_called_once_with([0x22 | 0x40, frend0_after])