blob: 236b59c4bfc7fa3043ad00a12fa5d3dfdb076c35 [file] [log] [blame]
Bu Sun Kim65e33c02019-10-25 10:45:00 -07001# Copyright 2019 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Bu Sun Kimb1a12d22021-02-26 11:50:02 -070015import shutil
16import os
Bu Sun Kim65e33c02019-10-25 10:45:00 -070017import nox
18
19TEST_DEPENDENCIES = [
20 "flask",
Peter Lamutd86d7b82019-12-12 01:33:45 +010021 "freezegun",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070022 "mock",
23 "oauth2client",
arithmetic1728bb9215a2020-03-20 09:49:44 -070024 "pyopenssl",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070025 "pytest",
26 "pytest-cov",
27 "pytest-localserver",
arithmetic172882293fe2021-04-14 11:22:13 -070028 "pyu2f",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070029 "requests",
30 "urllib3",
31 "cryptography",
Brent Shafferbc0ec932020-02-13 14:11:34 -080032 "responses",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070033 "grpcio",
34]
Christopher Wilcox7e152582020-09-28 15:27:20 -070035
Bu Sun Kimd7c63002021-03-08 14:17:54 -070036ASYNC_DEPENDENCIES = [
37 "pytest-asyncio",
38 "aioresponses",
39 "asynctest",
40 "aiohttp!=3.7.4.post0",
41]
Christopher Wilcox7e152582020-09-28 15:27:20 -070042
Bu Sun Kim65e33c02019-10-25 10:45:00 -070043BLACK_VERSION = "black==19.3b0"
Christopher Wilcox7e152582020-09-28 15:27:20 -070044BLACK_PATHS = [
45 "google",
46 "tests",
47 "tests_async",
48 "noxfile.py",
49 "setup.py",
50 "docs/conf.py",
51]
Bu Sun Kim65e33c02019-10-25 10:45:00 -070052
53
54@nox.session(python="3.7")
55def lint(session):
56 session.install("flake8", "flake8-import-order", "docutils", BLACK_VERSION)
57 session.install(".")
58 session.run("black", "--check", *BLACK_PATHS)
59 session.run(
60 "flake8",
61 "--import-order-style=google",
62 "--application-import-names=google,tests,system_tests",
63 "google",
64 "tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -070065 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -070066 )
67 session.run(
68 "python", "setup.py", "check", "--metadata", "--restructuredtext", "--strict"
69 )
70
71
Bu Sun Kima9234422021-05-24 18:16:01 -060072@nox.session(python="3.8")
Bu Sun Kim65e33c02019-10-25 10:45:00 -070073def blacken(session):
74 """Run black.
Bu Sun Kim65e33c02019-10-25 10:45:00 -070075 Format code to uniform standard.
Bu Sun Kima9234422021-05-24 18:16:01 -060076 The Python version should be consistent with what is
77 supplied in the Python Owlbot postprocessor.
78
79 https://github.com/googleapis/synthtool/blob/master/docker/owlbot/python/Dockerfile
Bu Sun Kim65e33c02019-10-25 10:45:00 -070080 """
81 session.install(BLACK_VERSION)
82 session.run("black", *BLACK_PATHS)
83
84
Tres Seaver6de753d2020-12-11 13:20:39 -050085@nox.session(python=["3.6", "3.7", "3.8", "3.9"])
Bu Sun Kim65e33c02019-10-25 10:45:00 -070086def unit(session):
87 session.install(*TEST_DEPENDENCIES)
Christopher Wilcox7e152582020-09-28 15:27:20 -070088 session.install(*(ASYNC_DEPENDENCIES))
89 session.install(".")
90 session.run(
91 "pytest",
Bu Sun Kime87b1ec2021-03-15 09:02:06 -060092 f"--junitxml=unit_{session.python}_sponge_log.xml",
Christopher Wilcox7e152582020-09-28 15:27:20 -070093 "--cov=google.auth",
94 "--cov=google.oauth2",
95 "--cov=tests",
96 "tests",
97 "tests_async",
98 )
99
100
Tres Seaver6de753d2020-12-11 13:20:39 -0500101@nox.session(python=["2.7"])
Christopher Wilcox7e152582020-09-28 15:27:20 -0700102def unit_prev_versions(session):
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700103 session.install(".")
Bu Sun Kim882d0ff2021-02-16 13:10:11 -0700104 session.install(*TEST_DEPENDENCIES)
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700105 session.run(
Bu Sun Kime87b1ec2021-03-15 09:02:06 -0600106 "pytest",
107 f"--junitxml=unit_{session.python}_sponge_log.xml",
108 "--cov=google.auth",
109 "--cov=google.oauth2",
110 "--cov=tests",
111 "tests",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700112 )
113
114
115@nox.session(python="3.7")
116def cover(session):
117 session.install(*TEST_DEPENDENCIES)
Christopher Wilcox7e152582020-09-28 15:27:20 -0700118 session.install(*(ASYNC_DEPENDENCIES))
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700119 session.install(".")
120 session.run(
121 "pytest",
122 "--cov=google.auth",
123 "--cov=google.oauth2",
124 "--cov=tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700125 "--cov=tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700126 "--cov-report=",
127 "tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700128 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700129 )
130 session.run("coverage", "report", "--show-missing", "--fail-under=100")
131
132
133@nox.session(python="3.7")
134def docgen(session):
135 session.env["SPHINX_APIDOC_OPTIONS"] = "members,inherited-members,show-inheritance"
136 session.install(*TEST_DEPENDENCIES)
137 session.install("sphinx")
138 session.install(".")
139 session.run("rm", "-r", "docs/reference")
140 session.run(
141 "sphinx-apidoc",
142 "--output-dir",
143 "docs/reference",
144 "--separate",
145 "--module-first",
146 "google",
147 )
148
149
150@nox.session(python="3.7")
151def docs(session):
Bu Sun Kimb1a12d22021-02-26 11:50:02 -0700152 """Build the docs for this library."""
153
154 session.install("-e", ".[aiohttp]")
155 session.install(
156 "sphinx<3.0.0", "alabaster", "recommonmark", "sphinx-docstring-typing"
157 )
158
159 shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
160 session.run(
161 "sphinx-build",
162 "-T", # show full traceback on exception
163 "-W", # warnings as errors
164 "-N", # no colors
165 "-b",
166 "html",
167 "-d",
168 os.path.join("docs", "_build", "doctrees", ""),
169 os.path.join("docs", ""),
170 os.path.join("docs", "_build", "html", ""),
171 )
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700172
173
174@nox.session(python="pypy")
175def pypy(session):
176 session.install(*TEST_DEPENDENCIES)
Tres Seaver3b3172e2020-10-22 16:05:20 -0400177 session.install(*ASYNC_DEPENDENCIES)
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700178 session.install(".")
179 session.run(
Christopher Wilcox7e152582020-09-28 15:27:20 -0700180 "pytest",
Bu Sun Kime87b1ec2021-03-15 09:02:06 -0600181 f"--junitxml=unit_{session.python}_sponge_log.xml",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700182 "--cov=google.auth",
183 "--cov=google.oauth2",
184 "--cov=tests",
185 "tests",
186 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700187 )