blob: 0bd7f6c6c40fb3b5381a6723ff42b628cda16166 [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
72@nox.session(python="3.6")
73def blacken(session):
74 """Run black.
Bu Sun Kim65e33c02019-10-25 10:45:00 -070075 Format code to uniform standard.
Bu Sun Kim65e33c02019-10-25 10:45:00 -070076 This currently uses Python 3.6 due to the automated Kokoro run of synthtool.
77 That run uses an image that doesn't have 3.6 installed. Before updating this
78 check the state of the `gcp_ubuntu_config` we use for that Kokoro run.
79 """
80 session.install(BLACK_VERSION)
81 session.run("black", *BLACK_PATHS)
82
83
Tres Seaver6de753d2020-12-11 13:20:39 -050084@nox.session(python=["3.6", "3.7", "3.8", "3.9"])
Bu Sun Kim65e33c02019-10-25 10:45:00 -070085def unit(session):
86 session.install(*TEST_DEPENDENCIES)
Christopher Wilcox7e152582020-09-28 15:27:20 -070087 session.install(*(ASYNC_DEPENDENCIES))
88 session.install(".")
89 session.run(
90 "pytest",
Bu Sun Kime87b1ec2021-03-15 09:02:06 -060091 f"--junitxml=unit_{session.python}_sponge_log.xml",
Christopher Wilcox7e152582020-09-28 15:27:20 -070092 "--cov=google.auth",
93 "--cov=google.oauth2",
94 "--cov=tests",
95 "tests",
96 "tests_async",
97 )
98
99
Tres Seaver6de753d2020-12-11 13:20:39 -0500100@nox.session(python=["2.7"])
Christopher Wilcox7e152582020-09-28 15:27:20 -0700101def unit_prev_versions(session):
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700102 session.install(".")
Bu Sun Kim882d0ff2021-02-16 13:10:11 -0700103 session.install(*TEST_DEPENDENCIES)
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700104 session.run(
Bu Sun Kime87b1ec2021-03-15 09:02:06 -0600105 "pytest",
106 f"--junitxml=unit_{session.python}_sponge_log.xml",
107 "--cov=google.auth",
108 "--cov=google.oauth2",
109 "--cov=tests",
110 "tests",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700111 )
112
113
114@nox.session(python="3.7")
115def cover(session):
116 session.install(*TEST_DEPENDENCIES)
Christopher Wilcox7e152582020-09-28 15:27:20 -0700117 session.install(*(ASYNC_DEPENDENCIES))
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700118 session.install(".")
119 session.run(
120 "pytest",
121 "--cov=google.auth",
122 "--cov=google.oauth2",
123 "--cov=tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700124 "--cov=tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700125 "--cov-report=",
126 "tests",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700127 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700128 )
129 session.run("coverage", "report", "--show-missing", "--fail-under=100")
130
131
132@nox.session(python="3.7")
133def docgen(session):
134 session.env["SPHINX_APIDOC_OPTIONS"] = "members,inherited-members,show-inheritance"
135 session.install(*TEST_DEPENDENCIES)
136 session.install("sphinx")
137 session.install(".")
138 session.run("rm", "-r", "docs/reference")
139 session.run(
140 "sphinx-apidoc",
141 "--output-dir",
142 "docs/reference",
143 "--separate",
144 "--module-first",
145 "google",
146 )
147
148
149@nox.session(python="3.7")
150def docs(session):
Bu Sun Kimb1a12d22021-02-26 11:50:02 -0700151 """Build the docs for this library."""
152
153 session.install("-e", ".[aiohttp]")
154 session.install(
155 "sphinx<3.0.0", "alabaster", "recommonmark", "sphinx-docstring-typing"
156 )
157
158 shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
159 session.run(
160 "sphinx-build",
161 "-T", # show full traceback on exception
162 "-W", # warnings as errors
163 "-N", # no colors
164 "-b",
165 "html",
166 "-d",
167 os.path.join("docs", "_build", "doctrees", ""),
168 os.path.join("docs", ""),
169 os.path.join("docs", "_build", "html", ""),
170 )
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700171
172
173@nox.session(python="pypy")
174def pypy(session):
175 session.install(*TEST_DEPENDENCIES)
Tres Seaver3b3172e2020-10-22 16:05:20 -0400176 session.install(*ASYNC_DEPENDENCIES)
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700177 session.install(".")
178 session.run(
Christopher Wilcox7e152582020-09-28 15:27:20 -0700179 "pytest",
Bu Sun Kime87b1ec2021-03-15 09:02:06 -0600180 f"--junitxml=unit_{session.python}_sponge_log.xml",
Christopher Wilcox7e152582020-09-28 15:27:20 -0700181 "--cov=google.auth",
182 "--cov=google.oauth2",
183 "--cov=tests",
184 "tests",
185 "tests_async",
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700186 )