Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#32 Find configuration files with ".yml" suffix #42

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
mcsken marked this conversation as resolved.
Show resolved Hide resolved

roskakori marked this conversation as resolved.
Show resolved Hide resolved
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():
mcsken marked this conversation as resolved.
Show resolved Hide resolved
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():
roskakori marked this conversation as resolved.
Show resolved Hide resolved
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
mcsken marked this conversation as resolved.
Show resolved Hide resolved


def test_fails_on_missing_default_config_path():
with (
tempfile.TemporaryDirectory() as temp_folder,
Expand Down
Loading