-
-
Notifications
You must be signed in to change notification settings - Fork 535
/
noxfile.py
190 lines (151 loc) · 5.38 KB
/
noxfile.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import itertools
from typing import Any, Callable, List
import nox
from nox_poetry import Session, session
nox.options.reuse_existing_virtualenvs = True
nox.options.error_on_external_run = True
nox.options.default_venv_backend = "uv"
PYTHON_VERSIONS = ["3.13", "3.12", "3.11", "3.10", "3.9", "3.8"]
GQL_CORE_VERSIONS = [
"3.2.3",
"3.3.0a6",
]
COMMON_PYTEST_OPTIONS = [
"--cov=.",
"--cov-append",
"--cov-report=xml",
"-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: Session, version: str) -> None:
session._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 lambda fn: nox.parametrize(arg_names, combinations, ids=ids)(fn)
@session(python=PYTHON_VERSIONS, name="Tests", tags=["tests"])
@gql_core_parametrize
def tests(session: Session, gql_core: str) -> None:
session.run_always("poetry", "install", external=True)
_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,
)
@session(python=["3.12"], name="Django tests", tags=["tests"])
@with_gql_core_parametrize("django", ["4.2.0", "4.1.0", "4.0.0", "3.2.0"])
def tests_django(session: Session, django: str, gql_core: str) -> None:
session.run_always("poetry", "install", external=True)
_install_gql_core(session, gql_core)
session._session.install(f"django~={django}") # type: ignore
session._session.install("pytest-django") # type: ignore
session.run("pytest", *COMMON_PYTEST_OPTIONS, "-m", "django")
@session(python=["3.11"], name="Starlette tests", tags=["tests"])
@with_gql_core_parametrize("starlette", ["0.28.0", "0.27.0", "0.26.1"])
def tests_starlette(session: Session, starlette: str, gql_core: str) -> None:
session.run_always("poetry", "install", external=True)
session._session.install(f"starlette=={starlette}") # type: ignore
_install_gql_core(session, gql_core)
session.run("pytest", *COMMON_PYTEST_OPTIONS, "-m", "asgi")
@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: Session, integration: str, gql_core: str) -> None:
session.run_always("poetry", "install", external=True)
session._session.install(integration) # type: ignore
_install_gql_core(session, gql_core)
if integration == "aiohttp":
session._session.install("pytest-aiohttp") # type: ignore
elif integration == "channels":
session._session.install("pytest-django") # type: ignore
session._session.install("daphne") # type: ignore
session.run("pytest", *COMMON_PYTEST_OPTIONS, "-m", integration)
@session(python=PYTHON_VERSIONS, name="Pydantic tests", tags=["tests", "pydantic"])
@with_gql_core_parametrize("pydantic", ["1.10", "2.8.0", "2.9.0"])
def test_pydantic(session: Session, pydantic: str, gql_core: str) -> None:
session.run_always("poetry", "install", external=True)
session._session.install(f"pydantic~={pydantic}") # type: ignore
_install_gql_core(session, gql_core)
session.run(
"pytest",
"--cov=.",
"--cov-append",
"--cov-report=xml",
"-m",
"pydantic",
"--ignore=tests/cli",
)
@session(python=PYTHON_VERSIONS, name="Type checkers tests", tags=["tests"])
def tests_typecheckers(session: Session) -> None:
session.run_always("poetry", "install", external=True)
session.install("pyright")
session.install("pydantic")
session.install("git+https://github.com/python/mypy.git#master")
session.run(
"pytest",
"--cov=.",
"--cov-append",
"--cov-report=xml",
"tests/typecheckers",
"-vv",
)
@session(python=PYTHON_VERSIONS, name="CLI tests", tags=["tests"])
def tests_cli(session: Session) -> None:
session.run_always("poetry", "install", external=True)
session._session.install("uvicorn") # type: ignore
session._session.install("starlette") # type: ignore
session.run(
"pytest",
"--cov=.",
"--cov-append",
"--cov-report=xml",
"tests/cli",
"-vv",
)
@session(name="Mypy", tags=["lint"])
def mypy(session: Session) -> None:
session.run_always("poetry", "install", "--with", "integrations", external=True)
session.install("mypy")
session.run("mypy", "--config-file", "mypy.ini")