blob: 249ace7fbd25444ce1fcd0036f0e422ea0a582af [file] [log] [blame]
Luke Sneeringeracb6e3e2017-10-31 08:57:09 -07001# Copyright 2016 Google LLC
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -07002#
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
15from __future__ import absolute_import
16import os
Bu Sun Kimbee4b072019-06-25 12:44:16 -070017import shutil
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070018
Rebecca Chen0fce6372018-09-27 10:45:58 -070019# https://github.com/google/importlab/issues/25
20import nox # pytype: disable=import-error
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070021
22
Danny Hermesfd1d18f2017-11-01 21:47:55 -070023def default(session):
24 """Default unit test session.
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070025
Danny Hermesfd1d18f2017-11-01 21:47:55 -070026 This is intended to be run **without** an interpreter set, so
27 that the current ``python`` (on the ``PATH``) or the version of
28 Python corresponding to the ``nox`` binary the ``PATH`` can
29 run the tests.
30 """
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070031 # Install all test dependencies, then install this package in-place.
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080032 session.install("mock", "pytest", "pytest-cov", "grpcio >= 1.0.2")
33 session.install("-e", ".")
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070034
35 # Run py.test against the unit tests.
36 session.run(
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080037 "py.test",
38 "--quiet",
39 "--cov=google.api_core",
40 "--cov=tests.unit",
41 "--cov-append",
42 "--cov-config=.coveragerc",
43 "--cov-report=",
Tres Seaver0c2c5562020-02-25 13:59:11 -050044 "--cov-fail-under=0",
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080045 os.path.join("tests", "unit"),
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070046 *session.posargs
47 )
48
49
Bu Sun Kime72202e2020-02-19 17:58:47 -080050@nox.session(python=["2.7", "3.5", "3.6", "3.7", "3.8"])
Bu Sun Kim9f45e3c2018-10-10 11:04:44 -070051def unit(session):
Danny Hermesfd1d18f2017-11-01 21:47:55 -070052 """Run the unit test suite."""
Danny Hermesfd1d18f2017-11-01 21:47:55 -070053 default(session)
54
55
Bu Sun Kime72202e2020-02-19 17:58:47 -080056@nox.session(python=["2.7", "3.5", "3.6", "3.7", "3.8"])
Bu Sun Kim9f45e3c2018-10-10 11:04:44 -070057def unit_grpc_gcp(session):
Weiran Fang0a5c85c2018-07-27 11:30:48 -070058 """Run the unit test suite with grpcio-gcp installed."""
59
Weiran Fang0a5c85c2018-07-27 11:30:48 -070060 # Install grpcio-gcp
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080061 session.install("grpcio-gcp")
Weiran Fang0a5c85c2018-07-27 11:30:48 -070062
63 default(session)
64
65
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080066@nox.session(python="3.6")
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070067def lint(session):
68 """Run linters.
69
70 Returns a failure if the linters find linting errors or sufficiently
71 serious code quality issues.
72 """
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080073 session.install("flake8", "flake8-import-order")
74 session.install(".")
75 session.run("flake8", "google", "tests")
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070076
77
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080078@nox.session(python="3.6")
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070079def lint_setup_py(session):
80 """Verify that setup.py is valid (including RST check)."""
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070081
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080082 session.install("docutils", "Pygments")
83 session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070084
85
Rebecca Chen0fce6372018-09-27 10:45:58 -070086# No 2.7 due to https://github.com/google/importlab/issues/26.
87# No 3.7 because pytype supports up to 3.6 only.
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080088@nox.session(python="3.6")
Rebecca Chen0fce6372018-09-27 10:45:58 -070089def pytype(session):
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080090 """Run type-checking."""
91 session.install(
Christopher Wilcox2576a1b2019-03-27 10:58:39 -070092 ".", "grpcio >= 1.8.2", "grpcio-gcp >= 0.2.2", "pytype >= 2019.3.21"
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080093 )
94 session.run("pytype")
Rebecca Chen0fce6372018-09-27 10:45:58 -070095
96
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080097@nox.session(python="3.6")
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070098def cover(session):
99 """Run the final coverage report.
100
101 This outputs the coverage report aggregating coverage from the unit
102 test runs (not system test runs), and then erases coverage data.
103 """
Christopher Wilcox6f4070d2018-11-29 11:02:52 -0800104 session.install("coverage", "pytest-cov")
105 session.run("coverage", "report", "--show-missing", "--fail-under=100")
106 session.run("coverage", "erase")
Bu Sun Kimbee4b072019-06-25 12:44:16 -0700107
108
109@nox.session(python="3.7")
110def docs(session):
111 """Build the docs for this library."""
112
113 session.install(".", "grpcio >= 1.8.2", "grpcio-gcp >= 0.2.2")
114 session.install("-e", ".")
115 session.install("sphinx", "alabaster", "recommonmark")
116
117 shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
118 session.run(
119 "sphinx-build",
120 "-W", # warnings as errors
121 "-T", # show full traceback on exception
122 "-N", # no colors
123 "-b",
124 "html",
125 "-d",
126 os.path.join("docs", "_build", "doctrees", ""),
127 os.path.join("docs", ""),
128 os.path.join("docs", "_build", "html", ""),
Tres Seaver0c2c5562020-02-25 13:59:11 -0500129 )