1
0

test_str.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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=(
  40. cc1101.SyncMode.TRANSMIT_16_MATCH_15_BITS
  41. if sync_word
  42. else cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD
  43. ),
  44. ), unittest.mock.patch.object(
  45. transceiver, "get_preamble_length_bytes", return_value=4
  46. ), unittest.mock.patch.object(
  47. transceiver, "get_sync_word", return_value=sync_word
  48. ), unittest.mock.patch.object(
  49. transceiver,
  50. "get_packet_length_mode",
  51. return_value=cc1101.PacketLengthMode.FIXED,
  52. ), unittest.mock.patch.object(
  53. transceiver, "get_packet_length_bytes", return_value=21
  54. ), unittest.mock.patch.object(
  55. transceiver, "get_output_power", return_value=(0, 0xC0)
  56. ):
  57. assert str(transceiver) == transceiver_str