Exemplo n.º 1
0
def test_caller_extra():
    m = MiddlewareManager()

    rn = m.get('return_n', return_n)

    assert run(rn(0)) == 0

    with pytest.raises(ValueError):
        run(rn(0))
Exemplo n.º 2
0
def test_build_stack():
    m = MiddlewareManager()
    m.middlewares = [
        AddOne,
        DoNothing,
    ]
    rn = m.get('return_n', return_n)

    # noinspection PyProtectedMember,PyUnresolvedReferences
    assert len(rn._stack) == 1
Exemplo n.º 3
0
def test_caller_stack():
    m = MiddlewareManager()
    m.middlewares = [
        AddOne,
        AddOne,
    ]

    rn = m.get('return_n', return_n)

    assert run(rn(40)) == 42
Exemplo n.º 4
0
def test_next_not_called():
    m = MiddlewareManager()
    m.middlewares = [BadPlayer]

    rn = m.get('return_n', return_n)

    error_msg = '"BadPlayer.return_n" did not call `self.next()`, or forgot ' \
                'to await it'

    with pytest.raises(TypeError) as exec_info:
        run(rn(0))

    assert str(exec_info.value) == error_msg