test_cli.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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"),
  7. (
  8. (["-a", "12345678", "-1"], 12345678, 0, True),
  9. (["-a", "12345678", "-0"], 12345678, 0, False),
  10. (["--address", "12345678", "--turn-on"], 12345678, 0, True),
  11. (["-a", "12345678", "--turn-off"], 12345678, 0, False),
  12. (["-a", "12345678", "-b", "7", "-1"], 12345678, 7, True),
  13. ),
  14. )
  15. def test__main(argv, address, button_index, turn_on):
  16. with unittest.mock.patch(
  17. "intertechno_cc1101.RemoteControl"
  18. ) as remote_control_class_mock, unittest.mock.patch("sys.argv", [""] + argv):
  19. intertechno_cc1101._cli._main()
  20. remote_control_class_mock.assert_called_once_with(address=address)
  21. if turn_on:
  22. remote_control_class_mock().turn_on.assert_called_once_with(
  23. button_index=button_index
  24. )
  25. remote_control_class_mock().turn_off.assert_not_called()
  26. else:
  27. remote_control_class_mock().turn_off.assert_called_once_with(
  28. button_index=button_index
  29. )
  30. remote_control_class_mock().turn_on.assert_not_called()