|
@@ -25,6 +25,7 @@ import pytest
|
|
|
|
|
|
import switchbot_mqtt
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -93,7 +94,6 @@ def test__main(
|
|
|
with unittest.mock.patch("switchbot_mqtt._run") as run_mock, unittest.mock.patch(
|
|
|
"sys.argv", argv
|
|
|
):
|
|
|
-
|
|
|
switchbot_mqtt._main()
|
|
|
run_mock.assert_called_once_with(
|
|
|
mqtt_host=expected_mqtt_host,
|
|
@@ -138,7 +138,6 @@ def test__main_mqtt_password_file(
|
|
|
str(mqtt_password_path),
|
|
|
],
|
|
|
):
|
|
|
-
|
|
|
switchbot_mqtt._main()
|
|
|
run_mock.assert_called_once_with(
|
|
|
mqtt_host="localhost",
|
|
@@ -167,7 +166,6 @@ def test__main_mqtt_password_file_collision(capsys):
|
|
|
],
|
|
|
):
|
|
|
with pytest.raises(SystemExit):
|
|
|
-
|
|
|
switchbot_mqtt._main()
|
|
|
out, err = capsys.readouterr()
|
|
|
assert not out
|
|
@@ -197,7 +195,6 @@ def test__main_device_password_file(tmpdir, device_passwords):
|
|
|
str(device_passwords_path),
|
|
|
],
|
|
|
):
|
|
|
-
|
|
|
switchbot_mqtt._main()
|
|
|
run_mock.assert_called_once_with(
|
|
|
mqtt_host="localhost",
|
|
@@ -219,7 +216,6 @@ def test__main_fetch_device_info():
|
|
|
"localhost",
|
|
|
],
|
|
|
):
|
|
|
-
|
|
|
switchbot_mqtt._main()
|
|
|
default_kwargs = dict(
|
|
|
mqtt_host="localhost",
|
|
@@ -234,7 +230,24 @@ def test__main_fetch_device_info():
|
|
|
"sys.argv",
|
|
|
["", "--mqtt-host", "localhost", "--fetch-device-info"],
|
|
|
):
|
|
|
-
|
|
|
+ switchbot_mqtt._main()
|
|
|
+ run_mock.assert_called_once_with(fetch_device_info=True, **default_kwargs)
|
|
|
+ with unittest.mock.patch("switchbot_mqtt._run") as run_mock, unittest.mock.patch(
|
|
|
+ "sys.argv",
|
|
|
+ ["", "--mqtt-host", "localhost"],
|
|
|
+ ), unittest.mock.patch.dict("os.environ", {"FETCH_DEVICE_INFO": "21"}):
|
|
|
+ switchbot_mqtt._main()
|
|
|
+ run_mock.assert_called_once_with(fetch_device_info=True, **default_kwargs)
|
|
|
+ with unittest.mock.patch("switchbot_mqtt._run") as run_mock, unittest.mock.patch(
|
|
|
+ "sys.argv",
|
|
|
+ ["", "--mqtt-host", "localhost"],
|
|
|
+ ), unittest.mock.patch.dict("os.environ", {"FETCH_DEVICE_INFO": ""}):
|
|
|
+ switchbot_mqtt._main()
|
|
|
+ run_mock.assert_called_once_with(fetch_device_info=False, **default_kwargs)
|
|
|
+ with unittest.mock.patch("switchbot_mqtt._run") as run_mock, unittest.mock.patch(
|
|
|
+ "sys.argv",
|
|
|
+ ["", "--mqtt-host", "localhost"],
|
|
|
+ ), unittest.mock.patch.dict("os.environ", {"FETCH_DEVICE_INFO": " "}):
|
|
|
switchbot_mqtt._main()
|
|
|
run_mock.assert_called_once_with(fetch_device_info=True, **default_kwargs)
|
|
|
|
|
@@ -260,7 +273,6 @@ def test__main_log_config(
|
|
|
) as logging_basic_config_mock, unittest.mock.patch(
|
|
|
"switchbot_mqtt._run"
|
|
|
):
|
|
|
-
|
|
|
switchbot_mqtt._main()
|
|
|
logging_basic_config_mock.assert_called_once_with(
|
|
|
level=root_log_level, format=log_format, datefmt="%Y-%m-%dT%H:%M:%S%z"
|