Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 1 | # 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 | |
| 15 | import nox |
| 16 | |
| 17 | TEST_DEPENDENCIES = [ |
| 18 | "flask", |
Peter Lamut | d86d7b8 | 2019-12-12 01:33:45 +0100 | [diff] [blame] | 19 | "freezegun", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 20 | "mock", |
| 21 | "oauth2client", |
arithmetic1728 | bb9215a | 2020-03-20 09:49:44 -0700 | [diff] [blame] | 22 | "pyopenssl", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 23 | "pytest", |
| 24 | "pytest-cov", |
| 25 | "pytest-localserver", |
| 26 | "requests", |
| 27 | "urllib3", |
| 28 | "cryptography", |
Brent Shaffer | bc0ec93 | 2020-02-13 14:11:34 -0800 | [diff] [blame] | 29 | "responses", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 30 | "grpcio", |
| 31 | ] |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 32 | |
David Buxton | b790e65 | 2020-10-29 21:38:01 +0000 | [diff] [blame] | 33 | ASYNC_DEPENDENCIES = ["pytest-asyncio", "aioresponses", "asynctest"] |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 34 | |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 35 | BLACK_VERSION = "black==19.3b0" |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 36 | BLACK_PATHS = [ |
| 37 | "google", |
| 38 | "tests", |
| 39 | "tests_async", |
| 40 | "noxfile.py", |
| 41 | "setup.py", |
| 42 | "docs/conf.py", |
| 43 | ] |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 44 | |
| 45 | |
| 46 | @nox.session(python="3.7") |
| 47 | def lint(session): |
| 48 | session.install("flake8", "flake8-import-order", "docutils", BLACK_VERSION) |
| 49 | session.install(".") |
| 50 | session.run("black", "--check", *BLACK_PATHS) |
| 51 | session.run( |
| 52 | "flake8", |
| 53 | "--import-order-style=google", |
| 54 | "--application-import-names=google,tests,system_tests", |
| 55 | "google", |
| 56 | "tests", |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 57 | "tests_async", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 58 | ) |
| 59 | session.run( |
| 60 | "python", "setup.py", "check", "--metadata", "--restructuredtext", "--strict" |
| 61 | ) |
| 62 | |
| 63 | |
| 64 | @nox.session(python="3.6") |
| 65 | def blacken(session): |
| 66 | """Run black. |
| 67 | |
| 68 | Format code to uniform standard. |
| 69 | |
| 70 | This currently uses Python 3.6 due to the automated Kokoro run of synthtool. |
| 71 | That run uses an image that doesn't have 3.6 installed. Before updating this |
| 72 | check the state of the `gcp_ubuntu_config` we use for that Kokoro run. |
| 73 | """ |
| 74 | session.install(BLACK_VERSION) |
| 75 | session.run("black", *BLACK_PATHS) |
| 76 | |
| 77 | |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 78 | @nox.session(python=["3.6", "3.7", "3.8"]) |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 79 | def unit(session): |
| 80 | session.install(*TEST_DEPENDENCIES) |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 81 | session.install(*(ASYNC_DEPENDENCIES)) |
| 82 | session.install(".") |
| 83 | session.run( |
| 84 | "pytest", |
| 85 | "--cov=google.auth", |
| 86 | "--cov=google.oauth2", |
| 87 | "--cov=tests", |
| 88 | "tests", |
| 89 | "tests_async", |
| 90 | ) |
| 91 | |
| 92 | |
| 93 | @nox.session(python=["2.7", "3.5"]) |
| 94 | def unit_prev_versions(session): |
| 95 | session.install(*TEST_DEPENDENCIES) |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 96 | session.install(".") |
| 97 | session.run( |
| 98 | "pytest", "--cov=google.auth", "--cov=google.oauth2", "--cov=tests", "tests" |
| 99 | ) |
| 100 | |
| 101 | |
| 102 | @nox.session(python="3.7") |
| 103 | def cover(session): |
| 104 | session.install(*TEST_DEPENDENCIES) |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 105 | session.install(*(ASYNC_DEPENDENCIES)) |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 106 | session.install(".") |
| 107 | session.run( |
| 108 | "pytest", |
| 109 | "--cov=google.auth", |
| 110 | "--cov=google.oauth2", |
| 111 | "--cov=tests", |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 112 | "--cov=tests_async", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 113 | "--cov-report=", |
| 114 | "tests", |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 115 | "tests_async", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 116 | ) |
| 117 | session.run("coverage", "report", "--show-missing", "--fail-under=100") |
| 118 | |
| 119 | |
| 120 | @nox.session(python="3.7") |
| 121 | def docgen(session): |
| 122 | session.env["SPHINX_APIDOC_OPTIONS"] = "members,inherited-members,show-inheritance" |
| 123 | session.install(*TEST_DEPENDENCIES) |
| 124 | session.install("sphinx") |
| 125 | session.install(".") |
| 126 | session.run("rm", "-r", "docs/reference") |
| 127 | session.run( |
| 128 | "sphinx-apidoc", |
| 129 | "--output-dir", |
| 130 | "docs/reference", |
| 131 | "--separate", |
| 132 | "--module-first", |
| 133 | "google", |
| 134 | ) |
| 135 | |
| 136 | |
| 137 | @nox.session(python="3.7") |
| 138 | def docs(session): |
| 139 | session.install("sphinx", "-r", "docs/requirements-docs.txt") |
| 140 | session.install(".") |
| 141 | session.run("make", "-C", "docs", "html") |
| 142 | |
| 143 | |
| 144 | @nox.session(python="pypy") |
| 145 | def pypy(session): |
| 146 | session.install(*TEST_DEPENDENCIES) |
Tres Seaver | 3b3172e | 2020-10-22 16:05:20 -0400 | [diff] [blame] | 147 | session.install(*ASYNC_DEPENDENCIES) |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 148 | session.install(".") |
| 149 | session.run( |
Christopher Wilcox | 7e15258 | 2020-09-28 15:27:20 -0700 | [diff] [blame] | 150 | "pytest", |
| 151 | "--cov=google.auth", |
| 152 | "--cov=google.oauth2", |
| 153 | "--cov=tests", |
| 154 | "tests", |
| 155 | "tests_async", |
Bu Sun Kim | 65e33c0 | 2019-10-25 10:45:00 -0700 | [diff] [blame] | 156 | ) |