File: gen_tests_for_posix_pxds.py

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (41 lines) | stat: -rw-r--r-- 1,006 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
#!/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():
    data = [
        "# 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)

        data.append(s)

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

if __name__ == "__main__":
    main()