Skip to content

Commit 2d1cf4a

Browse files
Blind4Basicskazk
andauthored
Improve expect_error feedback (#16)
Co-authored-by: kazk <kazk.dev@gmail.com>
1 parent a07c83f commit 2d1cf4a

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

codewars_test/test_framework.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def expect_error(message, function, exception=Exception):
5151
function()
5252
except exception:
5353
passed = True
54-
except Exception:
55-
pass
54+
except Exception as e:
55+
message = "{}: {} should be {}".format(message or "Unexpected exception", repr(e), repr(exception))
5656
expect(passed, message)
5757

5858

@@ -62,7 +62,7 @@ def expect_no_error(message, function, exception=BaseException):
6262
except exception as e:
6363
fail("{}: {}".format(message or "Unexpected exception", repr(e)))
6464
return
65-
except Exception:
65+
except:
6666
pass
6767
pass_()
6868

tests/fixtures/expect_error_sample.expected.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525

2626
<PASSED::>Test Passed
2727

28-
<FAILED::>f1 did not raise ArithmeticError
28+
<FAILED::>f1 did not raise ArithmeticError: Exception() should be <class 'ArithmeticError'>
2929

30-
<FAILED::>f1 did not raise ZeroDivisionError
30+
<FAILED::>f1 did not raise ZeroDivisionError: Exception() should be <class 'ZeroDivisionError'>
3131

32-
<FAILED::>f1 did not raise LookupError
32+
<FAILED::>f1 did not raise LookupError: Exception() should be <class 'LookupError'>
3333

34-
<FAILED::>f1 did not raise KeyError
34+
<FAILED::>f1 did not raise KeyError: Exception() should be <class 'KeyError'>
3535

36-
<FAILED::>f1 did not raise OSError
36+
<FAILED::>f1 did not raise OSError: Exception() should be <class 'OSError'>
3737

3838
<COMPLETEDIN::>0.02
3939

@@ -47,11 +47,11 @@
4747

4848
<PASSED::>Test Passed
4949

50-
<FAILED::>f2 did not raise LookupError
50+
<FAILED::>f2 did not raise LookupError: ZeroDivisionError('integer division or modulo by zero') should be <class 'LookupError'>
5151

52-
<FAILED::>f2 did not raise KeyError
52+
<FAILED::>f2 did not raise KeyError: ZeroDivisionError('integer division or modulo by zero') should be <class 'KeyError'>
5353

54-
<FAILED::>f2 did not raise OSError
54+
<FAILED::>f2 did not raise OSError: ZeroDivisionError('integer division or modulo by zero') should be <class 'OSError'>
5555

5656
<COMPLETEDIN::>0.02
5757

@@ -61,16 +61,16 @@
6161

6262
<PASSED::>Test Passed
6363

64-
<FAILED::>f3 did not raise ArithmeticError
64+
<FAILED::>f3 did not raise ArithmeticError: KeyError(1) should be <class 'ArithmeticError'>
6565

66-
<FAILED::>f3 did not raise ZeroDivisionError
66+
<FAILED::>f3 did not raise ZeroDivisionError: KeyError(1) should be <class 'ZeroDivisionError'>
6767

6868
<PASSED::>Test Passed
6969

7070
<PASSED::>Test Passed
7171

72-
<FAILED::>f3 did not raise OSError
72+
<FAILED::>f3 did not raise OSError: KeyError(1) should be <class 'OSError'>
7373

7474
<COMPLETEDIN::>0.02
7575

76-
<COMPLETEDIN::>0.11
76+
<COMPLETEDIN::>0.11

tests/test_outputs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ def test(self):
2020
)
2121
with open(expected_file, "r", encoding="utf-8") as r:
2222
# Allow duration to change
23+
expected = re.sub(r"([()])", r"\\\1", r.read())
2324
expected = re.sub(
24-
r"(?<=<COMPLETEDIN::>)\d+(?:\.\d+)?", r"\\d+(?:\\.\\d+)?", r.read()
25+
r"(?<=<COMPLETEDIN::>)\d+(?:\.\d+)?", r"\\d+(?:\\.\\d+)?", expected
2526
)
27+
2628
self.assertRegex(result.stdout.decode("utf-8"), expected)
2729

2830
return test

0 commit comments

Comments
 (0)