Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add prerelease session to test with latest dependencies, separate compliance tests #401

Merged
merged 17 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .kokoro/continuous/compliance.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Only run this nox session.
env_vars: {
key: "NOX_SESSION"
value: "compliance"
}
7 changes: 7 additions & 0 deletions .kokoro/continuous/prerelease.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Only run this nox session.
env_vars: {
key: "NOX_SESSION"
value: "prerelease"
}
7 changes: 7 additions & 0 deletions .kokoro/presubmit/compliance.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Only run this nox session.
env_vars: {
key: "NOX_SESSION"
value: "compliance"
}
7 changes: 7 additions & 0 deletions .kokoro/presubmit/prerelease.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Only run this nox session.
env_vars: {
key: "NOX_SESSION"
value: "prerelease"
}
84 changes: 77 additions & 7 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from __future__ import absolute_import
import os
import pathlib
import re
import shutil

import nox
Expand All @@ -37,11 +38,10 @@

# 'docfx' is excluded since it only needs to run in 'docs-presubmit'
nox.options.sessions = [
"lint",
"unit",
"cover",
"system",
"compliance",
"cover",
"lint",
"lint_setup_py",
"blacken",
"docs",
Expand Down Expand Up @@ -183,7 +183,77 @@ def system(session):
)


@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
@nox.session(python=DEFAULT_PYTHON_VERSION)
def prerelease(session):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Mostly taken straight from https://github.com/googleapis/python-bigquery-pandas/blob/d4539747848156446d8a3ccdb49661e72ae03109/noxfile.py#L176

googleapis/synthtool#1290 is open to add this to the templates, though it would need to be slightly templated to allow for customized prerelease dependencies.

session.install(
"--prefer-binary",
"--pre",
"--upgrade",
"alembic",
"geoalchemy2",
"google-api-core",
"google-cloud-bigquery",
"google-cloud-bigquery-storage",
"sqlalchemy",
"shapely",
# These are transitive dependencies, but we'd still like to know if a
# change in a prerelease there breaks this connector.
"google-cloud-core",
"grpcio",
)
session.install(
"freezegun",
"google-cloud-testutils",
"mock",
"psutil",
"pytest",
"pytest-cov",
"pytz",
)

# Because we test minimum dependency versions on the minimum Python
# version, the first version we test with in the unit tests sessions has a
# constraints file containing all dependencies and extras.
with open(
CURRENT_DIRECTORY
/ "testing"
/ f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt",
encoding="utf-8",
) as constraints_file:
constraints_text = constraints_file.read()

# Ignore leading whitespace and comment lines.
deps = [
match.group(1)
for match in re.finditer(
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
)
]

# We use --no-deps to ensure that pre-release versions aren't overwritten
# by the version ranges in setup.py.
session.install(*deps)
session.install("--no-deps", "-e", ".")

# Print out prerelease package versions.
session.run("python", "-m", "pip", "freeze")

# Run all tests, except a few samples tests which require extra dependencies.
session.run(
"py.test",
"--quiet",
f"--junitxml=prerelease_unit_{session.python}_sponge_log.xml",
os.path.join("tests", "unit"),
)
session.run(
"py.test",
"--quiet",
f"--junitxml=prerelease_system_{session.python}_sponge_log.xml",
os.path.join("tests", "system"),
)


@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS[-1])
def compliance(session):
"""Run the SQLAlchemy dialect-compliance system tests"""
constraints_path = str(
Expand All @@ -193,8 +263,6 @@ def compliance(session):

if os.environ.get("RUN_COMPLIANCE_TESTS", "true") == "false":
session.skip("RUN_COMPLIANCE_TESTS is set to false, skipping")
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
session.skip("Credentials must be set via environment variable")
if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true":
session.install("pyopenssl")
if not os.path.exists(system_test_folder_path):
Expand All @@ -204,7 +272,9 @@ def compliance(session):

session.install(
"mock",
"pytest",
# TODO: Allow latest version of pytest once SQLAlchemy 1.4.28+ is supported.
# See: https://github.com/googleapis/python-bigquery-sqlalchemy/issues/413
"pytest<=7.0.0dev",
"pytest-rerunfailures",
"google-cloud-testutils",
"-c",
Expand Down
100 changes: 81 additions & 19 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
'"sqlalchemy_bigquery"',
)

s.replace(
["noxfile.py"],
r"import shutil",
"import re\nimport shutil",
)

s.replace(
["noxfile.py"], "--cov=google", "--cov=sqlalchemy_bigquery",
)
Expand All @@ -89,28 +95,84 @@ def place_before(path, text, *before_text, escape=None):
"nox.options.stop_on_first_error = True",
)

old_sessions = '''
"unit",
"system",
"cover",
"lint",
'''
prerelease = r'''
@nox.session(python=DEFAULT_PYTHON_VERSION)
def prerelease(session):
session.install(
"--prefer-binary",
"--pre",
"--upgrade",
"alembic",
"geoalchemy2",
"google-api-core",
"google-cloud-bigquery",
"google-cloud-bigquery-storage",
"sqlalchemy",
"shapely",
# These are transitive dependencies, but we'd still like to know if a
# change in a prerelease there breaks this connector.
"google-cloud-core",
"grpcio",
)
session.install(
"freezegun",
"google-cloud-testutils",
"mock",
"psutil",
"pytest",
"pytest-cov",
"pytz",
)

new_sessions = '''
"lint",
"unit",
"cover",
"system",
"compliance",
'''
# Because we test minimum dependency versions on the minimum Python
# version, the first version we test with in the unit tests sessions has a
# constraints file containing all dependencies and extras.
with open(
CURRENT_DIRECTORY
/ "testing"
/ f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt",
encoding="utf-8",
) as constraints_file:
constraints_text = constraints_file.read()

# Ignore leading whitespace and comment lines.
deps = [
match.group(1)
for match in re.finditer(
r"^\\s*(\\S+)(?===\\S+)", constraints_text, flags=re.MULTILINE
)
]

# We use --no-deps to ensure that pre-release versions aren't overwritten
# by the version ranges in setup.py.
session.install(*deps)
session.install("--no-deps", "-e", ".")

# Print out prerelease package versions.
session.run("python", "-m", "pip", "freeze")

# Run all tests, except a few samples tests which require extra dependencies.
session.run(
"py.test",
"--quiet",
f"--junitxml=prerelease_unit_{session.python}_sponge_log.xml",
os.path.join("tests", "unit"),
)
session.run(
"py.test",
"--quiet",
f"--junitxml=prerelease_system_{session.python}_sponge_log.xml",
os.path.join("tests", "system"),
)

s.replace( ["noxfile.py"], old_sessions, new_sessions)

'''

# Maybe we can get rid of this when we don't need pytest-rerunfailures,
# which we won't need when BQ retries itself:
# https://github.com/googleapis/python-bigquery/pull/837
compliance = '''
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS[-1])
def compliance(session):
"""Run the SQLAlchemy dialect-compliance system tests"""
constraints_path = str(
Expand All @@ -120,8 +182,6 @@ def compliance(session):

if os.environ.get("RUN_COMPLIANCE_TESTS", "true") == "false":
session.skip("RUN_COMPLIANCE_TESTS is set to false, skipping")
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
session.skip("Credentials must be set via environment variable")
if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true":
session.install("pyopenssl")
if not os.path.exists(system_test_folder_path):
Expand All @@ -131,7 +191,9 @@ def compliance(session):

session.install(
"mock",
"pytest",
# TODO: Allow latest version of pytest once SQLAlchemy 1.4.28+ is supported.
# See: https://github.com/googleapis/python-bigquery-sqlalchemy/issues/413
"pytest<=7.0.0dev",
"pytest-rerunfailures",
"google-cloud-testutils",
"-c",
Expand Down Expand Up @@ -166,7 +228,7 @@ def compliance(session):
"noxfile.py",
"@nox.session(python=DEFAULT_PYTHON_VERSION)\n"
"def cover(session):",
compliance,
prerelease + compliance,
escape="()",
)

Expand Down