8OI-501 regression tests — ``.octrc.json`` schema errors must *warn* (not crash)
9in non-strict mode, and *raise* ``SystemExit(2)`` only when strict-config is
10enabled. Prior to the fix, ``raise SystemExit(2)`` was indented at the wrong
11level, so every schema error crashed the linter unconditionally.
15- Non-strict mode + schema error → warning printed to stderr, no SystemExit(2).
16- Strict mode + schema error → SystemExit(2).
17- Strict mode + malformed JSON → SystemExit(2) (unchanged behaviour).
24 L3 — assertion details
29- ``.octrc.json`` handling must not raise in non-strict mode.
34from pathlib
import Path
42 (root /
".octrc.json").write_text(content, encoding=
"utf-8")
46 temp_project_root: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
48 monkeypatch.delenv(
"OCT_STRICT_CONFIG", raising=
False)
50 _write_octrc(temp_project_root,
'{"linter": {"profile": "bogus"}}')
54 oct_lint.run_linter(temp_project_root, argv=[])
55 except SystemExit
as e:
56 assert e.code != 2, f
"non-strict mode must not SystemExit(2); got {e.code}"
58 err = capsys.readouterr().err
59 assert "Warning" in err
60 assert ".octrc.json schema errors" in err
64 temp_project_root: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
66 monkeypatch.setenv(
"OCT_STRICT_CONFIG",
"1")
67 _write_octrc(temp_project_root,
'{"linter": {"profile": "bogus"}}')
69 with pytest.raises(SystemExit)
as exc_info:
70 oct_lint.run_linter(temp_project_root, argv=[])
72 assert exc_info.value.code == 2
73 err = capsys.readouterr().err
75 assert ".octrc.json schema errors" in err
79 temp_project_root: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture
81 monkeypatch.setenv(
"OCT_STRICT_CONFIG",
"1")
84 with pytest.raises(SystemExit)
as exc_info:
85 oct_lint.run_linter(temp_project_root, argv=[])
87 assert exc_info.value.code == 2
test_schema_error_non_strict_warns_but_does_not_exit(Path temp_project_root, pytest.MonkeyPatch monkeypatch, pytest.CaptureFixture capsys)
test_schema_error_strict_mode_exits_2(Path temp_project_root, pytest.MonkeyPatch monkeypatch, pytest.CaptureFixture capsys)
test_malformed_json_strict_mode_exits_2(Path temp_project_root, pytest.MonkeyPatch monkeypatch, pytest.CaptureFixture capsys)
None _write_octrc(Path root, str content)