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 all commits
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
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