12345678910111213141516171819202122232425262728293031323334 |
- 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",
- ),
- )
- def test__cc1101_transmit(payload):
- with unittest.mock.patch("cc1101.CC1101") as transceiver_class_mock:
- intertechno_cc1101._cc1101_transmit(payload=payload)
- transceiver_class_mock.assert_called_once_with(lock_spi_device=True)
- method_calls = transceiver_class_mock().__enter__().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, 0xC6)),
- ]
- transmit_call = method_calls[-3]
- assert transmit_call == ("transmit", (payload,), {})
- assert all(transmit_call == t for t in method_calls[-2:])
|