Skip to content

Commit

Permalink
#32 Find configuration files with ".yml" suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
JMTyndall committed Dec 6, 2024
1 parent 4b50d9e commit ced63e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
11 changes: 7 additions & 4 deletions check_done/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
20 changes: 20 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ced63e3

Please sign in to comment.