test_remote_control.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import unittest.mock
  2. import pytest
  3. import intertechno_cc1101
  4. # pylint: disable=protected-access
  5. @pytest.mark.parametrize(
  6. ("address", "button_index", "command", "expected_message"),
  7. ((12345678, 0, 0b00, 790123392), (2 ** 26 - 1, 0b1111, 0b01, 4294967263)),
  8. )
  9. def test__send_command(address, button_index, command, expected_message):
  10. remote_control = intertechno_cc1101.RemoteControl(address=address)
  11. with unittest.mock.patch(
  12. "intertechno_cc1101._encode_message", return_value=b"dummy"
  13. ) as encode_message_mock, unittest.mock.patch(
  14. "intertechno_cc1101._cc1101_transmit"
  15. ) as transmit_mock:
  16. remote_control._send_command(button_index=button_index, command=command)
  17. encode_message_mock.assert_called_once_with(expected_message)
  18. transmit_mock.assert_called_once_with(b"dummy")
  19. @pytest.mark.parametrize("address", [12345678])
  20. @pytest.mark.parametrize("button_index", [7])
  21. def test_turn_on(address, button_index):
  22. remote_control = intertechno_cc1101.RemoteControl(address=address)
  23. with unittest.mock.patch.object(
  24. remote_control, "_send_command"
  25. ) as send_command_mock:
  26. remote_control.turn_on(button_index=button_index)
  27. send_command_mock.assert_called_once_with(button_index=button_index, command=0b01)
  28. @pytest.mark.parametrize("address", [12345678])
  29. @pytest.mark.parametrize("button_index", [7])
  30. def test_turn_off(address, button_index):
  31. remote_control = intertechno_cc1101.RemoteControl(address=address)
  32. with unittest.mock.patch.object(
  33. remote_control, "_send_command"
  34. ) as send_command_mock:
  35. remote_control.turn_off(button_index=button_index)
  36. send_command_mock.assert_called_once_with(button_index=button_index, command=0b00)