Debian Codegraph @

tests/conftest.py

raw ◀ ▶
1 Debian patch touch this file
•1 import asyncio
2 from functools import partial
3 from types import ModuleType
4 from typing import List, Union
5
6 import pytest
7 from caio import python_aio_asyncio
8
9 from aiofile import AIOFile, async_open
10
11
12 try:
13 from caio import thread_aio_asyncio
14 except ImportError:
15 thread_aio_asyncio = None # type: ignore
16
17 try:
18 from caio import linux_aio_asyncio
19 except ImportError:
20 linux_aio_asyncio = None # type: ignore
21
22 try:
23 from caio import linux_uring_asyncio
24 except ImportError:
25 linux_uring_asyncio = None # type: ignore
26
27
28 IMPLEMENTATIONS: List[Union[ModuleType, None]] = list(
29 filter(
30 None, [
31 linux_uring_asyncio,
32 linux_aio_asyncio,
33 thread_aio_asyncio,
34 python_aio_asyncio,
35 ],
36 ),
37 )
38
39 IMPLEMENTATIONS.insert(0, None)
40
41 IMPLEMENTATION_NAMES: List[str] = list(
42 map(
43 lambda x: x.__name__ if x is not None else "default",
44 IMPLEMENTATIONS
45 )
46 )
47
48
49 @pytest.fixture(params=IMPLEMENTATIONS, ids=IMPLEMENTATION_NAMES)
•50 async def aio_context(request):
51 if request.param is None:
52 yield None
53 return
54
•55 async with request.param.AsyncioContext(
56 loop=asyncio.get_event_loop()
57 ) as context:
58 yield context
59
60
61 @pytest.fixture
62 def aio_file_maker(aio_context):
63 return partial(AIOFile, context=aio_context)
64
65
66 @pytest.fixture(name="async_open")
67 def async_open_maker(aio_context):
68 return partial(async_open, context=aio_context)