Skip to content

Commit 281d310

Browse files
committed
Make tests write to result.json and expected.json when result is not expected, and throw a small user error
1 parent 4a5648f commit 281d310

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

Python/tests.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,13 @@ def read_test(filepath):
2121
return filepath.read_text()
2222

2323

24-
def test(input_str, result, expected):
25-
function_name = sys._getframe(1).f_code.co_name
26-
error_message = (
27-
"A test error occurred, report it to MyNameIsTrez#1585!"
28-
f"\n\nTest function name: {function_name}"
29-
f"\n\nInput:\n{repr(input_str)}"
30-
f"\n\nExpected:\n{str(expected)}"
31-
f"\n\nResult:\n{str(result)}"
32-
)
33-
34-
# print(result)
35-
36-
# TODO: Comment these out before releasing this!
37-
# import json
38-
# with open("result.json", "w") as f:
39-
# f.write(json.dumps(result))
40-
# with open("expected.json", "w") as f:
41-
# f.write(json.dumps(expected))
42-
43-
# TODO: Make the error_message not show twice in the popup.
44-
assert result == expected, error_message
24+
def test(test_name, result, expected):
25+
if result != expected:
26+
# TODO: Comment these out before releasing this!
27+
import json
28+
with open("result.json", "w") as f:
29+
f.write(json.dumps(result, indent=4))
30+
with open("expected.json", "w") as f:
31+
f.write(json.dumps(expected, indent=4))
32+
33+
raise ValueError(f"The test '{test_name}' failed, report it to MyNameIsTrez#1585!")

0 commit comments

Comments
 (0)