add check for directory in config loader

This commit is contained in:
Florian Förster 2025-03-14 12:47:13 +01:00
parent d3f399bd58
commit 23dc0a9fdd
3 changed files with 11 additions and 1 deletions

View File

@ -1,6 +1,6 @@
[project] [project]
name = "dopt-basics" name = "dopt-basics"
version = "0.1.1" version = "0.1.2"
description = "basic cross-project tools for Python-based d-opt projects" description = "basic cross-project tools for Python-based d-opt projects"
authors = [ authors = [
{name = "Florian Förster", email = "f.foerster@d-opt.com"}, {name = "Florian Förster", email = "f.foerster@d-opt.com"},

View File

@ -14,6 +14,9 @@ def load_toml(
if not path_to_toml.exists(): if not path_to_toml.exists():
raise FileNotFoundError(f"Config file seems not to exist under: >{path_to_toml}<") 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") path_to_toml = path_to_toml.with_suffix(".toml")
with open(path_to_toml, "rb") as f: with open(path_to_toml, "rb") as f:

View File

@ -34,3 +34,10 @@ def test_load_toml_FailWrongPath(tmp_path):
with pytest.raises(FileNotFoundError): with pytest.raises(FileNotFoundError):
_ = configs.load_toml(wrong_pth) _ = 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)