forked from LukasNiessen/ArchUnitPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassertion.py
More file actions
47 lines (35 loc) · 1.4 KB
/
Copy pathassertion.py
File metadata and controls
47 lines (35 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Testing assertion helpers for architecture rules."""
from __future__ import annotations
from archunitpython.common.assertion.violation import Violation
from archunitpython.common.fluentapi.checkable import Checkable, CheckOptions
from archunitpython.testing.common.violation_factory import ViolationFactory
def format_violations(violations: list[Violation]) -> str:
"""Format violations into a human-readable string.
Args:
violations: List of violations to format.
Returns:
Formatted string describing all violations.
"""
if not violations:
return "No violations found."
lines = [f"Found {len(violations)} architecture violation(s):", ""]
for i, violation in enumerate(violations, 1):
tv = ViolationFactory.from_violation(violation)
lines.append(f" {i}. {tv.message}")
lines.append(f" {tv.details}")
lines.append("")
return "\n".join(lines)
def assert_passes(
checkable: Checkable,
options: CheckOptions | None = None,
) -> None:
"""Assert that an architecture rule passes (no violations).
Args:
checkable: Any object with a check() method (implements Checkable).
options: Optional check options.
Raises:
AssertionError: If the rule has violations.
"""
violations = checkable.check(options)
if violations:
raise AssertionError(format_violations(violations))