Exemplo n.º 1
0
def test_output_funnel_2nd_plug(funnel: OutputFunnel) -> None:
    with funnel.plugged():
        funnel.write(b"B")
        assert response_texts(funnel) == [["B"]]
        with funnel.plugged():
            funnel.write(b"C")
            assert response_texts(funnel) == [["B"], ["C"]]
        assert response_texts(funnel) == [["B", "C"]]
    assert written(funnel) == b"BC"
Exemplo n.º 2
0
def test_output_funnel_context_nesting(funnel: OutputFunnel) -> None:
    funnel.write(b"A")
    assert written(funnel) == b"A"
    with funnel.plugged():
        funnel.write(b"B")
        assert response_texts(funnel) == [["B"]]
        with funnel.plugged():
            funnel.write(b"C")
            assert response_texts(funnel) == [["B"], ["C"]]
        assert response_texts(funnel) == [["B", "C"]]
    assert written(funnel) == b"ABC"
Exemplo n.º 3
0
def test_output_funnel_drain(funnel: OutputFunnel) -> None:
    with funnel.plugged():
        funnel.write(b"A")
        text = funnel.drain()
        assert text == "A"

        funnel.write(b"B")
        assert response_texts(funnel) == [["B"]]
    assert written(funnel) == b"B"
Exemplo n.º 4
0
def test_output_funnel_context_drain(funnel: OutputFunnel) -> None:
    funnel.write(b"A")
    assert written(funnel) == b"A"
    with funnel.plugged():
        funnel.write(b"B")
        assert response_texts(funnel) == [["B"]]
        code = funnel.drain()
        assert response_texts(funnel) == [[]]
    assert code == "B"
    assert written(funnel) == b"A"
Exemplo n.º 5
0
def test_output_funnel_context_raise(funnel: OutputFunnel) -> None:
    try:
        funnel.write(b"A")
        assert written(funnel) == b"A"
        with funnel.plugged():
            funnel.write(b"B")
            assert response_texts(funnel) == [["B"]]
            raise Exception("Test exception")
    except Exception as e:
        assert "%s" % e == "Test exception"
    finally:
        assert response_texts(funnel) == []
Exemplo n.º 6
0
def test_output_funnel_plugged(funnel: OutputFunnel) -> None:
    with funnel.plugged():
        funnel.write(b"B")
        assert response_texts(funnel) == [["B"]]