This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnoxfile.py
106 lines (86 loc) · 3.46 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
import nox.sessions
# Nox
nox.options.reuse_existing_virtualenvs = True
nox.options.sessions = [
'tests',
'tests_sqlalchemy',
'tests_fastapi',
'tests_ariadne',
'tests_pydantic',
]
# Versions
PYTHON_VERSIONS = ['3.9', '3.10']
SQLALCHEMY_VERSIONS = [
# Selective.
# NOTE: keep major versions with breaking changes. Skip versions with minor bugfix changes.
'1.3.11', '1.3.24',
'1.4.23', '1.4.39',
]
FASTAPI_VERSIONS = [
# Selective: one latest version from 0.5x, 0.6x, 0.7x and so on
'0.59.0', '0.69.0', '0.73.0', '0.75.0', '0.79.0',
]
ARIADNE_VERSIONS = [
# Selective
'0.13.0', '0.14.1', '0.15.1',
]
GRAPHQL_CORE_VERSIONS = [
'3.1.0', '3.1.1', '3.1.2', '3.1.3', '3.1.4', '3.1.5', '3.1.6', '3.1.7',
'3.2.0', '3.2.1',
]
PYDANTIC_VERSIONS = [
# Selective
'1.7.4', # latest 1.7.x
'1.8', '1.8.1', '1.8.2',
'1.9.0', '1.9.1',
]
@nox.session(python=PYTHON_VERSIONS)
def tests(session: nox.sessions.Session, *, overrides: dict[str, str] = {}):
""" Run all tests """
# This approach works ok on GitHub but fails locally because we have Poetry within Poetry
# session.install('poetry')
# session.run('poetry', 'install')
# This approach works better locally: install from requirements.txt
session.install(*requirements_txt, '.')
if overrides:
session.install(*(f'{name}=={version}' for name, version in overrides.items()))
# Test
args = ['-k', 'not extra']
if not overrides:
args.append('--cov=apiens')
session.run('pytest', 'tests/', *args)
@nox.session(python=PYTHON_VERSIONS[-1])
@nox.parametrize('sqlalchemy', SQLALCHEMY_VERSIONS)
def tests_sqlalchemy(session: nox.sessions.Session, sqlalchemy):
""" Test against a specific SqlAlchemy version """
tests(session, overrides={'sqlalchemy': sqlalchemy})
@nox.session(python=PYTHON_VERSIONS[-1])
@nox.parametrize('fastapi', FASTAPI_VERSIONS)
def tests_fastapi(session: nox.sessions.Session, fastapi):
""" Test against a specific FastAPI version """
tests(session, overrides={'fastapi': fastapi})
@nox.session(python=PYTHON_VERSIONS[-1])
@nox.parametrize('ariadne', ARIADNE_VERSIONS)
def tests_ariadne(session: nox.sessions.Session, ariadne):
""" Test against a specific Ariadne version """
if ariadne == '0.13.0':
# This is because ariadne 0.13.0 cannot work with graphql 3.2.x: def each() fails on schema.directives because it's a tuple now
tests(session, overrides={'ariadne': '0.13.0', 'graphql-core': '3.1.7'})
else:
tests(session, overrides={'ariadne': ariadne})
@nox.session(python=PYTHON_VERSIONS[-1])
@nox.parametrize('graphql_core', GRAPHQL_CORE_VERSIONS)
def tests_graphql(session: nox.sessions.Session, graphql_core):
""" Test against a specific GraphQL version """
tests(session, overrides={'graphql-core': graphql_core})
@nox.session(python=PYTHON_VERSIONS[-1])
@nox.parametrize('pydantic', PYDANTIC_VERSIONS)
def tests_pydantic(session: nox.sessions.Session, pydantic):
""" Test against a specific Pydantic version """
tests(session, overrides={'pydantic': pydantic})
# Get requirements.txt from external poetry
import tempfile, subprocess
with tempfile.NamedTemporaryFile('w+') as f:
subprocess.run(f'poetry export --no-interaction --dev --format requirements.txt --without-hashes --output={f.name}', shell=True, check=True)
f.seek(0)
requirements_txt = [line.split(';', 1)[0] for line in f.readlines()] # after ";" go some Python version specifiers