From fbfcd4fb0ed03dafc1dfe51264807f1b7982c2e0 Mon Sep 17 00:00:00 2001 From: mercael Date: Fri, 2 Oct 2026 00:36:03 +0300 Subject: [PATCH 1/5] Add actionable assertion messages to generators checks and regression test Signed-off-by: mercael --- checks/generators/generators1.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/checks/generators/generators1.py b/checks/generators/generators1.py index 4f3822e..b2153c0 100644 --- a/checks/generators/generators1.py +++ b/checks/generators/generators1.py @@ -1,4 +1,4 @@ -assert list(count_up_to(4)) == [1, 2, 3, 4] -assert list(count_up_to(1)) == [1] -assert list(count_up_to(0)) == [] +assert list(count_up_to(4)) == [1, 2, 3, 4], f"expected [1, 2, 3, 4], got {list(count_up_to(4))}" +assert list(count_up_to(1)) == [1], f"expected [1], got {list(count_up_to(1))}" +assert list(count_up_to(0)) == [], f"expected [], got {list(count_up_to(0))}" print("generators1 ✓") From 7d98e24a9bf678ab15dee8ad3606163dc2c0f1d9 Mon Sep 17 00:00:00 2001 From: mercael Date: Fri, 2 Oct 2026 00:36:05 +0300 Subject: [PATCH 2/5] Add actionable assertion messages to generators checks and regression test Signed-off-by: mercael --- checks/generators/generators3.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/checks/generators/generators3.py b/checks/generators/generators3.py index 8dc4615..1f8477c 100644 --- a/checks/generators/generators3.py +++ b/checks/generators/generators3.py @@ -1,4 +1,4 @@ assert collected == [2, 4, 6, 8], f"expected [2, 4, 6, 8], got {collected}" -assert list(evens_up_to(5)) == [2, 4] -assert list(evens_up_to(1)) == [] +assert list(evens_up_to(5)) == [2, 4], f"expected [2, 4], got {list(evens_up_to(5))}" +assert list(evens_up_to(1)) == [], f"expected [], got {list(evens_up_to(1))}" print("generators3 ✓") From cb8d9931cca168fba0924266502cd6bf77b3c8e0 Mon Sep 17 00:00:00 2001 From: mercael Date: Fri, 2 Oct 2026 00:36:06 +0300 Subject: [PATCH 3/5] Add actionable assertion messages to generators checks and regression test Signed-off-by: mercael --- checks/generators/generators6.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/checks/generators/generators6.py b/checks/generators/generators6.py index 8aabc65..58965f5 100644 --- a/checks/generators/generators6.py +++ b/checks/generators/generators6.py @@ -3,6 +3,6 @@ ) # Confirm the generator really is infinite: pull 1000 values. big = list(itertools.islice(natural_numbers(), 1000)) -assert len(big) == 1000 -assert big[-1] == 1000 +assert len(big) == 1000, f"expected 1000 values, got {len(big)}" +assert big[-1] == 1000, f"expected last value 1000, got {big[-1]}" print("generators6 ✓") From c49e256f2689642a76657199374b0d81b1e3ef21 Mon Sep 17 00:00:00 2001 From: mercael Date: Fri, 2 Oct 2026 00:36:08 +0300 Subject: [PATCH 4/5] Add actionable assertion messages to generators checks and regression test Signed-off-by: mercael --- tests/test_generators_assertion_messages.py | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/test_generators_assertion_messages.py diff --git a/tests/test_generators_assertion_messages.py b/tests/test_generators_assertion_messages.py new file mode 100644 index 0000000..6b5554f --- /dev/null +++ b/tests/test_generators_assertion_messages.py @@ -0,0 +1,24 @@ +import ast +import pathlib + + +CHECKS = [ + "checks/generators/generators1.py", + "checks/generators/generators3.py", + "checks/generators/generators6.py", +] + + +def _asserts_without_message(path): + tree = ast.parse(pathlib.Path(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_generators_checks_have_actionable_assertion_messages(): + for path in CHECKS: + missing = _asserts_without_message(path) + assert missing == [], f"{path} has asserts without messages at lines {missing}" From 68ed93b6f2e46a2488f5d3e63476a3f89215af6f Mon Sep 17 00:00:00 2001 From: mercael91 Date: Fri, 2 Oct 2026 05:44:00 +0000 Subject: [PATCH 5/5] Add assertion messages to generators7/8 checks (complete #90 batch) --- checks/generators/generators7.py | 6 +++--- checks/generators/generators8.py | 12 ++++++------ tests/test_generators_assertion_messages.py | 2 ++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/checks/generators/generators7.py b/checks/generators/generators7.py index a043998..88341e0 100644 --- a/checks/generators/generators7.py +++ b/checks/generators/generators7.py @@ -6,6 +6,6 @@ ) # Confirm more terms keep coming. first15 = list(itertools.islice(fibonacci(), 15)) -assert len(first15) == 15 -assert first15[-1] == 377 -print("generators7 ✓") +assert len(first15) == 15, f"expected 15 terms in the sequence, got {len(first15)}" +assert first15[-1] == 377, f"expected the 15th term to be 377, got {first15[-1]}" +print("generators7 \u2713") diff --git a/checks/generators/generators8.py b/checks/generators/generators8.py index d1e027d..854780f 100644 --- a/checks/generators/generators8.py +++ b/checks/generators/generators8.py @@ -1,8 +1,8 @@ -assert list(Countdown(3)) == [3, 2, 1] -assert list(Countdown(1)) == [1] -assert list(Countdown(5)) == [5, 4, 3, 2, 1] +assert list(Countdown(3)) == [3, 2, 1], f"expected [3, 2, 1], got {list(Countdown(3))}" +assert list(Countdown(1)) == [1], f"expected [1], got {list(Countdown(1))}" +assert list(Countdown(5)) == [5, 4, 3, 2, 1], f"expected [5, 4, 3, 2, 1], got {list(Countdown(5))}" # Should be re-iterable: a fresh iteration each time. cd = Countdown(3) -assert list(cd) == [3, 2, 1] -assert list(cd) == [3, 2, 1] -print("generators8 ✓") +assert list(cd) == [3, 2, 1], f"expected a fresh iteration [3, 2, 1], got {list(cd)}" +assert list(cd) == [3, 2, 1], f"expected the second iteration to replay [3, 2, 1], got {list(cd)}" +print("generators8 \u2713") diff --git a/tests/test_generators_assertion_messages.py b/tests/test_generators_assertion_messages.py index 6b5554f..ad3d590 100644 --- a/tests/test_generators_assertion_messages.py +++ b/tests/test_generators_assertion_messages.py @@ -6,6 +6,8 @@ "checks/generators/generators1.py", "checks/generators/generators3.py", "checks/generators/generators6.py", + "checks/generators/generators7.py", + "checks/generators/generators8.py", ]