File: test_impl_selector.py

package info (click to toggle)
caio 0.9.24-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 288 kB
  • sloc: ansic: 1,645; python: 632; makefile: 5
file content (61 lines) | stat: -rw-r--r-- 1,503 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import platform
import sys
from subprocess import check_output

import caio
import pytest


@pytest.fixture(params=caio.variants)
def implementation(request):
    if request.param is caio.linux_aio:
        return "linux"
    if request.param is caio.thread_aio:
        return "thread"
    if request.param is caio.python_aio:
        return "python"

    raise RuntimeError("Unknown variant %r" % (request.param,))


@pytest.mark.skipif(platform.system() == 'Windows', reason="Windows skip")
def test_env_selector(implementation):
    output = check_output(
        [
            sys.executable,
            "-c",
            "import caio, inspect; print(caio.Context.__doc__)"
        ],
        env={"CAIO_IMPL": implementation}
    ).decode()

    assert implementation in output, output


@pytest.fixture()
def implementation_file(implementation):
    path = os.path.dirname(caio.__file__)
    fname = os.path.join(path, "default_implementation")

    try:
        with open(fname, "w") as fp:
            fp.write("# NEWER COMMIT THIS FILE")
            fp.write("\nwrong string\n")
            fp.write(implementation)
            fp.write("\n\n")
        yield implementation
    finally:
        os.remove(fname)


def test_file_selector(implementation_file):
    output = check_output(
        [
            sys.executable,
            "-c",
            "import caio, inspect; print(caio.Context.__doc__)"
        ],
    ).decode()

    assert implementation_file in output, output