1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import unittest.mock
- import pytest
- @pytest.mark.parametrize(
- ("mdmcfg1", "length"),
- [
- (0b00000010, 2),
- (0b00010010, 3),
- (0b00100010, 4),
- (0b00110010, 6),
- (0b01000010, 8),
- (0b01010010, 12),
- (0b01100010, 16),
- (0b01110010, 24),
- ],
- )
- def test_get_preamble_length_bytes(transceiver, mdmcfg1, length):
- transceiver._spi.xfer.return_value = [0, mdmcfg1]
- assert transceiver.get_preamble_length_bytes() == length
- transceiver._spi.xfer.assert_called_once_with([0x13 | 0x80, 0])
- @pytest.mark.parametrize(
- ("mdmcfg1_before", "mdmcfg1_after", "length"),
- [
- (0b00000010, 0b00000010, 2),
- (0b00000010, 0b00010010, 3),
- (0b00000010, 0b00100010, 4),
- (0b00000010, 0b00110010, 6),
- (0b00000010, 0b01000010, 8),
- (0b00000010, 0b01010010, 12),
- (0b00000010, 0b01100010, 16),
- (0b00000010, 0b01110010, 24),
- (0b01010010, 0b01100010, 16),
- (0b01110010, 0b00000010, 2),
- (0b01110010, 0b01000010, 8),
- (0b11011010, 0b11101010, 16),
- (0b11110111, 0b11000111, 8),
- (0b11111110, 0b10001110, 2),
- ],
- )
- def test_set_preamble_length_bytes(transceiver, mdmcfg1_before, mdmcfg1_after, length):
- transceiver._spi.xfer.return_value = [15, 15]
- with unittest.mock.patch.object(
- transceiver, "_read_single_byte", return_value=mdmcfg1_before
- ):
- transceiver.set_preamble_length_bytes(length)
- transceiver._spi.xfer.assert_called_once_with([0x13 | 0x40, mdmcfg1_after])
- @pytest.mark.parametrize(
- "length", [-21, 0, 1, 5, 7, 9, 10, 11, 13, 14, 15, 17, 20, 23, 25, 32, 42]
- )
- def test_set_preamble_length_bytes_invalid(transceiver, length):
- with pytest.raises(ValueError, match=r"\bpreamble length\b"):
- transceiver.set_preamble_length_bytes(length)
|