Skip to content

Commit

Permalink
added test for error_handler
Browse files Browse the repository at this point in the history
  • Loading branch information
semiversus committed Dec 11, 2020
1 parent 9c289fa commit a518d67
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/test_error_handler.py
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):')

0 comments on commit a518d67

Please sign in to comment.