Skip to content
Closed
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
4 changes: 3 additions & 1 deletion checks/decorators/decorators2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
assert loud_greet() == "HELLO", (
f"loud_greet() should return 'HELLO', got {loud_greet()!r}"
)
assert shout(lambda: "world")() == "WORLD"
assert shout(lambda: "world")() == "WORLD", (
f"shout(lambda: 'world')() should return 'WORLD', got {shout(lambda: 'world')()!r}"
)
print("decorators2 ✓")
10 changes: 7 additions & 3 deletions checks/decorators/decorators5.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
assert add(3, 4) == 7, f"add(3, 4) should return 7, got {add(3, 4)!r}"
assert add(10, -2) == 8
assert greet("Alice") == "Hello, Alice!"
assert greet("Bob", greeting="Hi") == "Hi, Bob!"
assert add(10, -2) == 8, f"add(10, -2) should return 8, got {add(10, -2)!r}"
assert greet("Alice") == "Hello, Alice!", (
f"greet('Alice') should return 'Hello, Alice!', got {greet('Alice')!r}"
)
assert greet("Bob", greeting="Hi") == "Hi, Bob!", (
f"greet('Bob', greeting='Hi') should return 'Hi, Bob!', got {greet('Bob', greeting='Hi')!r}"
)
print("decorators5 ✓")
22 changes: 22 additions & 0 deletions tests/test_decorators_assertion_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import ast
from pathlib import Path


CHECKS = Path(__file__).resolve().parent.parent / "checks" / "decorators"


def _asserts_without_msg(path):
tree = ast.parse(path.read_text())
missing = []
for node in ast.walk(tree):
if isinstance(node, ast.Assert) and node.msg is None:
missing.append(node.lineno)
return missing


def test_decorators2_asserts_have_messages():
assert _asserts_without_msg(CHECKS / "decorators2.py") == []


def test_decorators5_asserts_have_messages():
assert _asserts_without_msg(CHECKS / "decorators5.py") == []
Loading