Option C Tools
Loading...
Searching...
No Matches
test_header_fixing.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# tests/tests_linter/test_header_fixing.py
4
5"""
6Purpose
7-------
8Validate the linter's header auto-fixing logic.
9
10Responsibilities
11----------------
12- Ensure missing or incorrect header lines are corrected.
13- Ensure duplicates and misplaced lines are removed.
14- Ensure docstrings and code remain intact.
15- Ensure backup files are created.
16
17Diagnostics
18-----------
19Domain: LINTER-TESTS
20Levels:
21 L2 — lifecycle
22 L3 — semantic details
23 L4 — deep tracing
24
25Contracts
26---------
27- Must not modify fixtures outside the temporary project root.
28- Must verify correctness of the rewritten header block.
29- Must ensure no corruption of module content.
30"""
31
32from pathlib import Path
33from oct.linter import oct_lint
34
35
36def read_lines(path: Path):
37 return path.read_text(encoding="utf-8").splitlines()
38
39
40def test_fix_missing_shebang(temp_project_root: Path, linter_ctx: oct_lint.LinterContext):
41 fixture = temp_project_root / "tests_linter" / "fixtures" / "missing_shebang.py"
42 original = fixture.read_text(encoding="utf-8")
43
44 oct_lint.fix_header_block(fixture, original, linter_ctx)
45 lines = read_lines(fixture)
46
47 assert lines[0].strip() == oct_lint.SHEBANG
48 assert lines[1].strip() == oct_lint.ENCODING
49 assert lines[2].strip().endswith("missing_shebang.py")
50 assert lines[3].strip() == ""
51
52
53def test_fix_wrong_path_header(temp_project_root: Path, linter_ctx: oct_lint.LinterContext):
54 fixture = temp_project_root / "tests_linter" / "fixtures" / "wrong_path_header.py"
55 original = fixture.read_text(encoding="utf-8")
56
57 oct_lint.fix_header_block(fixture, original, linter_ctx)
58 lines = read_lines(fixture)
59
60 assert lines[0].strip() == oct_lint.SHEBANG
61 assert lines[1].strip() == oct_lint.ENCODING
62 assert lines[2].strip().endswith("wrong_path_header.py")
63 assert lines[3].strip() == ""
test_fix_wrong_path_header(Path temp_project_root, oct_lint.LinterContext linter_ctx)
test_fix_missing_shebang(Path temp_project_root, oct_lint.LinterContext linter_ctx)