test_0x06_pktlen.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 pytest
  18. # pylint: disable=protected-access
  19. def test_get_packet_length_bytes(transceiver):
  20. xfer_mock = transceiver._spi.xfer
  21. xfer_mock.return_value = [0, 8]
  22. assert transceiver.get_packet_length_bytes() == 8
  23. xfer_mock.assert_called_once_with([0x06 | 0x80, 0])
  24. @pytest.mark.parametrize("packet_length", [21])
  25. def test_set_packet_length_bytes(transceiver, packet_length):
  26. xfer_mock = transceiver._spi.xfer
  27. xfer_mock.return_value = [15, 15]
  28. transceiver.set_packet_length_bytes(packet_length)
  29. xfer_mock.assert_called_once_with([0x06 | 0x40, packet_length])
  30. @pytest.mark.parametrize("packet_length", [-21, 0, 256, 1024])
  31. def test_set_packet_length_bytes_fail(transceiver, packet_length):
  32. with pytest.raises(Exception):
  33. transceiver.set_packet_length_bytes(packet_length)
  34. transceiver._spi.xfer.assert_not_called()