File: noxfile.py

package info (click to toggle)
python-lia 0.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 744 kB
  • sloc: python: 2,262; sh: 23; makefile: 10
file content (227 lines) | stat: -rw-r--r-- 7,153 bytes parent folder | download
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
# type: ignore
"""Nox sessions for testing and linting."""

import nox

# Configure nox to use uv
nox.options.default_venv_backend = "uv"
nox.options.reuse_existing_virtualenvs = True

# Python versions to test
PYTHON_VERSIONS = ["3.9", "3.10", "3.11", "3.12", "3.13"]
DJANGO_PYTHON_VERSIONS = ["3.10", "3.11", "3.12", "3.13"]

# Framework versions to test
DJANGO_VERSIONS = ["5.0", "5.1", "5.2"]
FLASK_VERSIONS = ["2.3", "3.0", "3.1"]
STARLETTE_VERSIONS = ["0.47"]


@nox.session(python=PYTHON_VERSIONS, tags=["tests"])
def tests(session: nox.Session) -> None:
    """Run the complete test suite with all dependencies."""
    session.run_install(
        "uv",
        "sync",
        "--dev",
        "--group",
        "integrations",
        "--no-default-groups",
        f"--python={session.virtualenv.location}",
        env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
    )
    session.run("coverage", "run", "-m", "pytest", "-v")


@nox.session(python=DJANGO_PYTHON_VERSIONS, tags=["tests"])
@nox.parametrize("django", DJANGO_VERSIONS)
def tests_django(session: nox.Session, django: str) -> None:
    """Test Django adapter with different Django versions."""
    session.run_install(
        "uv",
        "sync",
        "--dev",
        "--group",
        "integrations",
        "--no-default-groups",
        f"--python={session.virtualenv.location}",
        env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
    )
    session.install(f"django~={django}.0")
    session.run("coverage", "run", "-m", "pytest", "-m", "django", "-v")


@nox.session(python=["3.9", "3.12"], tags=["tests"])
@nox.parametrize("flask", FLASK_VERSIONS)
def tests_flask(session: nox.Session, flask: str) -> None:
    """Test Flask adapter with different Flask versions."""
    session.run_install(
        "uv",
        "sync",
        "--dev",
        "--group",
        "integrations",
        "--no-default-groups",
        f"--python={session.virtualenv.location}",
        env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
    )
    session.install(f"flask~={flask}.0")
    session.run("coverage", "run", "-m", "pytest", "-m", "flask", "-v")


@nox.session(python=["3.9", "3.12"], tags=["tests"])
@nox.parametrize("starlette", STARLETTE_VERSIONS)
def tests_starlette(session: nox.Session, starlette: str) -> None:
    """Test Starlette adapter with different Starlette versions."""
    session.run_install(
        "uv",
        "sync",
        "--dev",
        "--group",
        "integrations",
        "--no-default-groups",
        f"--python={session.virtualenv.location}",
        env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
    )
    session.install(f"starlette~={starlette}.0")
    session.run("coverage", "run", "-m", "pytest", "-m", "starlette", "-v")


@nox.session(python=["3.12"], name="tests-frameworks", tags=["tests"])
def tests_frameworks(session: nox.Session) -> None:
    """Test all framework adapters."""
    # Install base package
    session.run_install(
        "uv",
        "sync",
        "--dev",
        "--no-default-groups",
        f"--python={session.virtualenv.location}",
        env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
    )

    # Test each framework adapter separately
    frameworks = {
        "sanic": ["sanic", "sanic-testing"],
        "aiohttp": ["aiohttp", "yarl"],
        "quart": ["quart"],
        "chalice": ["chalice"],
        "litestar": ["litestar", "httpx"],
    }

    for framework, deps in frameworks.items():
        session.install(*deps)
        session.run("coverage", "run", "-m", "pytest", "-m", framework, "-v")


@nox.session(python=["3.12"], name="tests-fastapi", tags=["tests"])
def tests_fastapi(session: nox.Session) -> None:
    """Test FastAPI integration."""
    session.run_install(
        "uv",
        "sync",
        "--dev",
        "--no-default-groups",
        f"--python={session.virtualenv.location}",
        env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
    )
    session.install("fastapi", "httpx", "python-multipart")
    session.run("coverage", "run", "-m", "pytest", "-m", "fastapi", "-v")


@nox.session(python=["3.12"])
def lint(session: nox.Session) -> None:
    """Run linting checks."""
    session.run_install(
        "uv",
        "sync",
        "--dev",
        "--no-default-groups",
        f"--python={session.virtualenv.location}",
        env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
    )
    session.run("ruff", "check", ".")
    session.run("ruff", "format", "--check", ".")


@nox.session(python=["3.12"])
def mypy(session: nox.Session) -> None:
    """Run type checking with mypy."""
    session.run_install(
        "uv",
        "sync",
        "--dev",
        "--group",
        "integrations",
        "--no-default-groups",
        f"--python={session.virtualenv.location}",
        env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
    )
    session.run("mypy", "src")


@nox.session(python=["3.12"])
def coverage(session: nox.Session) -> None:
    """Combine coverage data and generate reports."""
    session.run_install(
        "uv",
        "sync",
        "--dev",
        "--no-default-groups",
        f"--python={session.virtualenv.location}",
        env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
    )

    # Combine coverage data from multiple test runs
    session.run("coverage", "combine", success_codes=[0, 1])

    # Generate HTML report
    session.run("coverage", "html", "--skip-covered", "--skip-empty")

    # Generate markdown report for GitHub Actions summary (if in CI)
    if session.posargs and "--ci" in session.posargs:
        session.run(
            "sh",
            "-c",
            "coverage report --format=markdown >> $GITHUB_STEP_SUMMARY",
            success_codes=[0, 1],
            external=True,
        )

    # Show report in terminal and check coverage threshold
    session.run("coverage", "report", "--fail-under=80")


@nox.session(python=["3.12"], name="test-coverage-html")
def test_coverage_html(session: nox.Session) -> None:
    """Run all tests and generate HTML coverage report (local use only)."""
    session.run_install(
        "uv",
        "sync",
        "--dev",
        "--group",
        "integrations",
        "--no-default-groups",
        f"--python={session.virtualenv.location}",
        env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
    )

    # Run all tests with coverage
    session.run("coverage", "run", "-m", "pytest", "-v")

    # Combine any existing coverage files (in case of parallel runs or leftover files)
    session.run("coverage", "combine", success_codes=[0, 1])

    session.run("coverage", "html")
    session.run("coverage", "report")

    # Open the HTML report in the browser (optional)
    import webbrowser
    import pathlib

    html_report = pathlib.Path("htmlcov/index.html").absolute()
    if html_report.exists():
        session.log(f"Opening coverage report at: {html_report}")
        webbrowser.open(f"file://{html_report}")
    else:
        session.warn("HTML coverage report not found")