-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c289fa
commit a518d67
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import sys | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
|
||
from broqer.error_handler import default_error_handler | ||
|
||
|
||
def test_default(capsys): | ||
try: | ||
0/0 | ||
except: | ||
exc = sys.exc_info() | ||
|
||
default_error_handler(*exc) | ||
|
||
captured = capsys.readouterr() | ||
|
||
assert captured.err.startswith('Traceback (most recent call last):') | ||
assert 'ZeroDivisionError: division by zero' in captured.err | ||
assert __file__ in captured.err | ||
|
||
assert captured.out == '' | ||
|
||
|
||
def test_set_errorhandler(capsys): | ||
mock = Mock() | ||
default_error_handler.set(mock) | ||
|
||
try: | ||
0/0 | ||
except: | ||
exc = sys.exc_info() | ||
|
||
default_error_handler(*exc) | ||
|
||
mock.assert_called_once_with(*exc) | ||
|
||
captured = capsys.readouterr() | ||
|
||
assert captured.err == '' | ||
assert captured.out == '' | ||
|
||
# reset | ||
default_error_handler.reset() | ||
|
||
default_error_handler(*exc) | ||
|
||
captured = capsys.readouterr() | ||
assert captured.err.startswith('Traceback (most recent call last):') |