-
-
Notifications
You must be signed in to change notification settings - Fork 627
Expand file tree
/
Copy pathnoxfile.py
More file actions
235 lines (202 loc) · 5.99 KB
/
noxfile.py
File metadata and controls
235 lines (202 loc) · 5.99 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import itertools
from collections.abc import Callable
from typing import Any
import nox
nox.options.reuse_existing_virtualenvs = True
nox.options.error_on_external_run = True
nox.options.default_venv_backend = "uv"
PYTHON_VERSIONS = ["3.14", "3.13", "3.12", "3.11", "3.10"]
GQL_CORE_VERSIONS = [
"3.2.6",
"3.3.0a12",
]
COMMON_PYTEST_OPTIONS = [
"--cov=.",
"--cov-append",
"-n",
"auto",
"--showlocals",
"-vv",
"--ignore=tests/typecheckers",
"--ignore=tests/cli",
"--ignore=tests/benchmarks",
"--ignore=tests/experimental/pydantic",
]
INTEGRATIONS = [
"asgi",
"aiohttp",
"chalice",
"channels",
"django",
"fastapi",
"flask",
"quart",
"sanic",
"litestar",
"pydantic",
]
def _install_gql_core(session: nox.Session, version: str) -> None:
session.install(f"graphql-core=={version}")
gql_core_parametrize = nox.parametrize(
"gql_core",
GQL_CORE_VERSIONS,
)
def with_gql_core_parametrize(name: str, params: list[str]) -> Callable[[Any], Any]:
# github cache doesn't support comma in the name, this is a workaround.
arg_names = f"{name}, gql_core"
combinations = list(itertools.product(params, GQL_CORE_VERSIONS))
ids = [f"{name}-{comb[0]}__graphql-core-{comb[1]}" for comb in combinations]
return nox.parametrize(arg_names, combinations, ids=ids)
@nox.session(python=PYTHON_VERSIONS, name="Tests", tags=["tests"])
@gql_core_parametrize
def tests(session: nox.Session, gql_core: str) -> None:
session.run_install(
"uv",
"sync",
"--no-group=integrations",
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
)
_install_gql_core(session, gql_core)
markers = (
["-m", f"not {integration}", f"--ignore=tests/{integration}"]
for integration in INTEGRATIONS
)
markers = [item for sublist in markers for item in sublist]
session.run(
"pytest",
*COMMON_PYTEST_OPTIONS,
*markers,
)
@nox.session(python=["3.12"], name="Django tests", tags=["tests"])
@with_gql_core_parametrize("django", ["5.1.3", "5.0.9", "4.2.0"])
def tests_django(session: nox.Session, django: str, gql_core: str) -> None:
session.run_install(
"uv",
"sync",
"--no-group=integrations",
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
)
_install_gql_core(session, gql_core)
session.install(f"django~={django}")
session.install("pytest-django")
session.run("pytest", *COMMON_PYTEST_OPTIONS, "-m", "django")
@nox.session(python=["3.11"], name="Starlette tests", tags=["tests"])
@gql_core_parametrize
def tests_starlette(session: nox.Session, gql_core: str) -> None:
session.run_install(
"uv",
"sync",
"--no-group=integrations",
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
)
session.install("starlette")
_install_gql_core(session, gql_core)
session.run("pytest", *COMMON_PYTEST_OPTIONS, "-m", "asgi")
@nox.session(python=["3.11"], name="Test integrations", tags=["tests"])
@with_gql_core_parametrize(
"integration",
[
"aiohttp",
"chalice",
"channels",
"fastapi",
"flask",
"quart",
"sanic",
"litestar",
],
)
def tests_integrations(session: nox.Session, integration: str, gql_core: str) -> None:
session.run_install(
"uv",
"sync",
"--no-group=integrations",
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
)
session.install(integration)
_install_gql_core(session, gql_core)
if integration == "aiohttp":
session.install("pytest-aiohttp")
elif integration == "channels":
session.install("pytest-django")
session.install("daphne")
session.run("pytest", *COMMON_PYTEST_OPTIONS, "-m", integration)
@nox.session(
python=["3.10", "3.11", "3.12", "3.13"],
name="Pydantic V1 tests",
tags=["tests", "pydantic"],
)
@gql_core_parametrize
def test_pydantic(session: nox.Session, gql_core: str) -> None:
session.run_install(
"uv",
"sync",
"--no-group=integrations",
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
)
session.install("pydantic~=1.10")
_install_gql_core(session, gql_core)
session.run(
"pytest",
"--cov=.",
"--cov-append",
"-m",
"pydantic",
"--ignore=tests/cli",
"--ignore=tests/benchmarks",
)
@nox.session(python=PYTHON_VERSIONS, name="Pydantic tests", tags=["tests", "pydantic"])
@gql_core_parametrize
def test_pydantic_v2(session: nox.Session, gql_core: str) -> None:
session.run_install(
"uv",
"sync",
"--no-group=integrations",
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
)
session.install("pydantic>=2.2")
_install_gql_core(session, gql_core)
session.run(
"pytest",
"--cov=.",
"--cov-append",
"-m",
"pydantic",
"--ignore=tests/cli",
"--ignore=tests/benchmarks",
)
@nox.session(python=PYTHON_VERSIONS, name="Type checkers tests", tags=["tests"])
def tests_typecheckers(session: nox.Session) -> None:
session.run_install(
"uv",
"sync",
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
)
session.install("pyright")
session.install("pydantic")
session.install("mypy")
session.install("ty")
session.run(
"pytest",
"--cov=.",
"--cov-append",
"tests/typecheckers",
"-vv",
)
@nox.session(python=PYTHON_VERSIONS, name="CLI tests", tags=["tests"])
def tests_cli(session: nox.Session) -> None:
session.run_install(
"uv",
"sync",
"--no-group=integrations",
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
)
session.install("uvicorn")
session.install("starlette")
session.run(
"pytest",
"--cov=.",
"--cov-append",
"tests/cli",
"-vv",
)