Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions checks/dataclasses/dataclasses1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
assert origin.x == 0 and origin.y == 0
assert Point(2, 5).x == 2 and Point(2, 5).y == 5
assert origin.x == 0 and origin.y == 0, (
f"expected origin at (0, 0), got ({origin.x}, {origin.y})"
)
assert Point(2, 5).x == 2 and Point(2, 5).y == 5, (
f"expected Point(2, 5) to have x=2 and y=5, "
f"got x={Point(2, 5).x} and y={Point(2, 5).y}"
)
print("dataclasses1 ✓")
6 changes: 3 additions & 3 deletions checks/dataclasses/dataclasses2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
assert orange.red == 255
assert orange.green == 128
assert orange.blue == 0
assert orange.red == 255, f"expected red=255, got {orange.red}"
assert orange.green == 128, f"expected green=128, got {orange.green}"
assert orange.blue == 0, f"expected blue=0, got {orange.blue}"
assert description == "R=255 G=128 B=0", f"got {description!r}"
print("dataclasses2 ✓")
33 changes: 33 additions & 0 deletions tests/test_dataclasses_assertion_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import ast
from pathlib import Path


CHECKS_DIR = Path(__file__).resolve().parent.parent / "checks" / "dataclasses"


def _asserts_without_messages(path):
tree = ast.parse(path.read_text(encoding="utf-8"))
return [
node
for node in ast.walk(tree)
if isinstance(node, ast.Assert) and node.msg is None
]


def test_dataclasses1_asserts_have_messages():
path = CHECKS_DIR / "dataclasses1.py"
assert _asserts_without_messages(path) == []


def test_dataclasses2_asserts_have_messages():
path = CHECKS_DIR / "dataclasses2.py"
assert _asserts_without_messages(path) == []


def test_dataclasses_checks_wrap_at_80_chars():
for name in ("dataclasses1.py", "dataclasses2.py"):
path = CHECKS_DIR / name
for lineno, line in enumerate(
path.read_text(encoding="utf-8").splitlines(), start=1
):
assert len(line) <= 80, f"{name}:{lineno} exceeds 80 chars: {line!r}"
Loading