-
Notifications
You must be signed in to change notification settings - Fork 1
/
tasks.py
173 lines (143 loc) · 4.65 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# 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 OpenApiLibCore import openapi_libcore
ROOT = pathlib.Path(__file__).parent.resolve().as_posix()
VERSION = version("robotframework-openapitools")
@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/driver/unittests",
]
subprocess.run(" ".join(cmd), shell=True, check=False)
cmd = [
"coverage",
"run",
"-m",
"unittest",
"discover ",
f"{ROOT}/tests/libcore/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",
"--exclude=roboswag",
f"{ROOT}/tests",
]
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"pylint {ROOT}/src/OpenApiLibCore", shell=True, check=False)
subprocess.run(f"pylint {ROOT}/src/roboswag", shell=True, check=False)
subprocess.run(f"robocop {ROOT}/tests", 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", shell=True, check=False)
@task
def libdoc(context: Context) -> None:
json_file = f"{ROOT}/tests/files/petstore_openapi.json"
source = f"OpenApiLibCore::{json_file}"
target = f"{ROOT}/docs/openapi_libcore.html"
cmd = [
"python",
"-m",
"robot.libdoc",
f"-v {VERSION}",
source,
target,
]
subprocess.run(" ".join(cmd), shell=True, check=False)
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:
json_file = f"{ROOT}/tests/files/petstore_openapi.json"
source = f"OpenApiLibCore::{json_file}"
target = f"{ROOT}/src/OpenApiLibCore/openapi_libcore.libspec"
cmd = [
"python",
"-m",
"robot.libdoc",
f"-v {VERSION}",
source,
target,
]
subprocess.run(" ".join(cmd), shell=True, check=False)
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_file:
# doc_string = openapi_libcore.__doc__
# readme_file.write(front_matter)
# readme_file.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)