|
@@ -0,0 +1,35 @@
|
|
|
+import unittest.mock
|
|
|
+
|
|
|
+import pytest
|
|
|
+
|
|
|
+import intertechno_cc1101._cli
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.parametrize(
|
|
|
+ ("argv", "address", "button_index", "turn_on"),
|
|
|
+ (
|
|
|
+ (["-a", "12345678", "-1"], 12345678, 0, True),
|
|
|
+ (["-a", "12345678", "-0"], 12345678, 0, False),
|
|
|
+ (["--address", "12345678", "--turn-on"], 12345678, 0, True),
|
|
|
+ (["-a", "12345678", "--turn-off"], 12345678, 0, False),
|
|
|
+ (["-a", "12345678", "-b", "7", "-1"], 12345678, 7, True),
|
|
|
+ ),
|
|
|
+)
|
|
|
+def test__main(argv, address, button_index, turn_on):
|
|
|
+ with unittest.mock.patch(
|
|
|
+ "intertechno_cc1101.RemoteControl"
|
|
|
+ ) as remote_control_class_mock, unittest.mock.patch("sys.argv", [""] + argv):
|
|
|
+ intertechno_cc1101._cli._main()
|
|
|
+ remote_control_class_mock.assert_called_once_with(address=address)
|
|
|
+ if turn_on:
|
|
|
+ remote_control_class_mock().turn_on.assert_called_once_with(
|
|
|
+ button_index=button_index
|
|
|
+ )
|
|
|
+ remote_control_class_mock().turn_off.assert_not_called()
|
|
|
+ else:
|
|
|
+ remote_control_class_mock().turn_off.assert_called_once_with(
|
|
|
+ button_index=button_index
|
|
|
+ )
|
|
|
+ remote_control_class_mock().turn_on.assert_not_called()
|