test_cli.py 754 B

123456789101112131415161718192021222324252627
  1. import unittest.mock
  2. import pytest
  3. import switchbot_mqtt
  4. @pytest.mark.parametrize(
  5. ("argv", "expected_mqtt_host", "expected_mqtt_port"),
  6. [
  7. (["", "--mqtt-host", "mqtt-broker.local"], "mqtt-broker.local", 1883),
  8. (
  9. ["", "--mqtt-host", "mqtt-broker.local", "--mqtt-port", "8883"],
  10. "mqtt-broker.local",
  11. 8883,
  12. ),
  13. ],
  14. )
  15. def test__main(argv, expected_mqtt_host, expected_mqtt_port):
  16. with unittest.mock.patch("switchbot_mqtt._run") as run_mock, unittest.mock.patch(
  17. "sys.argv", argv
  18. ):
  19. # pylint: disable=protected-access
  20. switchbot_mqtt._main()
  21. run_mock.assert_called_once_with(
  22. mqtt_host=expected_mqtt_host, mqtt_port=expected_mqtt_port,
  23. )