コード例 #1
0
def test_allowing_exceptions_that_not_raises():
    with logbook.TestHandler() as handler:
        with slash.allowing_exceptions((Exception, CustomException)):
            pass
    assert len(handler.records) == 1
    assert handler.records[0].message.startswith(
        "Exception/CustomException not raised")
コード例 #2
0
def test_allowing_exceptions(exc_types, message):
    raised = CustomException()
    with slash.Session():
        with slash.allowing_exceptions(exc_types, msg=message) as caught:
            with logbook.TestHandler() as handler:
                raise raised
    assert sys.exc_info() == exception_handling.NO_EXC_INFO
    assert caught.exception is raised
    assert len(handler.records) == 0  # pylint: disable=len-as-condition
コード例 #3
0
def test_handling_exceptions_inside_allowing_exceptions_with_session(
        with_session):
    value = CustomException()

    with ExitStack() as ctx:

        if with_session:
            session = ctx.enter_context(slash.Session())
            ctx.enter_context(session.get_started_context())
        else:
            session = None

        with logbook.TestHandler() as handler:
            with slash.allowing_exceptions(CustomException):
                with exception_handling.handling_exceptions():
                    raise value

    assert not exception_handling.is_exception_handled(value)
    if with_session:
        assert session.results.get_num_errors() == 0
    assert len(handler.records) == 0  # pylint: disable=len-as-condition