asynctest.mock.PropertyMock

Here are the examples of the python api asynctest.mock.PropertyMock taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

0 Source : test_player_network_interface.py
with MIT License
from hsahovic

async def test_listen():
    player = PlayerNetworkChild(
        player_configuration=player_configuration,
        avatar=12,
        server_configuration=server_configuration,
        start_listening=False,
    )

    type(player).websocket_url = PropertyMock(return_value="ws://localhost:8899")

    player._handle_message = CoroutineMock()
    semaphore = asyncio.Semaphore()

    async def showdown_server_mock(websocket, path):
        semaphore.release()
        await websocket.ping()
        await websocket.send("error|test 1")
        await websocket.send("error|test 2")
        await websocket.send("error|test 3")

    await semaphore.acquire()

    gathered = asyncio.gather(websockets.serve(showdown_server_mock, "0.0.0.0", 8899))

    await player.listen()

    await gathered
    assert player._handle_message.await_count == 3
    player._handle_message.assert_awaited_with("error|test 3")


@pytest.mark.asyncio