Skip to content

Commit

Permalink
add tests for CC1101._set_transceive_mode()
Browse files Browse the repository at this point in the history
  • Loading branch information
fphammerle committed May 25, 2024
1 parent 34b1071 commit a20c0f2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
env:
PYTHON_VERSION: ${{ matrix.python-version }}
- run: pipenv graph
- run: pipenv run pytest --cov="$(cat *.egg-info/top_level.txt)" --cov-report=term-missing --cov-fail-under=97
- run: pipenv run pytest --cov="$(cat *.egg-info/top_level.txt)" --cov-report=term-missing --cov-fail-under=98
- run: pipenv run pylint "$(cat *.egg-info/top_level.txt)"
# https://github.com/PyCQA/pylint/issues/352
- run: pipenv run pylint tests/*
Expand Down
24 changes: 24 additions & 0 deletions tests/config/test_0x08_pktctrl0.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ def test__get_transceive_mode(transceiver: cc1101.CC1101) -> None:
assert transceiver._get_transceive_mode() == _TransceiveMode.ASYNCHRONOUS_SERIAL


@pytest.mark.parametrize(
("pktctrl0_before", "mode", "pktctrl0_after"),
[
(0b01000101, _TransceiveMode.FIFO, 0b01000101),
(0b01000101, _TransceiveMode.SYNCHRONOUS_SERIAL, 0b01010101),
(0b01000101, _TransceiveMode.ASYNCHRONOUS_SERIAL, 0b01110101),
(0b11111111, _TransceiveMode.FIFO, 0b11001111),
],
)
def test__set_transceive_mode(
transceiver: cc1101.CC1101,
pktctrl0_before: int,
mode: _TransceiveMode,
pktctrl0_after: int,
) -> None:
xfer_mock = transceiver._spi.xfer
xfer_mock.return_value = [0xFF] * 2 # chip status byte
with unittest.mock.patch.object(
transceiver, "_read_single_byte", return_value=pktctrl0_before
):
transceiver._set_transceive_mode(mode)
xfer_mock.assert_called_once_with([0x08 | 0x40, pktctrl0_after])


@pytest.mark.parametrize(
("pktctrl0_before", "pktctrl0_after"),
(
Expand Down

0 comments on commit a20c0f2

Please sign in to comment.