mirror of
https://github.com/soxoj/maigret.git
synced 2026-05-06 14:08:59 +00:00
e8d63ef273
* Bump pytest-asyncio from 0.16.0 to 0.17.0 Bumps [pytest-asyncio](https://github.com/pytest-dev/pytest-asyncio) from 0.16.0 to 0.17.0. - [Release notes](https://github.com/pytest-dev/pytest-asyncio/releases) - [Commits](https://github.com/pytest-dev/pytest-asyncio/compare/v0.16.0...v0.17.0) --- updated-dependencies: - dependency-name: pytest-asyncio dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Python version specified for dependency (3.6 support was dropped) * Pytest config fixes Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Soxoj <soxoj@protonmail.com>
77 lines
2.5 KiB
Python
77 lines
2.5 KiB
Python
"""Maigret checking logic test functions"""
|
|
import pytest
|
|
import asyncio
|
|
import logging
|
|
from maigret.executors import (
|
|
AsyncioSimpleExecutor,
|
|
AsyncioProgressbarExecutor,
|
|
AsyncioProgressbarSemaphoreExecutor,
|
|
AsyncioProgressbarQueueExecutor,
|
|
)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def func(n):
|
|
await asyncio.sleep(0.1 * (n % 3))
|
|
return n
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_simple_asyncio_executor():
|
|
tasks = [(func, [n], {}) for n in range(10)]
|
|
executor = AsyncioSimpleExecutor(logger=logger)
|
|
assert await executor.run(tasks) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
assert executor.execution_time > 0.2
|
|
assert executor.execution_time < 0.3
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_asyncio_progressbar_executor():
|
|
tasks = [(func, [n], {}) for n in range(10)]
|
|
|
|
executor = AsyncioProgressbarExecutor(logger=logger)
|
|
# no guarantees for the results order
|
|
assert sorted(await executor.run(tasks)) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
assert executor.execution_time > 0.2
|
|
assert executor.execution_time < 0.3
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_asyncio_progressbar_semaphore_executor():
|
|
tasks = [(func, [n], {}) for n in range(10)]
|
|
|
|
executor = AsyncioProgressbarSemaphoreExecutor(logger=logger, in_parallel=5)
|
|
# no guarantees for the results order
|
|
assert sorted(await executor.run(tasks)) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
assert executor.execution_time > 0.2
|
|
assert executor.execution_time < 0.4
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_asyncio_progressbar_queue_executor():
|
|
tasks = [(func, [n], {}) for n in range(10)]
|
|
|
|
executor = AsyncioProgressbarQueueExecutor(logger=logger, in_parallel=2)
|
|
assert await executor.run(tasks) == [0, 1, 3, 2, 4, 6, 7, 5, 9, 8]
|
|
assert executor.execution_time > 0.5
|
|
assert executor.execution_time < 0.6
|
|
|
|
executor = AsyncioProgressbarQueueExecutor(logger=logger, in_parallel=3)
|
|
assert await executor.run(tasks) == [0, 3, 1, 4, 6, 2, 7, 9, 5, 8]
|
|
assert executor.execution_time > 0.4
|
|
assert executor.execution_time < 0.5
|
|
|
|
executor = AsyncioProgressbarQueueExecutor(logger=logger, in_parallel=5)
|
|
assert await executor.run(tasks) in (
|
|
[0, 3, 6, 1, 4, 7, 9, 2, 5, 8],
|
|
[0, 3, 6, 1, 4, 9, 7, 2, 5, 8],
|
|
)
|
|
assert executor.execution_time > 0.3
|
|
assert executor.execution_time < 0.4
|
|
|
|
executor = AsyncioProgressbarQueueExecutor(logger=logger, in_parallel=10)
|
|
assert await executor.run(tasks) == [0, 3, 6, 9, 1, 4, 7, 2, 5, 8]
|
|
assert executor.execution_time > 0.2
|
|
assert executor.execution_time < 0.3
|