Miroslav Simko <ms@iolabs.ch> 2026-09-02T11:50:10+02:00
Commit #9 · 3 snippets
src/pipeline/job_config.py | 8 +------- test/test_job_config.py | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-)
| 84 | directory. Malformed JSON, missing required keys and unknown top-level | 84 | directory. Malformed JSON, missing required keys and unknown top-level |
| 85 | keys all raise :class:`JobConfigError` (a :class:`ValueError`). | 85 | keys all raise :class:`JobConfigError` (a :class:`ValueError`). |
| 86 | """ | 86 | """ |
| 87 | path = Path(path) | 87 | path = Path(path) |
| 88 | try: | 88 | raw = config_loader.load_json_overrides(path, error_cls=JobConfigError) |
| 89 | raw = json.loads(path.read_text(encoding="utf-8")) | ||
| 90 | except json.JSONDecodeError as exc: | ||
| 91 | raise JobConfigError(f"Job config {path} is not valid JSON: {exc}") from exc | ||
| 92 | |||
| 93 | if not isinstance(raw, dict): | ||
| 94 | raise JobConfigError(f"Job config {path} must be a JSON object") | ||
| 95 | 89 | ||
| 96 | cfg = config_loader.validate_config( | 90 | cfg = config_loader.validate_config( |
| 97 | JobConfig, | 91 | JobConfig, |
| 98 | raw, | 92 | raw, |
| 269 | def test_load_job_config_rejects_malformed_json(tmp_path: Path) -> None: | 269 | def test_load_job_config_rejects_malformed_json(tmp_path: Path) -> None: |
| 270 | cfg_path = tmp_path / "job.json" | 270 | cfg_path = tmp_path / "job.json" |
| 271 | cfg_path.write_text("{not json", encoding="utf-8") | 271 | cfg_path.write_text("{not json", encoding="utf-8") |
| 272 | 272 | ||
| 273 | with pytest.raises(job_config.JobConfigError, match="not valid JSON"): | 273 | with pytest.raises(job_config.JobConfigError, match="Invalid JSON"): |
| 274 | job_config.load_job_config(cfg_path) | 274 | job_config.load_job_config(cfg_path) |
| 275 | 275 | ||
| 276 | 276 | ||
| 277 | def test_load_job_config_rejects_unknown_device(tmp_path: Path) -> None: | 277 | def test_load_job_config_rejects_unknown_device(tmp_path: Path) -> None: |
| 269 | def test_load_job_config_rejects_malformed_json(tmp_path: Path) -> None: | 269 | def test_load_job_config_rejects_malformed_json(tmp_path: Path) -> None: |
| 270 | cfg_path = tmp_path / "job.json" | 270 | cfg_path = tmp_path / "job.json" |
| 271 | cfg_path.write_text("{not json", encoding="utf-8") | 271 | cfg_path.write_text("{not json", encoding="utf-8") |
| 272 | 272 | ||
| 273 | with pytest.raises(job_config.JobConfigError, match="not valid JSON"): | 273 | with pytest.raises(job_config.JobConfigError, match="Invalid JSON"): |
| 274 | job_config.load_job_config(cfg_path) | 274 | job_config.load_job_config(cfg_path) |
| 275 | 275 | ||
| 276 | 276 | ||
| 277 | def test_load_job_config_rejects_unknown_device(tmp_path: Path) -> None: | 277 | def test_load_job_config_rejects_unknown_device(tmp_path: Path) -> None: |
load_json_overrides; error text changes from “not valid JSON” to “Invalid JSON in config file …”.