12345678910111213141516171819202122232425262728293031323334353637 |
- import unittest.mock
- import pytest
- import intertechno_cc1101._cli
- # pylint: disable=protected-access
- @pytest.mark.parametrize(
- ("argv", "address", "button_index", "turn_on", "power_setting"),
- (
- (["-a", "12345678", "-1"], 12345678, 0, True, 0xC6),
- (["-a", "12345678", "-0"], 12345678, 0, False, 0xC6),
- (["--address", "12345678", "--turn-on"], 12345678, 0, True, 0xC6),
- (["-a", "12345678", "--turn-off"], 12345678, 0, False, 0xC6),
- (["-a", "12345678", "-b", "7", "-1"], 12345678, 7, True, 0xC6),
- (["-a", "12345678", "-1", "-p", str(0xC0)], 12345678, 0, True, 0xC0),
- (["-a", "12345678", "-0", "--power-setting", "14"], 12345678, 0, False, 14),
- ),
- )
- def test__main(argv, address, button_index, turn_on, power_setting):
- 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, power_setting=power_setting
- )
- remote_control_class_mock().turn_off.assert_not_called()
- else:
- remote_control_class_mock().turn_off.assert_called_once_with(
- button_index=button_index, power_setting=power_setting
- )
- remote_control_class_mock().turn_on.assert_not_called()
|