Skip to content

Commit 1e8b8bb

Browse files
authored
test: use templated noxfiles (#393)
* test: use templated noxfiles Adjust test configuration to prepare for running on Kokoro. * enable system tests on Circle CI * use environment variables for project ID * add google-cloud-testutils to test deps * use pip script for circle * use pandas from constraints * fix constraints path * use nox * add ADC
1 parent 09160e7 commit 1e8b8bb

21 files changed

+547
-235
lines changed

Diff for: .circleci/config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
steps:
4040
- checkout
4141
- run: ci/config_auth.sh
42-
- run: nox -s unit-3.8 system-3.8 cover
42+
- run: export GOOGLE_APPLICATION_CREDENTIALS="$(pwd)/ci/service_account.json"; nox -s unit-3.8 system-3.8 cover
4343

4444
# Conda
4545
"conda-3.7":
@@ -72,4 +72,4 @@ workflows:
7272
- "pip-3.7"
7373
- "pip-3.8"
7474
- "conda-3.7"
75-
- "conda-3.9-NIGHTLY"
75+
- "conda-3.9-NIGHTLY"

Diff for: ci/constraints-3.7.pip

-8
This file was deleted.

Diff for: ci/run_pip.sh

-25
This file was deleted.

Diff for: ci/run_tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ if [ -f "$DIR/service_account.json" ]; then
1111
fi
1212

1313
# Install test requirements
14-
pip install coverage pytest pytest-cov flake8 codecov
14+
pip install coverage pytest pytest-cov flake8 codecov google-cloud-testutils
1515
pytest -v -m "not local_auth" --cov=pandas_gbq --cov-report xml:/tmp/pytest-cov.xml tests

Diff for: conftest.py

-80
This file was deleted.

Diff for: docs/howto/authentication.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ authentication methods:
6161
If pandas-gbq does not find cached credentials, it prompts you to open a
6262
web browser, where you can grant pandas-gbq permissions to access your
6363
cloud resources. These credentials are only used locally. See the
64-
:doc:`privacy policy <privacy>` for details.
64+
:doc:`privacy policy <../privacy>` for details.
6565

6666

6767
Authenticating with a Service Account

Diff for: noxfile.py

+143-44
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
# Copyright (c) 2017 pandas-gbq Authors All rights reserved.
2-
# Use of this source code is governed by a BSD-style
3-
# license that can be found in the LICENSE file.
4-
5-
"""Nox test automation configuration.
6-
7-
See: https://nox.readthedocs.io/en/latest/
8-
"""
9-
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2018 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Generated by synthtool. DO NOT EDIT!
18+
19+
from __future__ import absolute_import
1020
import os
11-
import os.path
21+
import pathlib
1222
import shutil
1323

1424
import nox
@@ -18,9 +28,21 @@
1828
BLACK_PATHS = ["docs", "pandas_gbq", "tests", "noxfile.py", "setup.py"]
1929

2030
DEFAULT_PYTHON_VERSION = "3.8"
21-
SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"]
31+
SYSTEM_TEST_PYTHON_VERSIONS = ["3.8", "3.9"]
2232
UNIT_TEST_PYTHON_VERSIONS = ["3.7", "3.8", "3.9"]
2333

34+
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
35+
36+
# 'docfx' is excluded since it only needs to run in 'docs-presubmit'
37+
nox.options.sessions = [
38+
"unit",
39+
"system",
40+
"cover",
41+
"lint",
42+
"lint_setup_py",
43+
"blacken",
44+
"docs",
45+
]
2446

2547
# Error if a python version is missing
2648
nox.options.error_on_missing_interpreters = True
@@ -29,6 +51,7 @@
2951
@nox.session(python=DEFAULT_PYTHON_VERSION)
3052
def lint(session):
3153
"""Run linters.
54+
3255
Returns a failure if the linters find linting errors or sufficiently
3356
serious code quality issues.
3457
"""
@@ -55,32 +78,99 @@ def lint_setup_py(session):
5578
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
5679

5780

58-
@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)
59-
def unit(session):
60-
session.install("pytest", "pytest-cov")
81+
def default(session):
82+
# Install all test dependencies, then install this package in-place.
83+
84+
constraints_path = str(
85+
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
86+
)
6187
session.install(
62-
"-e",
63-
".",
64-
# Use dependencies versions from constraints file. This enables testing
65-
# across a more full range of versions of the dependencies.
88+
"mock",
89+
"asyncmock",
90+
"pytest",
91+
"pytest-cov",
92+
"pytest-asyncio",
6693
"-c",
67-
os.path.join(".", "ci", "constraints-{}.pip".format(session.python)),
94+
constraints_path,
6895
)
96+
97+
session.install("-e", ".[tqdm]", "-c", constraints_path)
98+
99+
# Run py.test against the unit tests.
69100
session.run(
70-
"pytest",
71-
os.path.join(".", "tests", "unit"),
72-
"-v",
101+
"py.test",
102+
"--quiet",
103+
f"--junitxml=unit_{session.python}_sponge_log.xml",
73104
"--cov=pandas_gbq",
74-
"--cov=tests.unit",
75-
"--cov-report",
76-
"xml:/tmp/pytest-cov.xml",
105+
"--cov=tests/unit",
106+
"--cov-append",
107+
"--cov-config=.coveragerc",
108+
"--cov-report=",
109+
"--cov-fail-under=0",
110+
os.path.join("tests", "unit"),
77111
*session.posargs,
78112
)
79113

80114

115+
@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)
116+
def unit(session):
117+
"""Run the unit test suite."""
118+
default(session)
119+
120+
121+
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
122+
def system(session):
123+
"""Run the system test suite."""
124+
constraints_path = str(
125+
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
126+
)
127+
system_test_path = os.path.join("tests", "system.py")
128+
system_test_folder_path = os.path.join("tests", "system")
129+
130+
# Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true.
131+
if os.environ.get("RUN_SYSTEM_TESTS", "true") == "false":
132+
session.skip("RUN_SYSTEM_TESTS is set to false, skipping")
133+
# Install pyopenssl for mTLS testing.
134+
if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true":
135+
session.install("pyopenssl")
136+
137+
system_test_exists = os.path.exists(system_test_path)
138+
system_test_folder_exists = os.path.exists(system_test_folder_path)
139+
# Sanity check: only run tests if found.
140+
if not system_test_exists and not system_test_folder_exists:
141+
session.skip("System tests were not found")
142+
143+
# Use pre-release gRPC for system tests.
144+
session.install("--pre", "grpcio")
145+
146+
# Install all test dependencies, then install this package into the
147+
# virtualenv's dist-packages.
148+
session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path)
149+
session.install("-e", ".[tqdm]", "-c", constraints_path)
150+
151+
# Run py.test against the system tests.
152+
if system_test_exists:
153+
session.run(
154+
"py.test",
155+
"--quiet",
156+
f"--junitxml=system_{session.python}_sponge_log.xml",
157+
system_test_path,
158+
*session.posargs,
159+
)
160+
if system_test_folder_exists:
161+
session.run(
162+
"py.test",
163+
"--quiet",
164+
f"--junitxml=system_{session.python}_sponge_log.xml",
165+
system_test_folder_path,
166+
*session.posargs,
167+
)
168+
169+
81170
@nox.session(python=DEFAULT_PYTHON_VERSION)
82171
def cover(session):
83172
"""Run the final coverage report.
173+
84174
This outputs the coverage report aggregating coverage from the unit
85175
test runs (not system test runs), and then erases coverage data.
86176
"""
@@ -112,27 +202,36 @@ def docs(session):
112202
)
113203

114204

115-
@nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS)
116-
def system(session):
117-
session.install("pytest", "pytest-cov")
205+
@nox.session(python=DEFAULT_PYTHON_VERSION)
206+
def docfx(session):
207+
"""Build the docfx yaml files for this library."""
208+
209+
session.install("-e", ".")
118210
session.install(
119-
"-e",
120-
".",
121-
# Use dependencies versions from constraints file. This enables testing
122-
# across a more full range of versions of the dependencies.
123-
"-c",
124-
os.path.join(".", "ci", "constraints-{}.pip".format(session.python)),
211+
"sphinx==4.0.1", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml"
125212
)
126213

127-
# Skip local auth tests on CI.
128-
additional_args = list(session.posargs)
129-
if "CIRCLECI" in os.environ:
130-
additional_args = additional_args + ["-m", "not local_auth"]
131-
214+
shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
132215
session.run(
133-
"pytest",
134-
os.path.join(".", "tests", "system"),
135-
os.path.join(".", "samples", "snippets"),
136-
"-v",
137-
*additional_args,
216+
"sphinx-build",
217+
"-T", # show full traceback on exception
218+
"-N", # no colors
219+
"-D",
220+
(
221+
"extensions=sphinx.ext.autodoc,"
222+
"sphinx.ext.autosummary,"
223+
"docfx_yaml.extension,"
224+
"sphinx.ext.intersphinx,"
225+
"sphinx.ext.coverage,"
226+
"sphinx.ext.napoleon,"
227+
"sphinx.ext.todo,"
228+
"sphinx.ext.viewcode,"
229+
"recommonmark"
230+
),
231+
"-b",
232+
"html",
233+
"-d",
234+
os.path.join("docs", "_build", "doctrees", ""),
235+
os.path.join("docs", ""),
236+
os.path.join("docs", "_build", "html", ""),
138237
)

0 commit comments

Comments
 (0)