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"
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"
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"
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"
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) == []
def test_output_funnel_plugged(funnel: OutputFunnel) -> None: with funnel.plugged(): funnel.write(b"B") assert response_texts(funnel) == [["B"]]