test_cc1101_config.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. import unittest.mock
  2. import cc1101
  3. import pytest
  4. import intertechno_cc1101
  5. # pylint: disable=protected-access
  6. @pytest.mark.parametrize(
  7. "payload",
  8. (
  9. b"\x04\x00\xa0\xa0\x82\xa0\x82\x82\x82\x82\xa0\xa0\xa0\x82\x82\xa0\xa0"
  10. b"\xa0\xa0\x82\xa0\x82\xa0\xa0\x82\x82\x82\xa0\xa0\x82\xa0\xa0\xa0\xa0\x80",
  11. ),
  12. )
  13. def test__cc1101_transmit(payload):
  14. with unittest.mock.patch("cc1101.CC1101") as transceiver_class_mock:
  15. intertechno_cc1101._cc1101_transmit(payload=payload)
  16. transceiver_class_mock.assert_called_once_with(lock_spi_device=True)
  17. method_calls = transceiver_class_mock().__enter__().mock_calls
  18. assert method_calls[:-3] == [
  19. unittest.mock.call.set_base_frequency_hertz(433930000),
  20. unittest.mock.call.set_symbol_rate_baud(3942),
  21. unittest.mock.call.set_sync_mode(cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD),
  22. unittest.mock.call.set_packet_length_mode(cc1101.PacketLengthMode.FIXED),
  23. unittest.mock.call.set_packet_length_bytes(35),
  24. unittest.mock.call.disable_checksum(),
  25. unittest.mock.call.set_output_power((0, 0xC6)),
  26. ]
  27. transmit_call = method_calls[-3]
  28. assert transmit_call == ("transmit", (payload,), {})
  29. assert all(transmit_call == t for t in method_calls[-2:])