Option C Tools
Loading...
Searching...
No Matches
test_headers.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# tests/tests_linter/test_headers.py
4
5"""
6Purpose
7-------
8Validate the linter's header detection logic.
9
10Responsibilities
11----------------
12- Confirm correct detection of valid header blocks.
13- Confirm detection of missing or malformed header lines.
14- Ensure header validation behaves deterministically.
15
16Diagnostics
17-----------
18Domain: LINTER-TESTS
19Levels:
20 L2 — lifecycle
21 L3 — semantic details
22 L4 — deep tracing
23
24Contracts
25---------
26- Must not modify fixture files.
27- Must not rely on external state.
28- Must assert only on validation, not fixing.
29"""
30
31from pathlib import Path
32from oct.linter import oct_lint
33
34
35def test_valid_header_block(temp_project_root: Path, linter_ctx: oct_lint.LinterContext):
36 fixture = temp_project_root / "tests_linter" / "fixtures" / "minimal_valid.py"
37 text = fixture.read_text(encoding="utf-8")
38 lines = text.splitlines()
39 ok, errors = oct_lint.validate_header_block(lines, fixture, linter_ctx)
40 assert ok
41 assert errors == []
42
43
44def test_missing_shebang_detected(temp_project_root: Path, linter_ctx: oct_lint.LinterContext):
45 fixture = temp_project_root / "tests_linter" / "fixtures" / "missing_shebang.py"
46 text = fixture.read_text(encoding="utf-8")
47 lines = text.splitlines()
48 ok, errors = oct_lint.validate_header_block(lines, fixture, linter_ctx)
49 assert not ok
50 assert any("Shebang" in e for e in errors)
test_missing_shebang_detected(Path temp_project_root, oct_lint.LinterContext linter_ctx)
test_valid_header_block(Path temp_project_root, oct_lint.LinterContext linter_ctx)