diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 881def25f..3e7469cb8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -90,6 +90,49 @@ jobs: tool: just - run: just test offline + # The SQLAlchemy tests that need no AWS, and the collection of the compliance + # suites, on the latest release of each supported SQLAlchemy series; the + # offline job above runs the dialect tests on the locked version, + # and the AWS suites run the compliance suites on it. The AWS suites + # do not wait for this job, so a new SQLAlchemy release that breaks it does + # not stop the AWS suites of unrelated pull requests. The Release workflow + # requires it, as it requires every job of this workflow. + offline-sqla: + runs-on: ubuntu-latest + timeout-minutes: 20 + permissions: + contents: read + strategy: + fail-fast: false + matrix: + # Each series runs on the newest Python version for which its releases + # publish compiled wheels, so the versions differ: SQLAlchemy 2.0 has + # none for Python 3.15, where only its pure-Python wheel, without the + # C extensions, would install. Move a series to a newer Python version + # once its releases publish compiled wheels for it. + include: + - sqlalchemy: '2.0' + python-version: '3.14' + - sqlalchemy: '2.1' + python-version: '3.15' + steps: + - name: Checkout + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0 + with: + python-version: ${{ matrix.python-version }} + enable-cache: true + # As in the offline job, uv's Python 3.13+ cannot compile Python.h. + - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 + with: + python-version: ${{ matrix.python-version }} + - uses: taiki-e/install-action@7a79fe8c3a13344501c80d99cae481c1c9085912 # v2.81.10 + with: + tool: just + - run: just test offline-sqla ${{ matrix.sqlalchemy }} + # Selects the AWS suites and Python versions. Draft and external-fork pull # requests run none. A ready pull request runs the PyAthena suite only when # the package, the tests, setup.cfg, the dependencies, or this workflow @@ -168,7 +211,8 @@ jobs: EVENT_NAME: ${{ github.event_name }} REQUESTED_VERSIONS: ${{ inputs.python-versions }} # Every supported version, oldest first; keep in sync with the - # pyproject.toml classifiers and the offline job's version. + # pyproject.toml classifiers, the offline job's version, and the + # offline-sqla job's matrix. PYTHON_VERSIONS: '["3.11", "3.12", "3.13", "3.14", "3.15"]' run: | case "$EVENT_NAME" in diff --git a/AGENTS.md b/AGENTS.md index 651140662..46ad94cfe 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -55,6 +55,7 @@ just lint # Python lint, format check, mypy, CloudFormation validation, and li ```bash # ALWAYS run `just lint` first — tests will fail if lint doesn't pass just test offline # PyAthena tests that need no AWS, with no AWS credentials or .env +just test offline-sqla 2.0 # SQLAlchemy tests that need no AWS on the latest 2.0 release (also 2.1, or a version) just test pyathena # PyAthena tests, including AWS integration (runs lint first) just test sqla # SQLAlchemy compliance suite just test sqla-async # SQLAlchemy async compliance suite diff --git a/docs/contributing.md b/docs/contributing.md index 0516c05d3..17617359d 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -63,6 +63,7 @@ Choose coverage based on the affected behavior, including synchronous and asynch SQLAlchemy dialect changes require the relevant PyAthena dialect tests under `tests/pyathena/sqlalchemy/` as well as the SQLAlchemy compliance suite (`just test sqla`). Changes affecting async dialects also require the relevant tests under `tests/pyathena/aio/sqlalchemy/` and `just test sqla-async`. The PyAthena dialect tests are included in `just test pyathena`; they are not run by the two compliance-suite commands. +`just test offline-sqla 2.0` and `just test offline-sqla 2.1` run the dialect tests that need no AWS, and collect the compliance suites, on the latest release of each supported SQLAlchemy series. Exercise the regression on the version before the fix where practical, and record the before/after result. Documentation-only changes need documentation checks; changes limited to logic independent of AWS need appropriate tests for that logic. `just test offline` runs the tests that need no AWS without AWS credentials; the testing guide describes when a change also needs the AWS tests. diff --git a/docs/testing.md b/docs/testing.md index 315f185ff..773371fc0 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -161,6 +161,17 @@ When a change affects a request to AWS, or how PyAthena reads what AWS returns, uv run --env-file .env pytest -n 1 -m aws tests/pyathena/test_cursor.py ``` +`just test offline` runs the SQLAlchemy tests on the locked SQLAlchemy. +`just test offline-sqla ` runs the SQLAlchemy tests that need no AWS (`tests/pyathena/sqlalchemy/` and `tests/pyathena/aio/sqlalchemy/`) on another release, in the same environment, and collects the compliance suites (`tests/sqlalchemy/`, synchronous and `--dburi async`), which imports them without contacting AWS: + +```bash +just test offline-sqla 2.0 # the latest 2.0 release that the sqlalchemy extras allow +just test offline-sqla 2.1 # the latest 2.1 release +just test offline-sqla 2.1.9 # a given release +``` + +uv resolves a series from `pyproject.toml`, and the recipe prints the SQLAlchemy version that it runs. + ### S3 null-version moves The null-version move regression tests create three dedicated temporary buckets: @@ -271,6 +282,7 @@ Retain dtype and schema checks, option contexts, and resource cleanup where appl The Test workflow runs for pull requests that change files other than `docs/` and Markdown. It runs the offline checks (`just lint`, and `just test offline` on the newest supported Python version) on each of them, including Drafts and external forks. +It also runs `just test offline-sqla 2.0` and `just test offline-sqla 2.1`, for each supported SQLAlchemy series, each on the newest Python version for which that series publishes compiled wheels; the AWS suites do not wait for these, and the Release workflow requires them. The AWS suites start only after the offline checks pass, and run as follows: | Trigger | PyAthena suite | SQLAlchemy tests | Spark tests | Python versions | diff --git a/justfile b/justfile index aafe7d0e5..d3c3d4b6a 100644 --- a/justfile +++ b/justfile @@ -35,9 +35,10 @@ lint: license-headers license-headers: uv run python scripts/check_license_headers.py -# Run tests: just test (pyathena|offline|sqla|sqla-async) -test target="help": - @just _test-{{ if target =~ "^-" { "help" } else { target } }} +# Run tests: just test (pyathena|offline|offline-sqla SERIES|VERSION|sqla|sqla-async) +[positional-arguments] +test target="help" *args: + @shift && just _test-{{ if target =~ "^-" { "help" } else { target } }} "$@" _test-help: @echo "Usage: just test " @@ -45,21 +46,26 @@ _test-help: @echo "Targets:" @echo " pyathena Run the PyAthena tests, including AWS integration tests (runs lint first)" @echo " offline Run the PyAthena tests that need no AWS, with no AWS credentials" + @echo " offline-sqla SERIES|VERSION" + @echo " Run the SQLAlchemy tests that need no AWS and collect the compliance" + @echo " suites on the latest release of a series, such as 2.0, or a version" @echo " sqla Run SQLAlchemy dialect tests" @echo " sqla-async Run SQLAlchemy async dialect tests" _test-pyathena: lint uv run pytest -n 8 {{PYTEST_RERUN}} --cov pyathena --cov-report html --cov-report term tests/pyathena/ -# Sync the environment first, as uv run does, with the developer's settings. -# Then unset every AWS and fsspec setting and HTTP_PROXY, HTTPS_PROXY, and -# ALL_PROXY in either case, set NO_PROXY and no_proxy to '*', and give the four -# settings that tests/__init__.py requires placeholder values. A request -# made by accident carries credentials that no account accepts, and the clients -# that read AWS_ENDPOINT_URL send it to a reserved name that does not resolve -# (RFC 6761), with AWS_MAX_ATTEMPTS=1 and POLARS_CLOUD_MAX_RETRIES=0. uv must not -# load a .env file back. -_test-offline: +# Run a command with no AWS settings, for the tests that need no AWS. Sync the +# environment first, as uv run does, with the developer's settings. Then unset +# every AWS and fsspec setting and HTTP_PROXY, HTTPS_PROXY, and ALL_PROXY in +# either case, set NO_PROXY and no_proxy to '*', and give the four settings that +# tests/__init__.py requires placeholder values. A request made by accident +# carries credentials that no account accepts, and the clients that read +# AWS_ENDPOINT_URL send it to a reserved name that does not resolve (RFC 6761), +# with AWS_MAX_ATTEMPTS=1 and POLARS_CLOUD_MAX_RETRIES=0. uv must not load a +# .env file back. +[positional-arguments] +_offline *command: #!/usr/bin/env bash set -euo pipefail uv run --no-env-file true @@ -73,7 +79,37 @@ _test-offline: export AWS_CONFIG_FILE=/dev/null AWS_SHARED_CREDENTIALS_FILE=/dev/null BOTO_CONFIG=/dev/null export AWS_EC2_METADATA_DISABLED=true FSSPEC_CONFIG_DIR=/dev/null export AWS_ENDPOINT_URL=https://offline.invalid AWS_MAX_ATTEMPTS=1 POLARS_CLOUD_MAX_RETRIES=0 - uv run --no-sync --no-env-file pytest -n auto -p no:rerunfailures -m "not aws" tests/pyathena/ + "$@" + +_test-offline: + @just _offline uv run --no-sync --no-env-file pytest -n auto -p no:rerunfailures -m "not aws" tests/pyathena/ + +# The SQLAlchemy tests that need no AWS, and the collection of the compliance +# suites (which imports them without contacting AWS), on another SQLAlchemy: +# a series such as 2.0 runs its latest release that the extras allow, resolved +# by uv, and any other value is a version. The packages are resolved and cached +# before _offline removes the proxy settings, and the runs inside it use that +# cache only (--offline), so the recipe needs uv's cache. +[positional-arguments] +_test-offline-sqla version: + #!/usr/bin/env bash + set -euo pipefail + if [[ "$1" =~ ^([0-9]+)\.([0-9]+)$ ]]; then + series="sqlalchemy>=$1,<${BASH_REMATCH[1]}.$((BASH_REMATCH[2] + 1))" + version=$(uv pip compile pyproject.toml --extra sqlalchemy --extra aiosqlalchemy \ + --constraint <(echo "$series") --resolution highest \ + --no-deps --no-header --no-annotate --quiet \ + | sed -n 's/^sqlalchemy==//p') + else + version="$1" + fi + with="sqlalchemy[asyncio]==$version" + echo "SQLAlchemy $version" + uv run --no-env-file --with "$with" true + run=(uv run --offline --no-sync --no-env-file --with "$with") + just _offline "${run[@]}" pytest -n auto -p no:rerunfailures -m "not aws" tests/pyathena/sqlalchemy/ tests/pyathena/aio/sqlalchemy/ + just _offline "${run[@]}" pytest -n 0 -p no:rerunfailures --collect-only -qq tests/sqlalchemy/ + just _offline "${run[@]}" pytest -n 0 -p no:rerunfailures --collect-only -qq tests/sqlalchemy/ --dburi async _test-sqla: uv run pytest -n 8 {{PYTEST_RERUN}} --cov pyathena --cov-report html --cov-report term tests/sqlalchemy/ diff --git a/tests/sqlalchemy/test_suite.py b/tests/sqlalchemy/test_suite.py index dd63e5a66..19fbe0aaa 100644 --- a/tests/sqlalchemy/test_suite.py +++ b/tests/sqlalchemy/test_suite.py @@ -1276,6 +1276,20 @@ class CompoundSelectTest(_InsertFixtureRowsOnce, _CompoundSelectTest): pass +if hasattr(sa_suite, "NameDenormalizeTest"): # SQLAlchemy 2.1 and later + + class NameDenormalizeTest(_InsertFixtureRowsOnce, sa_suite.NameDenormalizeTest): + @functools.wraps(sa_suite.NameDenormalizeTest.test_cols_driver_cols) + def test_cols_driver_cols(self, **kwargs): + # SQLAlchemy's variations also pass exclusion arguments. Athena + # returns the column names of a core select as its column list + # writes them, but the names of `SELECT *` in lowercase, including + # quoted names, which the driver SQL and textual statements read. + if not kwargs["stmt_type"].core_select: + pytest.skip("Athena returns column names in lowercase.") + super().test_cols_driver_cols(**kwargs) + + if hasattr(sa_suite, "DeprecatedCompoundSelectTest"): # SQLAlchemy 2.1 removed this test class.