This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
tasks.py
134 lines (109 loc) · 3.7 KB
/
tasks.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# pylint: disable=missing-function-docstring, unused-argument
import pathlib
import subprocess
from importlib.metadata import version
from invoke.context import Context
from invoke.tasks import task
from OpenApiDriver import openapidriver
ROOT = pathlib.Path(__file__).parent.resolve().as_posix()
VERSION = version("robotframework-openapidriver")
@task
def start_api(context: Context) -> None:
cmd = [
"python",
"-m",
"uvicorn",
"testserver:app",
f"--app-dir {ROOT}/tests/server",
"--host 0.0.0.0",
"--port 8000",
"--reload",
f"--reload-dir {ROOT}/tests/server",
]
subprocess.run(" ".join(cmd), shell=True, check=False)
@task
def utests(context: Context) -> None:
cmd = [
"coverage",
"run",
"-m",
"unittest",
"discover ",
f"{ROOT}/tests/unittests",
]
subprocess.run(" ".join(cmd), shell=True, check=False)
@task
def atests(context: Context) -> None:
cmd = [
"coverage",
"run",
"-m",
"robot",
f"--argumentfile={ROOT}/tests/rf_cli.args",
f"--variable=root:{ROOT}",
f"--outputdir={ROOT}/tests/logs",
"--loglevel=TRACE:DEBUG",
f"{ROOT}/tests/suites/",
]
subprocess.run(" ".join(cmd), shell=True, check=False)
@task(utests, atests)
def tests(context: Context) -> None:
subprocess.run("coverage combine", shell=True, check=False)
subprocess.run("coverage report", shell=True, check=False)
subprocess.run("coverage html", shell=True, check=False)
@task
def type_check(context: Context) -> None:
subprocess.run(f"mypy {ROOT}/src", shell=True, check=False)
subprocess.run(f"pyright {ROOT}/src", shell=True, check=False)
@task
def lint(context: Context) -> None:
subprocess.run(f"ruff {ROOT}", shell=True, check=False)
subprocess.run(f"pylint {ROOT}/src/OpenApiDriver", shell=True, check=False)
subprocess.run(f"robocop {ROOT}/tests/suites", shell=True, check=False)
@task
def format_code(context: Context) -> None:
subprocess.run(f"black {ROOT}", shell=True, check=False)
subprocess.run(f"isort {ROOT}", shell=True, check=False)
subprocess.run(f"robotidy {ROOT}/tests/suites", shell=True, check=False)
@task
def libdoc(context: Context) -> None:
print(f"Generating libdoc for library version {VERSION}")
json_file = f"{ROOT}/tests/files/petstore_openapi.json"
source = f"OpenApiDriver.openapidriver.DocumentationGenerator::{json_file}"
target = f"{ROOT}/docs/openapidriver.html"
cmd = [
"python",
"-m",
"robot.libdoc",
"-n OpenApiDriver",
f"-v {VERSION}",
source,
target,
]
subprocess.run(" ".join(cmd), shell=True, check=False)
@task
def libspec(context: Context) -> None:
print(f"Generating libspec for library version {VERSION}")
json_file = f"{ROOT}/tests/files/petstore_openapi.json"
source = f"OpenApiDriver.openapidriver.DocumentationGenerator::{json_file}"
target = f"{ROOT}/src/OpenApiDriver/openapidriver.libspec"
cmd = [
"python",
"-m",
"robot.libdoc",
"-n OpenApiDriver",
f"-v {VERSION}",
source,
target,
]
subprocess.run(" ".join(cmd), shell=True, check=False)
@task
def readme(context: Context) -> None:
front_matter = """---\n---\n"""
with open(f"{ROOT}/docs/README.md", "w", encoding="utf-8") as readme:
doc_string = openapidriver.__doc__
readme.write(front_matter)
readme.write(str(doc_string).replace("\\", "\\\\").replace("\\\\*", "\\*"))
@task(format_code, libdoc, libspec, readme)
def build(context: Context) -> None:
subprocess.run("poetry build", shell=True, check=False)