test_cc1101_config.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. @pytest.mark.parametrize("power_setting", (0xC6, 0xC0))
  14. def test__cc1101_transmit(payload, power_setting):
  15. with unittest.mock.patch("cc1101.CC1101") as transceiver_class_mock:
  16. intertechno_cc1101._cc1101_transmit(
  17. payload=payload, power_setting=power_setting
  18. )
  19. transceiver_class_mock.assert_called_once_with(lock_spi_device=True)
  20. with transceiver_class_mock() as transceiver_mock:
  21. method_calls = transceiver_mock.mock_calls
  22. assert method_calls[:-3] == [
  23. unittest.mock.call.set_base_frequency_hertz(433930000),
  24. unittest.mock.call.set_symbol_rate_baud(3942),
  25. unittest.mock.call.set_sync_mode(cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD),
  26. unittest.mock.call.set_packet_length_mode(cc1101.PacketLengthMode.FIXED),
  27. unittest.mock.call.set_packet_length_bytes(35),
  28. unittest.mock.call.disable_checksum(),
  29. unittest.mock.call.set_output_power((0, power_setting)),
  30. ]
  31. transmit_call = method_calls[-3]
  32. assert transmit_call == ("transmit", (payload,), {})
  33. assert all(transmit_call == t for t in method_calls[-2:])