Skip to content

Commit 234c64a

Browse files
authored
Merge pull request alexmojaki#110 from alexmojaki/assert_equal
changed `assert_equal` to use `repr` in error messages
2 parents 4851235 + 8deb159 commit 234c64a

File tree

3 files changed

+10
-176
lines changed

3 files changed

+10
-176
lines changed

backend/main/chapters/c09_functions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ class introducing_assert_equal(VerbatimStep):
466466
467467
{indent(inspect.getsource(assert_equal), " ")}
468468
469+
(What's that function `repr`? Try `print(f"{{'abc'}} {{repr('abc')}}")` to see one difference, but don't worry about it too much.)
470+
469471
This isn't a standard part of python (although similar functions are), but we've added it to your coding environment
470472
so you can always use it. Here's an example of using it for you to try out:
471473

backend/main/exercises.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,4 @@ def assert_equal(actual, expected):
174174
if actual == expected:
175175
print("OK")
176176
else:
177-
print("Error!", actual, "!=", expected)
177+
print(f"Error! {repr(actual)} != {repr(expected)}")

backend/main/tests/test_transcript.json

Lines changed: 7 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -14087,63 +14087,15 @@
1408714087
"result": [
1408814088
{
1408914089
"color": "white",
14090-
"text": "Error!"
14091-
},
14092-
{
14093-
"color": "white",
14094-
"text": " "
14095-
},
14096-
{
14097-
"color": "white",
14098-
"text": "6"
14099-
},
14100-
{
14101-
"color": "white",
14102-
"text": " "
14103-
},
14104-
{
14105-
"color": "white",
14106-
"text": "!="
14107-
},
14108-
{
14109-
"color": "white",
14110-
"text": " "
14111-
},
14112-
{
14113-
"color": "white",
14114-
"text": "4"
14090+
"text": "Error! 6 != 4"
1411514091
},
1411614092
{
1411714093
"color": "white",
1411814094
"text": "\n"
1411914095
},
1412014096
{
1412114097
"color": "white",
14122-
"text": "Error!"
14123-
},
14124-
{
14125-
"color": "white",
14126-
"text": " "
14127-
},
14128-
{
14129-
"color": "white",
14130-
"text": "15"
14131-
},
14132-
{
14133-
"color": "white",
14134-
"text": " "
14135-
},
14136-
{
14137-
"color": "white",
14138-
"text": "!="
14139-
},
14140-
{
14141-
"color": "white",
14142-
"text": " "
14143-
},
14144-
{
14145-
"color": "white",
14146-
"text": "10"
14098+
"text": "Error! 15 != 10"
1414714099
},
1414814100
{
1414914101
"color": "white",
@@ -14348,31 +14300,7 @@
1434814300
"result": [
1434914301
{
1435014302
"color": "white",
14351-
"text": "Error!"
14352-
},
14353-
{
14354-
"color": "white",
14355-
"text": " "
14356-
},
14357-
{
14358-
"color": "white",
14359-
"text": "2"
14360-
},
14361-
{
14362-
"color": "white",
14363-
"text": " "
14364-
},
14365-
{
14366-
"color": "white",
14367-
"text": "!="
14368-
},
14369-
{
14370-
"color": "white",
14371-
"text": " "
14372-
},
14373-
{
14374-
"color": "white",
14375-
"text": "[2, 4, 6]"
14303+
"text": "Error! 2 != [2, 4, 6]"
1437614304
},
1437714305
{
1437814306
"color": "white",
@@ -14813,63 +14741,15 @@
1481314741
},
1481414742
{
1481514743
"color": "white",
14816-
"text": "Error!"
14817-
},
14818-
{
14819-
"color": "white",
14820-
"text": " "
14821-
},
14822-
{
14823-
"color": "white",
14824-
"text": "Bob"
14825-
},
14826-
{
14827-
"color": "white",
14828-
"text": " "
14829-
},
14830-
{
14831-
"color": "white",
14832-
"text": "!="
14833-
},
14834-
{
14835-
"color": "white",
14836-
"text": " "
14837-
},
14838-
{
14839-
"color": "white",
14840-
"text": "True"
14744+
"text": "Error! 'Bob' != True"
1484114745
},
1484214746
{
1484314747
"color": "white",
1484414748
"text": "\n"
1484514749
},
1484614750
{
1484714751
"color": "white",
14848-
"text": "Error!"
14849-
},
14850-
{
14851-
"color": "white",
14852-
"text": " "
14853-
},
14854-
{
14855-
"color": "white",
14856-
"text": "Bob"
14857-
},
14858-
{
14859-
"color": "white",
14860-
"text": " "
14861-
},
14862-
{
14863-
"color": "white",
14864-
"text": "!="
14865-
},
14866-
{
14867-
"color": "white",
14868-
"text": " "
14869-
},
14870-
{
14871-
"color": "white",
14872-
"text": "False"
14752+
"text": "Error! 'Bob' != False"
1487314753
},
1487414754
{
1487514755
"color": "white",
@@ -14907,63 +14787,15 @@
1490714787
},
1490814788
{
1490914789
"color": "white",
14910-
"text": "Error!"
14911-
},
14912-
{
14913-
"color": "white",
14914-
"text": " "
14915-
},
14916-
{
14917-
"color": "white",
14918-
"text": "Bob"
14919-
},
14920-
{
14921-
"color": "white",
14922-
"text": " "
14923-
},
14924-
{
14925-
"color": "white",
14926-
"text": "!="
14927-
},
14928-
{
14929-
"color": "white",
14930-
"text": " "
14931-
},
14932-
{
14933-
"color": "white",
14934-
"text": "True"
14790+
"text": "Error! 'Bob' != True"
1493514791
},
1493614792
{
1493714793
"color": "white",
1493814794
"text": "\n"
1493914795
},
1494014796
{
1494114797
"color": "white",
14942-
"text": "Error!"
14943-
},
14944-
{
14945-
"color": "white",
14946-
"text": " "
14947-
},
14948-
{
14949-
"color": "white",
14950-
"text": "Bob"
14951-
},
14952-
{
14953-
"color": "white",
14954-
"text": " "
14955-
},
14956-
{
14957-
"color": "white",
14958-
"text": "!="
14959-
},
14960-
{
14961-
"color": "white",
14962-
"text": " "
14963-
},
14964-
{
14965-
"color": "white",
14966-
"text": "False"
14798+
"text": "Error! 'Bob' != False"
1496714799
},
1496814800
{
1496914801
"color": "white",

0 commit comments

Comments
 (0)