예제 #1
0
def test_exception_hook_ignores_contract_from_non_deal(capsys):
    with pytest.raises(deal.ContractError) as exc_info:
        raise deal.ContractError

    # the custom hook does not reduce contract from the traceback
    exception_hook(exc_info.type, exc_info.value, exc_info.tb)
    captured = capsys.readouterr()
    assert captured.out == ''
    assert 'test_exceptions.py' in captured.err
예제 #2
0
def test_exception_hook_ignores_non_contract_exceptions(capsys):
    with pytest.raises(NotImplementedError) as exc_info:
        Base.patched_function(None)

    # the custom hook does not reduce non-contract tracebacks
    exception_hook(exc_info.type, exc_info.value, exc_info.tb)
    captured = capsys.readouterr()
    assert captured.out == ''
    base_path = str(Path('deal', '_decorators', 'base.py'))
    assert base_path in captured.err
예제 #3
0
def test_exception_hook(capsys):
    pre_path = str(Path('deal', '_decorators', 'pre.py'))
    f = deal.pre(lambda x: x > 0)(lambda x: x)
    with pytest.raises(deal.PreContractError) as exc_info:
        f(-2)

    # custom hook is registered
    assert sys.excepthook is exception_hook

    # the default hook shows the full traceback
    _excepthook(exc_info.type, exc_info.value, exc_info.tb)
    captured = capsys.readouterr()
    assert captured.out == ''
    assert pre_path in captured.err

    # the custom hook hides deal from the traceback
    exception_hook(exc_info.type, exc_info.value, exc_info.tb)
    captured = capsys.readouterr()
    assert captured.out == ''
    # the hook doesn't work on python 3.6 and below
    if sys.version_info[:2] >= (3, 7):
        assert pre_path not in captured.err