test_cli.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import unittest.mock
  2. import pytest
  3. import intertechno_cc1101._cli
  4. # pylint: disable=protected-access
  5. @pytest.mark.parametrize(
  6. ("argv", "address", "button_index", "turn_on", "power_setting"),
  7. (
  8. (["-a", "12345678", "-1"], 12345678, 0, True, 0xC6),
  9. (["-a", "12345678", "-0"], 12345678, 0, False, 0xC6),
  10. (["--address", "12345678", "--turn-on"], 12345678, 0, True, 0xC6),
  11. (["-a", "12345678", "--turn-off"], 12345678, 0, False, 0xC6),
  12. (["-a", "12345678", "-b", "7", "-1"], 12345678, 7, True, 0xC6),
  13. (["-a", "12345678", "-1", "-p", str(0xC0)], 12345678, 0, True, 0xC0),
  14. (["-a", "12345678", "-0", "--power-setting", "14"], 12345678, 0, False, 14),
  15. ),
  16. )
  17. def test__main(argv, address, button_index, turn_on, power_setting):
  18. with unittest.mock.patch(
  19. "intertechno_cc1101.RemoteControl"
  20. ) as remote_control_class_mock, unittest.mock.patch("sys.argv", [""] + argv):
  21. intertechno_cc1101._cli._main()
  22. remote_control_class_mock.assert_called_once_with(address=address)
  23. if turn_on:
  24. remote_control_class_mock().turn_on.assert_called_once_with(
  25. button_index=button_index, power_setting=power_setting
  26. )
  27. remote_control_class_mock().turn_off.assert_not_called()
  28. else:
  29. remote_control_class_mock().turn_off.assert_called_once_with(
  30. button_index=button_index, power_setting=power_setting
  31. )
  32. remote_control_class_mock().turn_on.assert_not_called()