8OI-519 regression tests — :func:`oct.core.octrc.load_octrc` and its silent
9wrapper :func:`load_octrc_safe` must be the single source of truth for
10``.octrc.json`` reads. This test exercises the contract that multiple
11historical readers (linter, formatter, health, typecheck) now rely on.
15- Missing file → ``({}, [])``; ``load_octrc_safe`` → ``{}``.
16- Valid JSON object → parsed dict, no errors.
17- Invalid JSON → ``({}, [<error>])``.
18- Non-object top-level JSON (e.g. a list) → ``({}, [<error>])``.
19- OSError on read → ``({}, [<error>])``.
26 L3 — assertion details
31- All file reads and writes use ``tmp_path``; no real ``.octrc.json``
36from pathlib
import Path
38from oct.core.octrc
import load_octrc, load_octrc_safe
42 data, errors = load_octrc(tmp_path)
45 assert load_octrc_safe(tmp_path) == {}
49 cfg = {
"linter": {
"profile":
"strict"},
"health": {
"test_timeout": 60}}
50 (tmp_path /
".octrc.json").write_text(json.dumps(cfg), encoding=
"utf-8")
52 data, errors = load_octrc(tmp_path)
55 assert load_octrc_safe(tmp_path) == cfg
59 (tmp_path /
".octrc.json").write_text(
"{not valid json", encoding=
"utf-8")
61 data, errors = load_octrc(tmp_path)
63 assert len(errors) == 1
64 assert "invalid JSON" in errors[0]
65 assert load_octrc_safe(tmp_path) == {}
69 (tmp_path /
".octrc.json").write_text(
"[1, 2, 3]", encoding=
"utf-8")
71 data, errors = load_octrc(tmp_path)
73 assert len(errors) == 1
74 assert "JSON object" in errors[0]
75 assert "list" in errors[0]
test_missing_file_returns_empty(Path tmp_path)
test_non_object_top_level_returns_error(Path tmp_path)
test_valid_object_returns_dict(Path tmp_path)
test_invalid_json_returns_error(Path tmp_path)