-
Notifications
You must be signed in to change notification settings - Fork 22
curriculum: consolidate actionable assertion messages #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
179f8b9
curriculum: add actionable assertion messages to datetime checks (bat…
rookepoole 04db8a0
curriculum: add actionable assertion messages to JSON checks (batch 2…
rookepoole d5f9c7f
curriculum: add actionable assertion message to context_managers8 check
rookepoole 11709e1
curriculum: add actionable assertion messages to decorators checks (#89)
rookepoole 5cc70b8
curriculum: add actionable assertion messages to functions checks (ba…
rookepoole cb98da1
curriculum: add actionable assertion messages to recursion checks (ba…
rookepoole e46bebf
curriculum: add actionable assertion messages to recursion checks (ba…
rookepoole 8f30a3b
fix(curriculum): keep assertion messages side-effect free
abhiksark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| assert appointment.isoformat() == "2026-05-23T14:45:00" | ||
| # checks/datetime/datetime7.py | ||
| assert appointment.isoformat() == "2026-05-23T14:45:00", ( | ||
| "appointment should use ISO format '2026-05-23T14:45:00'" | ||
| ) | ||
| print("datetime7 ok") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| # checks/datetime/datetime8.py | ||
| from datetime import date | ||
|
|
||
| assert earliest == date(2024, 1, 1) | ||
| assert latest == date(2026, 5, 23) | ||
| assert earliest == date(2024, 1, 1), f"Expected earliest date to be date(2024, 1, 1), got {earliest!r}" | ||
| assert latest == date(2026, 5, 23), f"Expected latest date to be date(2026, 5, 23), got {latest!r}" | ||
| print("datetime8 ok") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,19 @@ | ||
| assert slow_square(4) == 16 | ||
| assert slow_square(5) == 25 | ||
| # checks/decorators/decorators10.py | ||
| assert slow_square(4) == 16, "slow_square(4) should return 16" | ||
| assert slow_square(5) == 25, "slow_square(5) should return 25" | ||
| # Second calls must hit the cache, not recompute | ||
| assert slow_square(4) == 16 | ||
| assert slow_square(5) == 25 | ||
| assert ( | ||
| slow_square(4) == 16 | ||
| ), "cached slow_square(4) call should return 16" | ||
| assert ( | ||
| slow_square(5) == 25 | ||
| ), "cached slow_square(5) call should return 25" | ||
| assert call_count == 2, ( | ||
| f"slow_square should have been called exactly 2 times (once per unique arg), " | ||
| f"but call_count is {call_count}" | ||
| ) | ||
| assert (4,) in slow_square.cache, "cache should contain key (4,) for arg 4" | ||
| assert slow_square.cache[(4,)] == 16 | ||
| assert ( | ||
| slow_square.cache[(4,)] == 16 | ||
| ), f"slow_square.cache[(4,)] should be 16, got {slow_square.cache[(4,)]}" | ||
| print("decorators10 ✓") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| assert average(2, 4) == 3 | ||
| assert average(10, 20) == 15 | ||
| assert average(-2, -4) == -3 | ||
| assert average(-10, -20) == -15 | ||
| assert average(1.5, 2.5) == 2 | ||
| assert average(0.5, 1.5) == 1 | ||
| assert average(0, 0) == 0 | ||
| assert average(3, 4.5) == 3.75 | ||
| # checks/functions/functions1.py | ||
| assert average(2, 4) == 3, "average(2, 4) should return 3" | ||
| assert average(10, 20) == 15, "average(10, 20) should return 15" | ||
| assert average(-2, -4) == -3, "average(-2, -4) should return -3" | ||
| assert average(-10, -20) == -15, "average(-10, -20) should return -15" | ||
| assert average(1.5, 2.5) == 2, "average(1.5, 2.5) should return 2" | ||
| assert average(0.5, 1.5) == 1, "average(0.5, 1.5) should return 1" | ||
| assert average(0, 0) == 0, "average(0, 0) should return 0" | ||
| assert average(3, 4.5) == 3.75, "average(3, 4.5) should return 3.75" | ||
| print("functions1 ✓") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| # checks/functions/functions2.py | ||
| assert callable(greet), "greet should be a function" | ||
| assert greet() == "hello" | ||
| assert message == "hello" | ||
| assert greet() == "hello", "greet() should return 'hello'" | ||
| assert message == "hello", f"message should be 'hello', got {message!r}" | ||
| print("functions2 ✓") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| # checks/functions/functions3.py | ||
| assert callable(double), "double should be a function" | ||
| assert double(3) == 6 | ||
| assert double(0) == 0 | ||
| assert double(-5) == -10 | ||
| assert double(2.5) == 5.0 | ||
| assert double(3) == 6, "double(3) should return 6" | ||
| assert double(0) == 0, "double(0) should return 0" | ||
| assert double(-5) == -10, "double(-5) should return -10" | ||
| assert double(2.5) == 5.0, "double(2.5) should return 5.0" | ||
| print("functions3 ✓") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| assert settings["theme"] == "dark" | ||
| assert encoded == '{"font_size": 12, "theme": "dark"}' | ||
| # checks/json/json7.py | ||
| assert settings["theme"] == "dark", f"Expected settings['theme'] to be 'dark', got {settings.get('theme')!r}" | ||
| assert encoded == '{"font_size": 12, "theme": "dark"}', f"Expected encoded JSON string '{{\"font_size\": 12, \"theme\": \"dark\"}}', got {encoded!r}" | ||
| print("json7 ok") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| assert decoded == original | ||
| assert tag_count == 2 | ||
| assert level == 3 | ||
| # checks/json/json8.py | ||
| assert decoded == original, f"Expected decoded dict to equal original {original!r}, got {decoded!r}" | ||
| assert tag_count == 2, f"Expected tag_count to be 2, got {tag_count!r}" | ||
| assert level == 3, f"Expected level to be 3, got {level!r}" | ||
| print("json8 ok") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| assert countdown(0) == [0] | ||
| assert countdown(1) == [1, 0] | ||
| assert countdown(3) == [3, 2, 1, 0] | ||
| assert countdown(5) == [5, 4, 3, 2, 1, 0] | ||
| # checks/recursion/recursion1.py | ||
| assert countdown(0) == [0], "countdown(0) should return [0]" | ||
| assert countdown(1) == [1, 0], "countdown(1) should return [1, 0]" | ||
| assert countdown(3) == [3, 2, 1, 0], "countdown(3) should return [3, 2, 1, 0]" | ||
| assert countdown(5) == [5, 4, 3, 2, 1, 0], ( | ||
| "countdown(5) should return [5, 4, 3, 2, 1, 0]" | ||
| ) | ||
| print("recursion1 ✓") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| assert factorial(0) == 1 | ||
| assert factorial(1) == 1 | ||
| assert factorial(5) == 120 | ||
| assert factorial(6) == 720 | ||
| # checks/recursion/recursion2.py | ||
| assert factorial(0) == 1, "factorial(0) should be 1" | ||
| assert factorial(1) == 1, "factorial(1) should be 1" | ||
| assert factorial(5) == 120, "factorial(5) should be 120" | ||
| assert factorial(6) == 720, "factorial(6) should be 720" | ||
| print("recursion2 ✓") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| assert recursive_sum([]) == 0 | ||
| assert recursive_sum([5]) == 5 | ||
| assert recursive_sum([1, 2, 3]) == 6 | ||
| assert recursive_sum([10, 20, 30, 40]) == 100 | ||
| assert recursive_sum([-1, -2, 3]) == 0 | ||
| # checks/recursion/recursion3.py | ||
| assert recursive_sum([]) == 0, "recursive_sum([]) should be 0" | ||
| assert recursive_sum([5]) == 5, "recursive_sum([5]) should be 5" | ||
| assert recursive_sum([1, 2, 3]) == 6, "recursive_sum([1, 2, 3]) should be 6" | ||
| assert recursive_sum([10, 20, 30, 40]) == 100, ( | ||
| "recursive_sum([10, 20, 30, 40]) should be 100" | ||
| ) | ||
| assert recursive_sum([-1, -2, 3]) == 0, "recursive_sum([-1, -2, 3]) should be 0" | ||
| print("recursion3 ✓") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| assert count_items([]) == 0 | ||
| assert count_items([42]) == 1 | ||
| assert count_items([1, 2, 3]) == 3 | ||
| assert count_items(["a", "b", "c", "d"]) == 4 | ||
| assert count_items(list(range(10))) == 10 | ||
| # checks/recursion/recursion4.py | ||
| assert count_items([]) == 0, "count_items([]) should return 0" | ||
| assert count_items([42]) == 1, "count_items([42]) should return 1" | ||
| assert count_items([1, 2, 3]) == 3, "count_items([1, 2, 3]) should return 3" | ||
| assert count_items(["a", "b", "c", "d"]) == 4, ( | ||
| 'count_items(["a", "b", "c", "d"]) should return 4' | ||
| ) | ||
| assert count_items(list(range(10))) == 10, ( | ||
| "count_items(list(range(10))) should return 10" | ||
| ) | ||
| print("recursion4 ✓") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| assert fibonacci(0) == 0 | ||
| assert fibonacci(1) == 1 | ||
| assert fibonacci(2) == 1 | ||
| assert fibonacci(5) == 5 | ||
| assert fibonacci(7) == 13 | ||
| assert fibonacci(10) == 55 | ||
| # checks/recursion/recursion5.py | ||
| assert fibonacci(0) == 0, "fibonacci(0) should return 0" | ||
| assert fibonacci(1) == 1, "fibonacci(1) should return 1" | ||
| assert fibonacci(2) == 1, "fibonacci(2) should return 1" | ||
| assert fibonacci(5) == 5, "fibonacci(5) should return 5" | ||
| assert fibonacci(7) == 13, "fibonacci(7) should return 13" | ||
| assert fibonacci(10) == 55, "fibonacci(10) should return 55" | ||
| print("recursion5 ✓") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please wrap this assertion to keep it within the Google Python style guide 80-character limit. The same issue appears in checks/datetime/datetime8.py lines 4-5, checks/json/json7.py lines 2-3, and checks/json/json8.py line 2. Preserve the predicates and message text.