diff --git a/check_done/config.py b/check_done/config.py index 4218e54..8df9e14 100644 --- a/check_done/config.py +++ b/check_done/config.py @@ -138,11 +138,9 @@ 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 - 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 if result is None: diff --git a/tests/test_config.py b/tests/test_config.py index 5791aff..d3c3a68 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -183,6 +183,27 @@ def test_can_resolve_config_default_path(): assert actual_config_path == expected_config_path +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") + expected_config_path.write_text("") + actual_config_path = default_config_path() + assert actual_config_path == expected_config_path + + +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()) + 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_with_prioritized_yaml_suffix + + def test_fails_on_missing_default_config_path(): with ( tempfile.TemporaryDirectory() as temp_folder,