Ejemplo n.º 1
0
async def test_streaming_error(monkeypatch):
    alice, _ = MultiplexerPairFactory()

    msg = "Multiplexing error"
    exc = Exception(msg)

    async def multiplexing():
        alice._started_streaming.set()
        raise exc

    monkeypatch.setattr(alice, '_do_multiplexing', multiplexing)
    await alice.stream_in_background()

    with pytest.raises(Exception, match=msg):
        await alice.wait_streaming_finished()
    assert alice.get_streaming_error() == exc
    with pytest.raises(Exception, match=msg):
        alice.raise_if_streaming_error()
Ejemplo n.º 2
0
async def test_stream_in_background():
    alice, _ = MultiplexerPairFactory()
    assert not alice.is_streaming
    assert not alice.is_closing
    with pytest.raises(Exception):
        await alice.wait_streaming()

    await alice.stream_in_background()

    assert alice.is_streaming

    await alice.stop_streaming()

    assert not alice.is_streaming
    assert alice.is_closing
    assert isinstance(alice.get_streaming_error(), asyncio.CancelledError)

    with pytest.raises(asyncio.CancelledError):
        await alice.wait_streaming_finished()
    with pytest.raises(asyncio.CancelledError):
        alice.raise_if_streaming_error()