1
0

test_0x3e_patable.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 pytest
  18. # pylint: disable=protected-access
  19. @pytest.mark.parametrize(
  20. "patable",
  21. (
  22. (198, 0, 0, 0, 0, 0, 0, 0), # default
  23. (0, 198, 0, 0, 0, 0, 0, 0), # OOK
  24. (1, 2, 3, 4, 5, 6, 7, 8),
  25. ),
  26. )
  27. def test__get_patable(transceiver, patable):
  28. transceiver._spi.xfer.return_value = [0] + list(patable)
  29. assert transceiver._get_patable() == patable
  30. transceiver._spi.xfer.assert_called_once_with([0x3E | 0xC0] + [0] * 8)
  31. @pytest.mark.parametrize(
  32. "patable",
  33. (
  34. (198, 0, 0, 0, 0, 0, 0, 0), # default
  35. [198, 0, 0, 0, 0, 0, 0, 0],
  36. (0, 198, 0, 0, 0, 0, 0, 0), # OOK
  37. (1, 2, 3, 4, 5, 6, 7, 8),
  38. (1, 2, 3),
  39. (1,),
  40. ),
  41. )
  42. def test__set_patable(transceiver, patable):
  43. transceiver._spi.xfer.return_value = [0b00000111] * (len(patable) + 1)
  44. transceiver._set_patable(patable)
  45. transceiver._spi.xfer.assert_called_once_with([0x3E | 0x40] + list(patable))
  46. @pytest.mark.parametrize(
  47. "patable", ((21, -7), (0, 42, 256), (0, 1, 2, 3, 4, 5, 6, 7, 8))
  48. )
  49. def test__set_patable_invalid(transceiver, patable):
  50. with pytest.raises(Exception):
  51. transceiver._set_patable(patable)
  52. transceiver._spi.xfer.assert_not_called()