From 23dc0a9fdd4f5d43f7bfd643d11e2e3b2225bf7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20F=C3=B6rster?= Date: Fri, 14 Mar 2025 12:47:13 +0100 Subject: [PATCH] add check for directory in config loader --- pyproject.toml | 2 +- src/dopt_basics/configs.py | 3 +++ tests/test_configs.py | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 84ab60e..b764df6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "dopt-basics" -version = "0.1.1" +version = "0.1.2" description = "basic cross-project tools for Python-based d-opt projects" authors = [ {name = "Florian Förster", email = "f.foerster@d-opt.com"}, diff --git a/src/dopt_basics/configs.py b/src/dopt_basics/configs.py index 60b5685..33bdffb 100644 --- a/src/dopt_basics/configs.py +++ b/src/dopt_basics/configs.py @@ -14,6 +14,9 @@ def load_toml( if not path_to_toml.exists(): raise FileNotFoundError(f"Config file seems not to exist under: >{path_to_toml}<") + if not path_to_toml.is_file(): + raise ValueError("Object to which path points must be a file.") + path_to_toml = path_to_toml.with_suffix(".toml") with open(path_to_toml, "rb") as f: diff --git a/tests/test_configs.py b/tests/test_configs.py index 35c2db5..cd90992 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -34,3 +34,10 @@ def test_load_toml_FailWrongPath(tmp_path): with pytest.raises(FileNotFoundError): _ = configs.load_toml(wrong_pth) + + +def test_load_toml_FailIsDirectory(config_file): + wrong_pth = config_file.parent + + with pytest.raises(ValueError): + _ = configs.load_toml(wrong_pth)