Exemplo n.º 1
0
def test_assert_with_proper_callback():
    try:
        raise TypeError
    except TypeError:
        traceback = sys.exc_info()[2]

        try:
            raise_(IOError, None, traceback)
            assert False
        except IOError:
            ctype, cexc1, ctb1 = sys.exc_info()

            assert ctb1 is not traceback
            assert isinstance(cexc1, IOError)
            assert issubclass(ctype, IOError)
            assert isinstance(cexc1.__context__, TypeError)
            assert cexc1.__suppress_context__ == False

            assert get_tb(traceback)[0] == get_tb(ctb1)[-1]

            try:
                raise_(IOError, None, None)
                assert False
            except IOError:
                ctype, cexc2, ctb2 = sys.exc_info()

                assert ctb2 is not ctb1
                assert ctb1 is not traceback
                assert get_tb(traceback)[0] != get_tb(ctb2)[-1]
                assert cexc2.__traceback__ is ctb2
                assert cexc2.__traceback__ is not ctb1
Exemplo n.º 2
0
def test_simple_raise(input_):
    try:
        raise_(IOError)
        assert False
    except IOError:
        ctype, cexc, ctb = sys.exc_info()

        assert isinstance(cexc, IOError)
        assert issubclass(ctype, IOError)
        assert cexc.__context__ is None
        assert cexc.__suppress_context__ == False
        assert cexc.__traceback__ is ctb
Exemplo n.º 3
0
def test_raise_custom():
    class CustomException(Exception):
        def parameter(self):
            return 1

    try:
        raise_(CustomException())
        assert False
    except CustomException:
        type_, value_, tb_ = sys.exc_info()

        assert issubclass(type_, CustomException)
        assert isinstance(value_, CustomException)
        assert value_.parameter() == 1
Exemplo n.º 4
0
def test_raise_from_proxy_exc():
    try:
        raise_(TypeError, "OK")
        assert False
    except TypeError:
        cause, cause_tb = sys.exc_info()[1:]

    try:
        raise_from(IOError, cause)
    except IOError:
        exc, exc_tb = sys.exc_info()[1:]

    assert exc.__suppress_context__
    assert exc.__context__ is None
    assert exc.__cause__ is cause
    assert exc.__traceback__ is exc_tb
    assert exc.__cause__.__traceback__ is cause_tb
Exemplo n.º 5
0
def test_raise_fault():
    with pytest.raises(TypeError):
        raise_(IOError("OK"), "NOK", None)
Exemplo n.º 6
0
def test_repr(input_, expect_):
    try:
        raise_(*input_)
        assert False
    except KeyError as exc:
        assert repr(exc) == expect_