simplefe

Log | Files | Refs

commit a0d7aa0cdb13a11984891c9eafcdc0e93ca567bf
parent fd90f77510280e5d90d603402244cb402c058457
Author: Chris Roberts <chris.roberts@learningunix.net>
Date:   Mon, 13 Jul 2026 07:18:52 -0500

Validate that jobs.toml entries have a required path

Raises a custom ConfigError, not a bare ValueError, so callers
can catch config problems specifically without also swallowing
unrelated errors. Tests assert on the specific exception type
and that the message names the offending job, not just that
some error occurred.

Diffstat:
Msrc/simplefe/config.py | 12+++++++++++-
Mtests/test_config.py | 31++++++++++++++++++++++++++++++-
2 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/src/simplefe/config.py b/src/simplefe/config.py @@ -1,7 +1,17 @@ import tomllib +class ConfigError(Exception): + pass + + def load_jobs(path): with open(path, "rb") as f: data = tomllib.load(f) - return data["jobs"] + jobs = data["jobs"] + + for name, job in jobs.items(): + if "path" not in job: + raise ConfigError(f"Job '{name} is missing required key: path") + + return jobs diff --git a/tests/test_config.py b/tests/test_config.py @@ -1,4 +1,15 @@ -from simplefe.config import load_jobs +import pytest + +from simplefe.config import ConfigError, load_jobs + + +def test_load_jobs_raises_on_missing_path(tmp_path): + config_file = tmp_path / "jobs.toml" + config_file.write_text(""" + [jobs.rip] + """) + with pytest.raises(ConfigError, match="rip"): + load_jobs(config_file) def test_load_jobs(tmp_path): @@ -10,3 +21,21 @@ def test_load_jobs(tmp_path): result = load_jobs(config_file) assert result == {"rip": {"path": ".scripts/rip"}} + + +def test_load_jobs_with_multiple_jobs(tmp_path): + config_file = tmp_path / "jobs.toml" + config_file.write_text(""" +[jobs.rip] +path = ".scripts/rip" + +[jobs.encode] +path = ".scripts/encode" +""") + + result = load_jobs(config_file) + + assert result == { + "rip": {"path": ".scripts/rip"}, + "encode": {"path": ".scripts/encode"}, + }