diff --git a/tests/test_config.py b/tests/test_config.py index 3c279f2..cc31db8 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -4,6 +4,7 @@ import pytest import hashlib import confighelper import shutil +import time from confighelper import ConfigError from moonraker import Server from utils import ServerError @@ -52,9 +53,9 @@ class TestConfigGeneric: sec = config["file_manager"] assert sec.section == "file_manager" - def test_get_item_fail(self, config: ConfigHelper): + def test_no_section_fail(self, config: ConfigHelper): with pytest.raises(ConfigError): - config["not_available"] + config["not_available"].get("no_section") def test_contains(self, config: ConfigHelper): assert "file_manager" in config @@ -112,20 +113,20 @@ class TestGetString: val = test_config.get("test_string") assert val == "Hello World" - def test_get_st_fail(self, test_config: ConfigHelper): + def test_get_str_fail(self, test_config: ConfigHelper): with pytest.raises(ConfigError): test_config.get("invalid_option") - def test_get_st_default(self, test_config: ConfigHelper): + def test_get_str_default(self, test_config: ConfigHelper): assert test_config.get("invalid_option", None) is None - def test_get_int_deprecate(self, test_config: ConfigHelper): + def test_get_str_deprecate(self, test_config: ConfigHelper): server = test_config.get_server() test_config.get("test_string", deprecate=True) expected = ( - f"[test_options]: Option 'test_string' in is " + f"[test_options]: Option 'test_string' is " "deprecated, see the configuration documention " - "at https://moonraker.readthedocs.io" + "at https://moonraker.readthedocs.io/en/latest/configuration" ) assert expected in server.warnings @@ -166,9 +167,9 @@ class TestGetInt: server = test_config.get_server() test_config.getint("test_int", deprecate=True) expected = ( - f"[test_options]: Option 'test_int' in is " + f"[test_options]: Option 'test_int' is " "deprecated, see the configuration documention " - "at https://moonraker.readthedocs.io" + "at https://moonraker.readthedocs.io/en/latest/configuration" ) assert expected in server.warnings @@ -209,9 +210,9 @@ class TestGetFloat: server = test_config.get_server() test_config.getfloat("test_float", deprecate=True) expected = ( - f"[test_options]: Option 'test_float' in is " + f"[test_options]: Option 'test_float' is " "deprecated, see the configuration documention " - "at https://moonraker.readthedocs.io" + "at https://moonraker.readthedocs.io/en/latest/configuration" ) assert expected in server.warnings @@ -231,9 +232,9 @@ class TestGetBoolean: server = test_config.get_server() test_config.getboolean("test_bool", deprecate=True) expected = ( - f"[test_options]: Option 'test_bool' in is " + f"[test_options]: Option 'test_bool' is " "deprecated, see the configuration documention " - "at https://moonraker.readthedocs.io" + "at https://moonraker.readthedocs.io/en/latest/configuration" ) assert expected in server.warnings @@ -266,9 +267,9 @@ class TestGetList: server = test_config.get_server() test_config.getlist("test_list", deprecate=True) expected = ( - f"[test_options]: Option 'test_list' in is " + f"[test_options]: Option 'test_list' is " "deprecated, see the configuration documention " - "at https://moonraker.readthedocs.io" + "at https://moonraker.readthedocs.io/en/latest/configuration" ) assert expected in server.warnings @@ -297,9 +298,9 @@ class TestGetDict: server = test_config.get_server() test_config.getdict("test_dict", deprecate=True) expected = ( - f"[test_options]: Option 'test_dict' in is " + f"[test_options]: Option 'test_dict' is " "deprecated, see the configuration documention " - "at https://moonraker.readthedocs.io" + "at https://moonraker.readthedocs.io/en/latest/configuration" ) assert expected in server.warnings @@ -343,9 +344,9 @@ class TestGetTemplate: server = test_config.get_server() test_config.gettemplate("test_template", deprecate=True) expected = ( - f"[test_options]: Option 'test_template' in is " + f"[test_options]: Option 'test_template' is " "deprecated, see the configuration documention " - "at https://moonraker.readthedocs.io" + "at https://moonraker.readthedocs.io/en/latest/configuration" ) assert expected in server.warnings @@ -417,9 +418,9 @@ class TestGetGpioOut: server = gpio_config.get_server() gpio_config.getgpioout("test_gpio", deprecate=True) expected = ( - f"[test_options]: Option 'test_gpio' in is " + f"[test_options]: Option 'test_gpio' is " "deprecated, see the configuration documention " - "at https://moonraker.readthedocs.io" + "at https://moonraker.readthedocs.io/en/latest/configuration" ) assert expected in server.warnings @@ -460,35 +461,32 @@ class TestGetConfiguration: confighelper.get_configuration(base_server, args) class TestBackupConfig: - def test_backup_fail(self, caplog: pytest.LogCaptureFixture): - fake_path = pathlib.Path("no_exist") - if fake_path.exists(): - pytest.fail("Path exists") - confighelper.backup_config(fake_path) - assert "Failed to create a backup" == caplog.messages[-1] - def test_find_backup_fail(self): fake_path = pathlib.Path("no_exist") if fake_path.exists(): - pytest.fail("Path exists") + fake_path.unlink() result = confighelper.find_config_backup(fake_path) assert result is None - def test_backup_config_success(self, path_args: Dict[str, pathlib.Path]): + def test_backup_config_success( + self, path_args: Dict[str, pathlib.Path], config: ConfigHelper + ): cfg_path = path_args["moonraker.conf"] bkp_dest = cfg_path.parent.joinpath(f".{cfg_path.name}.bkp") if bkp_dest.exists(): pytest.fail("Backup Already Exists") - confighelper.backup_config(str(cfg_path)) + config.create_backup() assert bkp_dest.is_file() - def test_backup_skip(self, path_args: Dict[str, pathlib.Path]): + def test_backup_skip( + self, path_args: Dict[str, pathlib.Path], config: ConfigHelper + ): cfg_path = path_args["moonraker.conf"] bkp_dest = cfg_path.parent.joinpath(f".{cfg_path.name}.bkp") if not bkp_dest.exists(): pytest.fail("Backup Not Present") stat = bkp_dest.stat() - confighelper.backup_config(str(cfg_path)) + config.create_backup() assert stat == bkp_dest.stat() def test_find_backup(self, path_args: Dict[str, pathlib.Path]):