ploop/scripts/tests/test_check_architecture.py

60 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from __future__ import annotations
from pathlib import Path
import subprocess
import sys
import unittest
REPOSITORY_ROOT = Path(__file__).resolve().parents[2]
CHECK_ARCHITECTURE = REPOSITORY_ROOT / "scripts" / "check_architecture.py"
FIXTURES = REPOSITORY_ROOT / "scripts" / "tests" / "fixtures" / "architecture"
def run_check(target: Path) -> subprocess.CompletedProcess[str]:
return subprocess.run(
[sys.executable, str(CHECK_ARCHITECTURE), str(target)],
cwd=REPOSITORY_ROOT,
text=True,
capture_output=True,
check=False,
)
class CheckArchitectureTest(unittest.TestCase):
def test_accepts_valid_layered_fixture(self) -> None:
result = run_check(FIXTURES / "valid")
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertIn("violations=0", result.stdout)
def test_accepts_current_p0_compatibility_exception(self) -> None:
result = run_check(REPOSITORY_ROOT / "backend" / "src" / "ploop")
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
def test_reports_each_enabled_rule_with_location_and_remediation(self) -> None:
violations = {
"arch001": "ARCH001",
"arch001-file-io": "ARCH001",
"arch002": "ARCH002",
"arch003": "ARCH003",
"arch004": "ARCH004",
"arch004-worker": "ARCH004",
"exec001": "EXEC001",
"exec002": "EXEC002",
"state001": "STATE001",
}
for fixture_name, rule_id in violations.items():
with self.subTest(fixture_name=fixture_name):
result = run_check(FIXTURES / "violations" / fixture_name)
self.assertNotEqual(result.returncode, 0)
self.assertIn(rule_id, result.stdout)
self.assertRegex(result.stdout, r"\.py:\d+:")
self.assertIn(";", result.stdout)
if __name__ == "__main__":
unittest.main()