summaryrefslogtreecommitdiff
path: root/Tools/gen_tests_for_posix_pxds.py
blob: c92c49a6a182a0cf0a31c12f8fbdecf115e78bc6 (plain)
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
#!/usr/bin/python3

from pathlib import Path

PROJECT_ROOT = Path(__file__) / "../.."
POSIX_PXDS_DIR = PROJECT_ROOT / "Cython/Includes/posix"
TEST_PATH = PROJECT_ROOT / "tests/compile/posix_pxds.pyx"

def main():
    datas = [
        "# tag: posix\n"
        "# mode: compile\n"
        "\n"
        "# This file is generated by `Tools/gen_tests_for_posix_pxds.py`.\n"
        "\n"
        "cimport posix\n"
    ]

    filenames = sorted(map(lambda path: path.name, POSIX_PXDS_DIR.iterdir()))

    for name in filenames:
        if name == "__init__.pxd":
            continue
        if name.endswith(".pxd"):
            name = name[:-4]
        else:
            continue

        s = (
            "cimport posix.{name}\n"
            "from posix cimport {name}\n"
            "from posix.{name} cimport *\n"
        ).format(name=name)

        datas.append(s)

    with open(TEST_PATH, "w", encoding="utf-8", newline="\n") as f:
        f.write("\n".join(datas))

if __name__ == "__main__":
    main()