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
10 changes: 5 additions & 5 deletions checks/generators/generators9.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
assert list(Counter(4)) == [0, 1, 2, 3]
assert list(Counter(1)) == [0]
assert list(Counter(0)) == []
assert list(Counter(4)) == [0, 1, 2, 3], "Counter(4) should yield 0, 1, 2, 3"
assert list(Counter(1)) == [0], "Counter(1) should yield only 0"
assert list(Counter(0)) == [], "Counter(0) should yield nothing"
# StopIteration must be raised at the right moment.
c = Counter(2)
assert next(c) == 0
assert next(c) == 1
assert next(c) == 0, "first next() should return 0"
assert next(c) == 1, "second next() should return 1"
try:
next(c)
raise AssertionError("expected StopIteration after stop elements")
Expand Down
22 changes: 22 additions & 0 deletions tests/test_generators_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import ast
from pathlib import Path


CHECK_FILE = Path(__file__).resolve().parents[1] / "checks" / "generators" / "generators9.py"


def test_generators9_assertions_have_messages():
source = CHECK_FILE.read_text(encoding="utf-8")
tree = ast.parse(source)
asserts = [node for node in ast.walk(tree) if isinstance(node, ast.Assert)]
assert asserts, "expected assertions in generators9 check"
for node in asserts:
assert node.msg is not None, (
f"assertion on line {node.lineno} is missing an actionable message"
)


def test_generators9_lines_within_limit():
source = CHECK_FILE.read_text(encoding="utf-8")
for lineno, line in enumerate(source.splitlines(), start=1):
assert len(line) <= 80, f"line {lineno} exceeds 80 characters: {line!r}"
Loading