Luke Sneeringer | acb6e3e | 2017-10-31 08:57:09 -0700 | [diff] [blame] | 1 | # Copyright 2016 Google LLC |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 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 | |
| 15 | from __future__ import absolute_import |
| 16 | import os |
Bu Sun Kim | bee4b07 | 2019-06-25 12:44:16 -0700 | [diff] [blame] | 17 | import shutil |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 18 | |
Rebecca Chen | 0fce637 | 2018-09-27 10:45:58 -0700 | [diff] [blame] | 19 | # https://github.com/google/importlab/issues/25 |
| 20 | import nox # pytype: disable=import-error |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 21 | |
| 22 | |
Danny Hermes | fd1d18f | 2017-11-01 21:47:55 -0700 | [diff] [blame] | 23 | def default(session): |
| 24 | """Default unit test session. |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 25 | |
Danny Hermes | fd1d18f | 2017-11-01 21:47:55 -0700 | [diff] [blame] | 26 | 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 Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 31 | # Install all test dependencies, then install this package in-place. |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 32 | session.install("mock", "pytest", "pytest-cov", "grpcio >= 1.0.2") |
| 33 | session.install("-e", ".") |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 34 | |
| 35 | # Run py.test against the unit tests. |
| 36 | session.run( |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 37 | "py.test", |
| 38 | "--quiet", |
| 39 | "--cov=google.api_core", |
| 40 | "--cov=tests.unit", |
| 41 | "--cov-append", |
| 42 | "--cov-config=.coveragerc", |
| 43 | "--cov-report=", |
Tres Seaver | 0c2c556 | 2020-02-25 13:59:11 -0500 | [diff] [blame^] | 44 | "--cov-fail-under=0", |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 45 | os.path.join("tests", "unit"), |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 46 | *session.posargs |
| 47 | ) |
| 48 | |
| 49 | |
Bu Sun Kim | e72202e | 2020-02-19 17:58:47 -0800 | [diff] [blame] | 50 | @nox.session(python=["2.7", "3.5", "3.6", "3.7", "3.8"]) |
Bu Sun Kim | 9f45e3c | 2018-10-10 11:04:44 -0700 | [diff] [blame] | 51 | def unit(session): |
Danny Hermes | fd1d18f | 2017-11-01 21:47:55 -0700 | [diff] [blame] | 52 | """Run the unit test suite.""" |
Danny Hermes | fd1d18f | 2017-11-01 21:47:55 -0700 | [diff] [blame] | 53 | default(session) |
| 54 | |
| 55 | |
Bu Sun Kim | e72202e | 2020-02-19 17:58:47 -0800 | [diff] [blame] | 56 | @nox.session(python=["2.7", "3.5", "3.6", "3.7", "3.8"]) |
Bu Sun Kim | 9f45e3c | 2018-10-10 11:04:44 -0700 | [diff] [blame] | 57 | def unit_grpc_gcp(session): |
Weiran Fang | 0a5c85c | 2018-07-27 11:30:48 -0700 | [diff] [blame] | 58 | """Run the unit test suite with grpcio-gcp installed.""" |
| 59 | |
Weiran Fang | 0a5c85c | 2018-07-27 11:30:48 -0700 | [diff] [blame] | 60 | # Install grpcio-gcp |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 61 | session.install("grpcio-gcp") |
Weiran Fang | 0a5c85c | 2018-07-27 11:30:48 -0700 | [diff] [blame] | 62 | |
| 63 | default(session) |
| 64 | |
| 65 | |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 66 | @nox.session(python="3.6") |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 67 | def 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 Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 73 | session.install("flake8", "flake8-import-order") |
| 74 | session.install(".") |
| 75 | session.run("flake8", "google", "tests") |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 76 | |
| 77 | |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 78 | @nox.session(python="3.6") |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 79 | def lint_setup_py(session): |
| 80 | """Verify that setup.py is valid (including RST check).""" |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 81 | |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 82 | session.install("docutils", "Pygments") |
| 83 | session.run("python", "setup.py", "check", "--restructuredtext", "--strict") |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 84 | |
| 85 | |
Rebecca Chen | 0fce637 | 2018-09-27 10:45:58 -0700 | [diff] [blame] | 86 | # 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 Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 88 | @nox.session(python="3.6") |
Rebecca Chen | 0fce637 | 2018-09-27 10:45:58 -0700 | [diff] [blame] | 89 | def pytype(session): |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 90 | """Run type-checking.""" |
| 91 | session.install( |
Christopher Wilcox | 2576a1b | 2019-03-27 10:58:39 -0700 | [diff] [blame] | 92 | ".", "grpcio >= 1.8.2", "grpcio-gcp >= 0.2.2", "pytype >= 2019.3.21" |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 93 | ) |
| 94 | session.run("pytype") |
Rebecca Chen | 0fce637 | 2018-09-27 10:45:58 -0700 | [diff] [blame] | 95 | |
| 96 | |
Christopher Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 97 | @nox.session(python="3.6") |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 98 | def 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 Wilcox | 6f4070d | 2018-11-29 11:02:52 -0800 | [diff] [blame] | 104 | session.install("coverage", "pytest-cov") |
| 105 | session.run("coverage", "report", "--show-missing", "--fail-under=100") |
| 106 | session.run("coverage", "erase") |
Bu Sun Kim | bee4b07 | 2019-06-25 12:44:16 -0700 | [diff] [blame] | 107 | |
| 108 | |
| 109 | @nox.session(python="3.7") |
| 110 | def 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 Seaver | 0c2c556 | 2020-02-25 13:59:11 -0500 | [diff] [blame^] | 129 | ) |