Esempio n. 1
0
async def test_queue_calls_attribute_error_for_non_existing_method() -> None:
    class Foo:
        pass

    queue, foo = queue_calls(Foo())
    with pytest.raises(AttributeError):
        await foo.bar()
Esempio n. 2
0
async def test_queue_calls_type_error_for_not_method() -> None:
    class Foo:
        bar = "sss"

    queue, foo = queue_calls(Foo())
    with pytest.raises(TypeError):
        await foo.bar()
Esempio n. 3
0
async def test_queue_calls_saves_args(loop: asyncio.AbstractEventLoop) -> None:
    mock = Mock()

    class Foo:
        def bar(self, *args: Any, **kwargs: Any) -> None:
            mock(*args, **kwargs)

    queue, foo = queue_calls(Foo())
    args = (1, 2, 3)
    kwargs = dict(bar="baz")
    await foo.bar(*args, **kwargs)
    queued_call = await queue.get()
    queued_call()
    mock.assert_called_with(*args, **kwargs)
Esempio n. 4
0
async def test_queue_calls_multiple_calls(
        loop: asyncio.AbstractEventLoop) -> None:
    calls_cnt = 5
    mock = Mock()

    class Foo:
        def bar(self, *args: Any, **kwargs: Any) -> None:
            mock(*args, **kwargs)

    queue, foo = queue_calls(Foo())
    for _ in range(calls_cnt):
        await foo.bar(42)
    while not queue.empty():
        queued_call = await queue.get()
        queued_call()
    mock.assert_has_calls([call(42) for _ in range(calls_cnt)])
Esempio n. 5
0
async def test_queue_calls_no_errors_for_none() -> None:
    queue, foo = queue_calls(None, allow_any_for_none=True)
    await foo.bar()
    await foo.baz()