Debian Codegraph @

tests/conftest.py

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