test_receive.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import unittest.mock
  2. import pytest
  3. # pylint: disable=protected-access
  4. def test__enable_receive_mode(transceiver):
  5. transceiver._spi.xfer.return_value = [15]
  6. transceiver._enable_receive_mode()
  7. transceiver._spi.xfer.assert_called_once_with([0x34 | 0x00])
  8. @pytest.mark.parametrize("payload", [b"\0", b"\x12\x45\x56"])
  9. def test__get_received_packet(transceiver, payload):
  10. fifo_buffer = list(payload) + [128, (1 << 7) | 42]
  11. with unittest.mock.patch.object(
  12. transceiver, "_read_status_register", return_value=len(fifo_buffer)
  13. ) as read_status_register, unittest.mock.patch.object(
  14. transceiver, "_read_burst", return_value=fifo_buffer
  15. ) as read_burst_mock:
  16. received_packet = transceiver._get_received_packet()
  17. read_status_register.assert_called_once_with(0x3B)
  18. read_burst_mock.assert_called_once_with(
  19. start_register=0x3F, length=len(fifo_buffer)
  20. )
  21. assert received_packet.payload == payload
  22. assert received_packet._rssi_index == 128
  23. assert received_packet.checksum_valid
  24. assert received_packet.link_quality_indicator == 42