test_0x04_0x05_sync1_sync0.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. ("xfer_return_value", "sync_word"),
  21. [([64, 211, 145], b"\xd3\x91"), ([64, 0, 0], b"\0\0")],
  22. )
  23. def test_get_sync_word(transceiver, xfer_return_value, sync_word):
  24. transceiver._spi.xfer.return_value = xfer_return_value
  25. assert transceiver.get_sync_word() == sync_word
  26. transceiver._spi.xfer.assert_called_once_with([0x04 | 0xC0, 0, 0])
  27. def test_set_sync_word(transceiver):
  28. transceiver._spi.xfer.return_value = [15, 15, 15]
  29. transceiver.set_sync_word(b"\x12\x34")
  30. transceiver._spi.xfer.assert_called_once_with([0x04 | 0x40, 0x12, 0x34])
  31. @pytest.mark.parametrize("sync_word", [b"", b"\0", "\x12\x34\x56"])
  32. def test_set_sync_word_invalid_length(transceiver, sync_word):
  33. with pytest.raises(ValueError, match=r"\bexpected two bytes\b"):
  34. transceiver.set_sync_word(sync_word)