Option C Tools
Loading...
Searching...
No Matches
test_regression.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# tests/tests_linter/test_regression.py
4
5"""
6Purpose
7-------
8Ensure previously fixed bugs never reappear.
9
10Responsibilities
11----------------
12- Test scenarios that historically caused linter failures.
13- Validate docstring preservation.
14- Validate encoding preservation.
15- Validate correct handling of tricky edge cases.
16
17Diagnostics
18-----------
19Domain: LINTER-TESTS
20Levels:
21 L2 — lifecycle
22 L3 — semantic details
23 L4 — deep tracing
24
25Contracts
26---------
27- Must encode each regression as a permanent test.
28- Must ensure fixes remain stable across refactors.
29- Must not modify fixture files.
30"""
31
32from pathlib import Path
33from oct.linter import oct_lint
34
35
36def test_docstring_not_overwritten(temp_project_root: Path, linter_ctx: oct_lint.LinterContext):
37 fixture = temp_project_root / "tests_linter" / "fixtures" / "header_below_docstring.py"
38 original = fixture.read_text(encoding="utf-8")
39
40 oct_lint.fix_header_block(fixture, original, linter_ctx)
41 text = fixture.read_text(encoding="utf-8")
42
43 assert '"""' in text.splitlines()[4:], "Docstring should remain after header block"
44 assert "Header below docstring." in text
45
46
47def test_encoding_not_overwritten(temp_project_root: Path, linter_ctx: oct_lint.LinterContext):
48 fixture = temp_project_root / "tests_linter" / "fixtures" / "unicode_content.py"
49 original = fixture.read_text(encoding="utf-8")
50
51 oct_lint.fix_header_block(fixture, original, linter_ctx)
52 lines = fixture.read_text(encoding="utf-8").splitlines()
53
54 assert lines[1].strip() == oct_lint.ENCODING
55 assert "MIDI 🎵 Bridge" in fixture.read_text(encoding="utf-8")
test_encoding_not_overwritten(Path temp_project_root, oct_lint.LinterContext linter_ctx)
test_docstring_not_overwritten(Path temp_project_root, oct_lint.LinterContext linter_ctx)