123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import pytest
- @pytest.mark.parametrize(
- ("xfer_return_value", "sync_word"),
- [([64, 211, 145], b"\xd3\x91"), ([64, 0, 0], b"\0\0")],
- )
- def test_get_sync_word(transceiver, xfer_return_value, sync_word):
- transceiver._spi.xfer.return_value = xfer_return_value
- assert transceiver.get_sync_word() == sync_word
- transceiver._spi.xfer.assert_called_once_with([0x04 | 0xC0, 0, 0])
- def test_set_sync_word(transceiver):
- transceiver._spi.xfer.return_value = [15, 15, 15]
- transceiver.set_sync_word(b"\x12\x34")
- transceiver._spi.xfer.assert_called_once_with([0x04 | 0x40, 0x12, 0x34])
- @pytest.mark.parametrize("sync_word", [b"", b"\0", "\x12\x34\x56"])
- def test_set_sync_word_invalid_length(transceiver, sync_word):
- with pytest.raises(ValueError, match=r"\bexpected two bytes\b"):
- transceiver.set_sync_word(sync_word)
|