Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Improve expect_error feedback #16

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 10 commits into from
May 17, 2021
6 changes: 3 additions & 3 deletions codewars_test/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def expect_error(message, function, exception=Exception):
function()
except exception:
passed = True
except Exception:
pass
except Exception as e:
message = "{}: {} should be {}".format(message or "Unexpected exception", repr(e), repr(exception))
expect(passed, message)


Expand All @@ -62,7 +62,7 @@ def expect_no_error(message, function, exception=BaseException):
except exception as e:
fail("{}: {}".format(message or "Unexpected exception", repr(e)))
return
except Exception:
except:
pass
pass_()

Expand Down
24 changes: 12 additions & 12 deletions tests/fixtures/expect_error_sample.expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

<PASSED::>Test Passed

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

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

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

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

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

<COMPLETEDIN::>0.02

Expand All @@ -47,11 +47,11 @@

<PASSED::>Test Passed

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

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

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

<COMPLETEDIN::>0.02

Expand All @@ -61,16 +61,16 @@

<PASSED::>Test Passed

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

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

<PASSED::>Test Passed

<PASSED::>Test Passed

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

<COMPLETEDIN::>0.02

<COMPLETEDIN::>0.11
<COMPLETEDIN::>0.11
4 changes: 3 additions & 1 deletion tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ def test(self):
)
with open(expected_file, "r", encoding="utf-8") as r:
# Allow duration to change
expected = re.sub(r"([()])", r"\\\1", r.read())
expected = re.sub(
r"(?<=<COMPLETEDIN::>)\d+(?:\.\d+)?", r"\\d+(?:\\.\\d+)?", r.read()
r"(?<=<COMPLETEDIN::>)\d+(?:\.\d+)?", r"\\d+(?:\\.\\d+)?", expected
)

self.assertRegex(result.stdout.decode("utf-8"), expected)

return test
Expand Down