1
0

test_str.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import unittest.mock
  2. import pytest
  3. import cc1101
  4. @pytest.mark.parametrize(
  5. ("transceiver_str", "sync_word"),
  6. (
  7. (
  8. "CC1101(marcstate=idle, base_frequency=433.92MHz, "
  9. "symbol_rate=2.14kBaud, modulation_format=ASK_OOK, "
  10. "sync_mode=NO_PREAMBLE_AND_SYNC_WORD, packet_length=21B, output_power=(0,0xc0))",
  11. None,
  12. ),
  13. (
  14. "CC1101(marcstate=idle, base_frequency=433.92MHz, "
  15. "symbol_rate=2.14kBaud, modulation_format=ASK_OOK, "
  16. "sync_mode=TRANSMIT_16_MATCH_15_BITS, preamble_length=4B, sync_word=0x01ef, "
  17. "packet_length=21B, output_power=(0,0xc0))",
  18. b"\x01\xef",
  19. ),
  20. ),
  21. )
  22. def test___str___(transceiver_str, sync_word):
  23. transceiver = cc1101.CC1101()
  24. with unittest.mock.patch.object(
  25. transceiver,
  26. "get_main_radio_control_state_machine_state",
  27. return_value=cc1101.MainRadioControlStateMachineState.IDLE,
  28. ), unittest.mock.patch.object(
  29. transceiver, "get_base_frequency_hertz", return_value=433.92e6
  30. ), unittest.mock.patch.object(
  31. transceiver, "get_symbol_rate_baud", return_value=2142
  32. ), unittest.mock.patch.object(
  33. transceiver,
  34. "get_modulation_format",
  35. return_value=cc1101.ModulationFormat.ASK_OOK,
  36. ), unittest.mock.patch.object(
  37. transceiver,
  38. "get_sync_mode",
  39. return_value=cc1101.SyncMode.TRANSMIT_16_MATCH_15_BITS
  40. if sync_word
  41. else cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD,
  42. ), unittest.mock.patch.object(
  43. transceiver, "get_preamble_length_bytes", return_value=4
  44. ), unittest.mock.patch.object(
  45. transceiver, "get_sync_word", return_value=sync_word
  46. ), unittest.mock.patch.object(
  47. transceiver,
  48. "get_packet_length_mode",
  49. return_value=cc1101.PacketLengthMode.FIXED,
  50. ), unittest.mock.patch.object(
  51. transceiver, "get_packet_length_bytes", return_value=21
  52. ), unittest.mock.patch.object(
  53. transceiver, "get_output_power", return_value=(0, 0xC0)
  54. ):
  55. assert str(transceiver) == transceiver_str