forked from googleapis/python-bigquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noxfile.py
233 lines (185 loc) · 7.47 KB
/
noxfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# Copyright 2016 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import
import os
import shutil
import nox
BLACK_PATHS = ("docs", "google", "samples", "tests", "noxfile.py", "setup.py")
def default(session):
"""Default unit test session.
This is intended to be run **without** an interpreter set, so
that the current ``python`` (on the ``PATH``) or the version of
Python corresponding to the ``nox`` binary the ``PATH`` can
run the tests.
"""
# Install all test dependencies, then install local packages in-place.
session.install(
"mock", "pytest", "google-cloud-testutils", "pytest-cov", "freezegun"
)
session.install("grpcio")
# fastparquet is not included in .[all] because, in general, it's redundant
# with pyarrow. We still want to run some unit tests with fastparquet
# serialization, though.
session.install("-e", ".[all,fastparquet]")
# IPython does not support Python 2 after version 5.x
if session.python == "2.7":
session.install("ipython==5.5")
else:
session.install("ipython")
# opentelemetry was not added to [all] because opentelemetry does not support Python 2.
# Exporter does not need to be in nox thus it has been added to README documentation
if session.python != "2.7":
session.install("-e", ".[opentelemetry]")
# Run py.test against the unit tests.
session.run(
"py.test",
"--quiet",
"--cov=google.cloud.bigquery",
"--cov=tests.unit",
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=0",
os.path.join("tests", "unit"),
*session.posargs,
)
@nox.session(python=["2.7", "3.5", "3.6", "3.7", "3.8"])
def unit(session):
"""Run the unit test suite."""
default(session)
@nox.session(python=["2.7", "3.8"])
def system(session):
"""Run the system test suite."""
# Check the value of `RUN_SYSTEM_TESTS` env var. It defaults to true.
if os.environ.get("RUN_SYSTEM_TESTS", "true") == "false":
session.skip("RUN_SYSTEM_TESTS is set to false, skipping")
# Sanity check: Only run system tests if the environment variable is set.
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
session.skip("Credentials must be set via environment variable.")
# Use pre-release gRPC for system tests.
session.install("--pre", "grpcio")
# Install all test dependencies, then install local packages in place.
session.install("mock", "pytest", "psutil", "google-cloud-testutils")
session.install("google-cloud-storage")
session.install("-e", ".[all]")
# IPython does not support Python 2 after version 5.x
if session.python == "2.7":
session.install("ipython==5.5")
else:
session.install("ipython")
# Run py.test against the system tests.
session.run(
"py.test", "--quiet", os.path.join("tests", "system.py"), *session.posargs
)
@nox.session(python=["2.7", "3.8"])
def snippets(session):
"""Run the snippets test suite."""
# Sanity check: Only run snippets tests if the environment variable is set.
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""):
session.skip("Credentials must be set via environment variable.")
# Install all test dependencies, then install local packages in place.
session.install("mock", "pytest", "google-cloud-testutils")
session.install("google-cloud-storage")
session.install("grpcio")
session.install("-e", ".[all]")
# Run py.test against the snippets tests.
# Skip tests in samples/snippets, as those are run in a different session
# using the nox config from that directory.
session.run("py.test", os.path.join("docs", "snippets.py"), *session.posargs)
session.run("py.test", "samples", "--ignore=samples/snippets", *session.posargs)
@nox.session(python="3.8")
def cover(session):
"""Run the final coverage report.
This outputs the coverage report aggregating coverage from the unit
test runs (not system test runs), and then erases coverage data.
"""
session.install("coverage", "pytest-cov")
session.run("coverage", "report", "--show-missing", "--fail-under=100")
session.run("coverage", "erase")
@nox.session(python="3.8")
def lint(session):
"""Run linters.
Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
session.install("black", "flake8")
session.install("-e", ".")
session.run("flake8", os.path.join("google", "cloud", "bigquery"))
session.run("flake8", "tests")
session.run("flake8", os.path.join("docs", "samples"))
session.run("flake8", os.path.join("docs", "snippets.py"))
session.run("black", "--check", *BLACK_PATHS)
@nox.session(python="3.8")
def lint_setup_py(session):
"""Verify that setup.py is valid (including RST check)."""
session.install("docutils", "Pygments")
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
@nox.session(python="3.6")
def blacken(session):
"""Run black.
Format code to uniform standard.
This currently uses Python 3.6 due to the automated Kokoro run of synthtool.
That run uses an image that doesn't have 3.6 installed. Before updating this
check the state of the `gcp_ubuntu_config` we use for that Kokoro run.
"""
session.install("black")
session.run("black", *BLACK_PATHS)
@nox.session(python="3.8")
def docs(session):
"""Build the docs."""
session.install("ipython", "recommonmark", "sphinx", "sphinx_rtd_theme")
session.install("google-cloud-storage")
session.install("-e", ".[all]")
shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
session.run(
"sphinx-build",
"-W", # warnings as errors
"-T", # show full traceback on exception
"-N", # no colors
"-b",
"html",
"-d",
os.path.join("docs", "_build", "doctrees", ""),
os.path.join("docs", ""),
os.path.join("docs", "_build", "html", ""),
)
@nox.session(python="3.8")
def docfx(session):
"""Build the docfx yaml files for this library."""
session.install("-e", ".")
session.install("sphinx", "alabaster", "recommonmark", "sphinx-docfx-yaml")
shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
session.run(
"sphinx-build",
"-T", # show full traceback on exception
"-N", # no colors
"-D",
(
"extensions=sphinx.ext.autodoc,"
"sphinx.ext.autosummary,"
"docfx_yaml.extension,"
"sphinx.ext.intersphinx,"
"sphinx.ext.coverage,"
"sphinx.ext.napoleon,"
"sphinx.ext.todo,"
"sphinx.ext.viewcode,"
"recommonmark"
),
"-b",
"html",
"-d",
os.path.join("docs", "_build", "doctrees", ""),
os.path.join("docs", ""),
os.path.join("docs", "_build", "html", ""),
)