Debian Codegraph @

tests/test_impl_selector.py

raw
1 import os
2 import platform
3 import sys
4 from subprocess import check_output
5
6 import pytest
7
8 import caio
9
10
11 @pytest.fixture(params=caio.variants)
12 def implementation(request):
13 if request.param is caio.linux_uring:
14 return "uring"
15 if request.param is caio.linux_aio:
16 return "linux"
17 if request.param is caio.thread_aio:
18 return "thread"
19 if request.param is caio.python_aio:
20 return "python"
21
22 raise RuntimeError(f"Unknown variant {request.param!r}")
23
24
25 @pytest.mark.skipif(platform.system() == 'Windows', reason="Windows skip")
26 def test_env_selector(implementation):
27 output = check_output(
28 [
29 sys.executable,
30 "-c",
31 "import caio, inspect; print(caio.Context.__doc__)"
32 ],
33 env={"CAIO_IMPL": implementation}
34 ).decode()
35
36 assert implementation in output, output
37
38
39 @pytest.fixture()
40 def implementation_file(implementation):
41 path = os.path.dirname(caio.__file__)
42 fname = os.path.join(path, "default_implementation")
43
44 try:
45 with open(fname, "w") as fp:
46 fp.write("# NEWER COMMIT THIS FILE")
47 fp.write("\nwrong string\n")
48 fp.write(implementation)
49 fp.write("\n\n")
50 yield implementation
51 finally:
52 os.remove(fname)
53
54
55 def test_file_selector(implementation_file):
56 output = check_output(
57 [
58 sys.executable,
59 "-c",
60 "import caio, inspect; print(caio.Context.__doc__)"
61 ],
62 ).decode()
63
64 assert implementation_file in output, output