From ced63e3d5c5d401754e9600aca341f7ae2605877 Mon Sep 17 00:00:00 2001 From: JMTyndall Date: Fri, 6 Dec 2024 20:35:24 +0000 Subject: [PATCH 1/3] #32 Find configuration files with ".yml" suffix --- check_done/config.py | 11 +++++++---- tests/test_config.py | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/check_done/config.py b/check_done/config.py index 4218e54..e03bd29 100644 --- a/check_done/config.py +++ b/check_done/config.py @@ -138,13 +138,16 @@ def default_config_path() -> Path: previous_config_folder = None result = None while result is None and config_folder != previous_config_folder: - # TODO#32 Check yaml and yml, if both exist yaml is picked over yml. - config_path_to_check = (config_folder / CONFIG_BASE_NAME).with_suffix(".yaml") - if config_path_to_check.is_file(): - result = config_path_to_check + config_path_to_check_yaml = (config_folder / CONFIG_BASE_NAME).with_suffix(".yaml") + config_path_to_check_yml = (config_folder / CONFIG_BASE_NAME).with_suffix(".yml") + if config_path_to_check_yaml.is_file(): + result = config_path_to_check_yaml + elif config_path_to_check_yml.is_file(): + result = config_path_to_check_yml else: previous_config_folder = config_folder config_folder = config_folder.parent + if result is None: raise FileNotFoundError( f"Cannot find configuration file by looking for {CONFIG_BASE_NAME}.yaml " diff --git a/tests/test_config.py b/tests/test_config.py index 5791aff..a4710ba 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -183,6 +183,26 @@ def test_can_resolve_config_default_path(): assert actual_config_path == expected_config_path +def test_can_resolve_config_default_path_yml(): + with tempfile.TemporaryDirectory() as temp_folder, change_current_folder(temp_folder): + current_folder = Path(os.getcwd()) + expected_config_path = (current_folder / CONFIG_BASE_NAME).with_suffix(".yml") + expected_config_path.write_text("") + actual_config_path = default_config_path() + assert actual_config_path == expected_config_path + + +def test_can_resolve_config_default_path_yml_and_yaml(): + with tempfile.TemporaryDirectory() as temp_folder, change_current_folder(temp_folder): + current_folder = Path(os.getcwd()) + expected_config_path_yaml = (current_folder / CONFIG_BASE_NAME).with_suffix(".yaml") + expected_config_path_yml = (current_folder / CONFIG_BASE_NAME).with_suffix(".yml") + expected_config_path_yml.write_text("") + expected_config_path_yaml.write_text("") + actual_config_path = default_config_path() + assert actual_config_path == expected_config_path_yaml + + def test_fails_on_missing_default_config_path(): with ( tempfile.TemporaryDirectory() as temp_folder, From 99103c3947e2b9d138b9e6d7ba54b3fcddcccdd8 Mon Sep 17 00:00:00 2001 From: Thomas Aglassinger Date: Sat, 7 Dec 2024 06:21:49 +0100 Subject: [PATCH 2/3] #32 Clean up code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mek Skëndo --- check_done/config.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/check_done/config.py b/check_done/config.py index e03bd29..7c57d13 100644 --- a/check_done/config.py +++ b/check_done/config.py @@ -138,13 +138,9 @@ def default_config_path() -> Path: previous_config_folder = None result = None while result is None and config_folder != previous_config_folder: - config_path_to_check_yaml = (config_folder / CONFIG_BASE_NAME).with_suffix(".yaml") - config_path_to_check_yml = (config_folder / CONFIG_BASE_NAME).with_suffix(".yml") - if config_path_to_check_yaml.is_file(): - result = config_path_to_check_yaml - elif config_path_to_check_yml.is_file(): - result = config_path_to_check_yml - else: + config_paths_to_check = [(config_folder / CONFIG_BASE_NAME).with_suffix(suffix) for suffix in [".yaml", ".yml"]] + result = next((path for path in config_paths_to_check if path.is_file()), None) + if result is None: previous_config_folder = config_folder config_folder = config_folder.parent From f6be54ed17a1d6731c7726094cfb0d297425fbf3 Mon Sep 17 00:00:00 2001 From: Thomas Aglassinger Date: Sat, 7 Dec 2024 06:27:43 +0100 Subject: [PATCH 3/3] #32 Clean up naming and formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mek Skëndo --- check_done/config.py | 1 - tests/test_config.py | 15 ++++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/check_done/config.py b/check_done/config.py index 7c57d13..8df9e14 100644 --- a/check_done/config.py +++ b/check_done/config.py @@ -143,7 +143,6 @@ def default_config_path() -> Path: if result is None: previous_config_folder = config_folder config_folder = config_folder.parent - if result is None: raise FileNotFoundError( f"Cannot find configuration file by looking for {CONFIG_BASE_NAME}.yaml " diff --git a/tests/test_config.py b/tests/test_config.py index a4710ba..d3c3a68 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -183,7 +183,7 @@ def test_can_resolve_config_default_path(): assert actual_config_path == expected_config_path -def test_can_resolve_config_default_path_yml(): +def test_can_resolve_default_config_path_with_yml_file_suffix(): with tempfile.TemporaryDirectory() as temp_folder, change_current_folder(temp_folder): current_folder = Path(os.getcwd()) expected_config_path = (current_folder / CONFIG_BASE_NAME).with_suffix(".yml") @@ -192,15 +192,16 @@ def test_can_resolve_config_default_path_yml(): assert actual_config_path == expected_config_path -def test_can_resolve_config_default_path_yml_and_yaml(): +def test_can_resolve_default_config_path_when_both_yaml_and_yml_config_files_exist(): with tempfile.TemporaryDirectory() as temp_folder, change_current_folder(temp_folder): current_folder = Path(os.getcwd()) - expected_config_path_yaml = (current_folder / CONFIG_BASE_NAME).with_suffix(".yaml") - expected_config_path_yml = (current_folder / CONFIG_BASE_NAME).with_suffix(".yml") - expected_config_path_yml.write_text("") - expected_config_path_yaml.write_text("") + current_folder = Path(os.getcwd()) + expected_config_path_with_prioritized_yaml_suffix = (current_folder / CONFIG_BASE_NAME).with_suffix(".yaml") + expected_config_path_with_prioritized_yaml_suffix.write_text("") + another_valid_config_path_with_yml_suffix = (current_folder / CONFIG_BASE_NAME).with_suffix(".yml") + another_valid_config_path_with_yml_suffix.write_text("") actual_config_path = default_config_path() - assert actual_config_path == expected_config_path_yaml + assert actual_config_path == expected_config_path_with_prioritized_yaml_suffix def test_fails_on_missing_default_config_path():