123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import unittest.mock
- import pytest
- import intertechno_cc1101
- # pylint: disable=protected-access
- @pytest.mark.parametrize(
- ("address", "button_index", "command", "expected_message"),
- ((12345678, 0, 0b00, 790123392), (2 ** 26 - 1, 0b1111, 0b01, 4294967263)),
- )
- def test__send_command(address, button_index, command, expected_message):
- remote_control = intertechno_cc1101.RemoteControl(address=address)
- with unittest.mock.patch(
- "intertechno_cc1101._encode_message", return_value=b"dummy"
- ) as encode_message_mock, unittest.mock.patch(
- "intertechno_cc1101._cc1101_transmit"
- ) as transmit_mock:
- remote_control._send_command(button_index=button_index, command=command)
- encode_message_mock.assert_called_once_with(expected_message)
- transmit_mock.assert_called_once_with(b"dummy")
- @pytest.mark.parametrize("address", [12345678])
- @pytest.mark.parametrize("button_index", [7])
- def test_turn_on(address, button_index):
- remote_control = intertechno_cc1101.RemoteControl(address=address)
- with unittest.mock.patch.object(
- remote_control, "_send_command"
- ) as send_command_mock:
- remote_control.turn_on(button_index=button_index)
- send_command_mock.assert_called_once_with(button_index=button_index, command=0b01)
- @pytest.mark.parametrize("address", [12345678])
- @pytest.mark.parametrize("button_index", [7])
- def test_turn_off(address, button_index):
- remote_control = intertechno_cc1101.RemoteControl(address=address)
- with unittest.mock.patch.object(
- remote_control, "_send_command"
- ) as send_command_mock:
- remote_control.turn_off(button_index=button_index)
- send_command_mock.assert_called_once_with(button_index=button_index, command=0b00)
|