|
14 | 14 |
|
15 | 15 | import os |
16 | 16 | import pathlib |
| 17 | +import re |
17 | 18 | import shutil |
18 | 19 |
|
19 | 20 | import nox |
|
33 | 34 | ] |
34 | 35 |
|
35 | 36 | DEFAULT_PYTHON_VERSION = "3.14" |
| 37 | + |
| 38 | +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2450): |
| 39 | +# Switch this to Python 3.15 alpha1 |
| 40 | +# https://peps.python.org/pep-0790/ |
| 41 | +PREVIEW_PYTHON_VERSION = "3.14" |
| 42 | + |
36 | 43 | UNIT_TEST_PYTHON_VERSIONS = [ |
37 | 44 | "3.10", |
38 | 45 | "3.11", |
|
42 | 49 | ] |
43 | 50 | ALL_PYTHON = UNIT_TEST_PYTHON_VERSIONS.copy() |
44 | 51 |
|
| 52 | +UNIT_TEST_STANDARD_DEPENDENCIES = [ |
| 53 | + "mock", |
| 54 | + "asyncmock", |
| 55 | + "pytest", |
| 56 | + "pytest-cov", |
| 57 | + "pytest-asyncio", |
| 58 | +] |
| 59 | +UNIT_TEST_EXTERNAL_DEPENDENCIES: list[str] = [] |
| 60 | + |
45 | 61 | # Error if a python version is missing |
46 | 62 | nox.options.error_on_missing_interpreters = True |
47 | 63 |
|
@@ -220,23 +236,83 @@ def docfx(session): |
220 | 236 | session.skip("This package does not have documentation in cloud.google.com") |
221 | 237 |
|
222 | 238 |
|
223 | | -@nox.session(python=DEFAULT_PYTHON_VERSION) |
224 | | -def prerelease_deps(session): |
225 | | - """Run all tests with pre-release versions of dependencies installed |
| 239 | +@nox.session(python=PREVIEW_PYTHON_VERSION) |
| 240 | +@nox.parametrize( |
| 241 | + "protobuf_implementation", |
| 242 | + ["python", "upb"], |
| 243 | +) |
| 244 | +def prerelease_deps(session, protobuf_implementation): |
| 245 | + """ |
| 246 | + Run all tests with pre-release versions of dependencies installed |
226 | 247 | rather than the standard non pre-release versions. |
227 | 248 | Pre-release versions can be installed using |
228 | 249 | `pip install --pre <package>`. |
229 | 250 | """ |
230 | | - # TODO(https://github.com/googleapis/google-cloud-python/issues/16013): |
231 | | - # Add prerelease tests |
232 | | - session.skip("Prerelease tests are not yet supported") |
| 251 | + |
| 252 | + # Install all dependencies |
| 253 | + session.install("-e", ".[testing,rsa]") |
| 254 | + session.install("oauth2client") |
| 255 | + |
| 256 | + # Install dependencies for the unit test environment |
| 257 | + unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES |
| 258 | + session.install(*unit_deps_all) |
| 259 | + |
| 260 | + # Because we test minimum dependency versions on the minimum Python |
| 261 | + # version, the first version we test with in the unit tests sessions has a |
| 262 | + # constraints file containing all dependencies and extras. |
| 263 | + with open( |
| 264 | + CURRENT_DIRECTORY / "testing" / f"constraints-{ALL_PYTHON[0]}.txt", |
| 265 | + encoding="utf-8", |
| 266 | + ) as constraints_file: |
| 267 | + constraints_text = constraints_file.read() |
| 268 | + |
| 269 | + # Ignore leading whitespace and comment lines. |
| 270 | + constraints_deps = [ |
| 271 | + match.group(1) |
| 272 | + for match in re.finditer( |
| 273 | + r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE |
| 274 | + ) |
| 275 | + ] |
| 276 | + |
| 277 | + # Install dependencies specified in `testing/constraints-X.txt`. |
| 278 | + session.install(*constraints_deps) |
| 279 | + |
| 280 | + # Note: If a dependency is added to the `prerel_deps` list, |
| 281 | + # the `core_dependencies_from_source` list in the `core_deps_from_source` |
| 282 | + # nox session should also be updated. |
| 283 | + prerel_deps = [ |
| 284 | + # Note: We use --no-deps below to prevent prerelease updates. |
| 285 | + # However, aiohttp 3.10+ introduced aiohappyeyeballs as a strict requirement. |
| 286 | + # We must manually inject it here so the aiohttp pre-release doesn't crash on import. |
| 287 | + "aiohappyeyeballs", |
| 288 | + "aiohttp", |
| 289 | + "cryptography", |
| 290 | + "grpcio", |
| 291 | + "pyasn1-modules", |
| 292 | + "pyjwt", |
| 293 | + "pyopenssl", |
| 294 | + "requests", |
| 295 | + "rsa", |
| 296 | + "urllib3", |
| 297 | + ] |
| 298 | + |
| 299 | + for dep in prerel_deps: |
| 300 | + session.install("--pre", "--no-deps", "--ignore-installed", dep) |
| 301 | + print(f"Installed {dep}") |
| 302 | + |
| 303 | + session.run( |
| 304 | + "py.test", |
| 305 | + "tests", |
| 306 | + "tests_async", |
| 307 | + env={ |
| 308 | + "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation, |
| 309 | + }, |
| 310 | + ) |
233 | 311 |
|
234 | 312 |
|
235 | 313 | @nox.session(python=DEFAULT_PYTHON_VERSION) |
236 | 314 | def core_deps_from_source(session): |
237 | 315 | """Run all tests with core dependencies installed from source |
238 | 316 | rather than pulling the dependencies from PyPI. |
239 | 317 | """ |
240 | | - # TODO(https://github.com/googleapis/google-cloud-python/issues/16013): |
241 | | - # Add prerelease tests |
242 | | - session.skip("Prerelease tests are not yet supported") |
| 318 | + session.skip("Skipping: Not applicable for google-auth.") |
0 commit comments