Skip to content

Commit

Permalink
Merge pull request #42 from JMTyndall/32-find-configuration-files-wit…
Browse files Browse the repository at this point in the history
…h-yml-suffix

#32 Find configuration files with ".yml" suffix
  • Loading branch information
mcsken authored Dec 9, 2024
2 parents 4b50d9e + f6be54e commit 98284d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 3 additions & 5 deletions check_done/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 98284d0

Please sign in to comment.