1234567891011121314151617181920212223242526272829303132333435363738 |
- import unittest.mock
- import cc1101
- import pytest
- import intertechno_cc1101
- # pylint: disable=protected-access
- @pytest.mark.parametrize(
- "payload",
- (
- b"\x04\x00\xa0\xa0\x82\xa0\x82\x82\x82\x82\xa0\xa0\xa0\x82\x82\xa0\xa0"
- b"\xa0\xa0\x82\xa0\x82\xa0\xa0\x82\x82\x82\xa0\xa0\x82\xa0\xa0\xa0\xa0\x80",
- ),
- )
- @pytest.mark.parametrize("power_setting", (0xC6, 0xC0))
- def test__cc1101_transmit(payload, power_setting):
- with unittest.mock.patch("cc1101.CC1101") as transceiver_class_mock:
- intertechno_cc1101._cc1101_transmit(
- payload=payload, power_setting=power_setting
- )
- transceiver_class_mock.assert_called_once_with(lock_spi_device=True)
- with transceiver_class_mock() as transceiver_mock:
- method_calls = transceiver_mock.mock_calls
- assert method_calls[:-3] == [
- unittest.mock.call.set_base_frequency_hertz(433930000),
- unittest.mock.call.set_symbol_rate_baud(3942),
- unittest.mock.call.set_sync_mode(cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD),
- unittest.mock.call.set_packet_length_mode(cc1101.PacketLengthMode.FIXED),
- unittest.mock.call.set_packet_length_bytes(35),
- unittest.mock.call.disable_checksum(),
- unittest.mock.call.set_output_power((0, power_setting)),
- ]
- transmit_call = method_calls[-3]
- assert transmit_call == ("transmit", (payload,), {})
- assert all(transmit_call == t for t in method_calls[-2:])
|