Skip to content

Commit 7f36628

Browse files
test: add prerelease session to test with latest dependencies, separate compliance tests (#401)
* test: add prerelease session to test with latest dependencies * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Revert "🦉 Updates from OwlBot" This reverts commit 01aca60. * Avoid owlbot from overwriting my changes * split compliance and prerelease tests out * remove newline escape * escape regex * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * remove unused [all] * disallow latest pytest due to incompatibilities * only use single python for compliance testing * comment about transitive deps Also, remove google-resumable-media from prerelease tests, as this package does not use load jobs. Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 2ee34e2 commit 7f36628

File tree

6 files changed

+186
-26
lines changed

6 files changed

+186
-26
lines changed

.kokoro/continuous/compliance.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Only run this nox session.
4+
env_vars: {
5+
key: "NOX_SESSION"
6+
value: "compliance"
7+
}

.kokoro/continuous/prerelease.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Only run this nox session.
4+
env_vars: {
5+
key: "NOX_SESSION"
6+
value: "prerelease"
7+
}

.kokoro/presubmit/compliance.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Only run this nox session.
4+
env_vars: {
5+
key: "NOX_SESSION"
6+
value: "compliance"
7+
}

.kokoro/presubmit/prerelease.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Only run this nox session.
4+
env_vars: {
5+
key: "NOX_SESSION"
6+
value: "prerelease"
7+
}

noxfile.py

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from __future__ import absolute_import
2020
import os
2121
import pathlib
22+
import re
2223
import shutil
2324

2425
import nox
@@ -37,11 +38,10 @@
3738

3839
# 'docfx' is excluded since it only needs to run in 'docs-presubmit'
3940
nox.options.sessions = [
40-
"lint",
4141
"unit",
42-
"cover",
4342
"system",
44-
"compliance",
43+
"cover",
44+
"lint",
4545
"lint_setup_py",
4646
"blacken",
4747
"docs",
@@ -183,7 +183,77 @@ def system(session):
183183
)
184184

185185

186-
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
186+
@nox.session(python=DEFAULT_PYTHON_VERSION)
187+
def prerelease(session):
188+
session.install(
189+
"--prefer-binary",
190+
"--pre",
191+
"--upgrade",
192+
"alembic",
193+
"geoalchemy2",
194+
"google-api-core",
195+
"google-cloud-bigquery",
196+
"google-cloud-bigquery-storage",
197+
"sqlalchemy",
198+
"shapely",
199+
# These are transitive dependencies, but we'd still like to know if a
200+
# change in a prerelease there breaks this connector.
201+
"google-cloud-core",
202+
"grpcio",
203+
)
204+
session.install(
205+
"freezegun",
206+
"google-cloud-testutils",
207+
"mock",
208+
"psutil",
209+
"pytest",
210+
"pytest-cov",
211+
"pytz",
212+
)
213+
214+
# Because we test minimum dependency versions on the minimum Python
215+
# version, the first version we test with in the unit tests sessions has a
216+
# constraints file containing all dependencies and extras.
217+
with open(
218+
CURRENT_DIRECTORY
219+
/ "testing"
220+
/ f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt",
221+
encoding="utf-8",
222+
) as constraints_file:
223+
constraints_text = constraints_file.read()
224+
225+
# Ignore leading whitespace and comment lines.
226+
deps = [
227+
match.group(1)
228+
for match in re.finditer(
229+
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
230+
)
231+
]
232+
233+
# We use --no-deps to ensure that pre-release versions aren't overwritten
234+
# by the version ranges in setup.py.
235+
session.install(*deps)
236+
session.install("--no-deps", "-e", ".")
237+
238+
# Print out prerelease package versions.
239+
session.run("python", "-m", "pip", "freeze")
240+
241+
# Run all tests, except a few samples tests which require extra dependencies.
242+
session.run(
243+
"py.test",
244+
"--quiet",
245+
f"--junitxml=prerelease_unit_{session.python}_sponge_log.xml",
246+
os.path.join("tests", "unit"),
247+
)
248+
session.run(
249+
"py.test",
250+
"--quiet",
251+
f"--junitxml=prerelease_system_{session.python}_sponge_log.xml",
252+
os.path.join("tests", "system"),
253+
)
254+
255+
256+
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS[-1])
187257
def compliance(session):
188258
"""Run the SQLAlchemy dialect-compliance system tests"""
189259
constraints_path = str(
@@ -193,8 +263,6 @@ def compliance(session):
193263

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

205273
session.install(
206274
"mock",
207-
"pytest",
275+
# TODO: Allow latest version of pytest once SQLAlchemy 1.4.28+ is supported.
276+
# See: https://github.com/googleapis/python-bigquery-sqlalchemy/issues/413
277+
"pytest<=7.0.0dev",
208278
"pytest-rerunfailures",
209279
"google-cloud-testutils",
210280
"-c",

owlbot.py

Lines changed: 81 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
'"sqlalchemy_bigquery"',
6666
)
6767

68+
s.replace(
69+
["noxfile.py"],
70+
r"import shutil",
71+
"import re\nimport shutil",
72+
)
73+
6874
s.replace(
6975
["noxfile.py"], "--cov=google", "--cov=sqlalchemy_bigquery",
7076
)
@@ -89,28 +95,84 @@ def place_before(path, text, *before_text, escape=None):
8995
"nox.options.stop_on_first_error = True",
9096
)
9197

92-
old_sessions = '''
93-
"unit",
94-
"system",
95-
"cover",
96-
"lint",
97-
'''
98+
prerelease = r'''
99+
@nox.session(python=DEFAULT_PYTHON_VERSION)
100+
def prerelease(session):
101+
session.install(
102+
"--prefer-binary",
103+
"--pre",
104+
"--upgrade",
105+
"alembic",
106+
"geoalchemy2",
107+
"google-api-core",
108+
"google-cloud-bigquery",
109+
"google-cloud-bigquery-storage",
110+
"sqlalchemy",
111+
"shapely",
112+
# These are transitive dependencies, but we'd still like to know if a
113+
# change in a prerelease there breaks this connector.
114+
"google-cloud-core",
115+
"grpcio",
116+
)
117+
session.install(
118+
"freezegun",
119+
"google-cloud-testutils",
120+
"mock",
121+
"psutil",
122+
"pytest",
123+
"pytest-cov",
124+
"pytz",
125+
)
98126
99-
new_sessions = '''
100-
"lint",
101-
"unit",
102-
"cover",
103-
"system",
104-
"compliance",
105-
'''
127+
# Because we test minimum dependency versions on the minimum Python
128+
# version, the first version we test with in the unit tests sessions has a
129+
# constraints file containing all dependencies and extras.
130+
with open(
131+
CURRENT_DIRECTORY
132+
/ "testing"
133+
/ f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt",
134+
encoding="utf-8",
135+
) as constraints_file:
136+
constraints_text = constraints_file.read()
137+
138+
# Ignore leading whitespace and comment lines.
139+
deps = [
140+
match.group(1)
141+
for match in re.finditer(
142+
r"^\\s*(\\S+)(?===\\S+)", constraints_text, flags=re.MULTILINE
143+
)
144+
]
145+
146+
# We use --no-deps to ensure that pre-release versions aren't overwritten
147+
# by the version ranges in setup.py.
148+
session.install(*deps)
149+
session.install("--no-deps", "-e", ".")
150+
151+
# Print out prerelease package versions.
152+
session.run("python", "-m", "pip", "freeze")
153+
154+
# Run all tests, except a few samples tests which require extra dependencies.
155+
session.run(
156+
"py.test",
157+
"--quiet",
158+
f"--junitxml=prerelease_unit_{session.python}_sponge_log.xml",
159+
os.path.join("tests", "unit"),
160+
)
161+
session.run(
162+
"py.test",
163+
"--quiet",
164+
f"--junitxml=prerelease_system_{session.python}_sponge_log.xml",
165+
os.path.join("tests", "system"),
166+
)
106167
107-
s.replace( ["noxfile.py"], old_sessions, new_sessions)
168+
169+
'''
108170

109171
# Maybe we can get rid of this when we don't need pytest-rerunfailures,
110172
# which we won't need when BQ retries itself:
111173
# https://github.com/googleapis/python-bigquery/pull/837
112174
compliance = '''
113-
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
175+
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS[-1])
114176
def compliance(session):
115177
"""Run the SQLAlchemy dialect-compliance system tests"""
116178
constraints_path = str(
@@ -120,8 +182,6 @@ def compliance(session):
120182
121183
if os.environ.get("RUN_COMPLIANCE_TESTS", "true") == "false":
122184
session.skip("RUN_COMPLIANCE_TESTS is set to false, skipping")
123-
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
124-
session.skip("Credentials must be set via environment variable")
125185
if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true":
126186
session.install("pyopenssl")
127187
if not os.path.exists(system_test_folder_path):
@@ -131,7 +191,9 @@ def compliance(session):
131191
132192
session.install(
133193
"mock",
134-
"pytest",
194+
# TODO: Allow latest version of pytest once SQLAlchemy 1.4.28+ is supported.
195+
# See: https://github.com/googleapis/python-bigquery-sqlalchemy/issues/413
196+
"pytest<=7.0.0dev",
135197
"pytest-rerunfailures",
136198
"google-cloud-testutils",
137199
"-c",
@@ -166,7 +228,7 @@ def compliance(session):
166228
"noxfile.py",
167229
"@nox.session(python=DEFAULT_PYTHON_VERSION)\n"
168230
"def cover(session):",
169-
compliance,
231+
prerelease + compliance,
170232
escape="()",
171233
)
172234

0 commit comments

Comments
 (0)