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 |
| 17 | |
Rebecca Chen | 0fce637 | 2018-09-27 10:45:58 -0700 | [diff] [blame] | 18 | # https://github.com/google/importlab/issues/25 |
| 19 | import nox # pytype: disable=import-error |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 20 | |
| 21 | |
Danny Hermes | fd1d18f | 2017-11-01 21:47:55 -0700 | [diff] [blame] | 22 | def default(session): |
| 23 | """Default unit test session. |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 24 | |
Danny Hermes | fd1d18f | 2017-11-01 21:47:55 -0700 | [diff] [blame] | 25 | This is intended to be run **without** an interpreter set, so |
| 26 | that the current ``python`` (on the ``PATH``) or the version of |
| 27 | Python corresponding to the ``nox`` binary the ``PATH`` can |
| 28 | run the tests. |
| 29 | """ |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 30 | # Install all test dependencies, then install this package in-place. |
| 31 | session.install( |
| 32 | 'mock', |
| 33 | 'pytest', |
| 34 | 'pytest-cov', |
| 35 | 'grpcio >= 1.0.2', |
| 36 | ) |
| 37 | session.install('-e', '.') |
| 38 | |
| 39 | # Run py.test against the unit tests. |
| 40 | session.run( |
| 41 | 'py.test', |
| 42 | '--quiet', |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 43 | '--cov=google.api_core', |
| 44 | '--cov=tests.unit', |
| 45 | '--cov-append', |
| 46 | '--cov-config=.coveragerc', |
| 47 | '--cov-report=', |
| 48 | '--cov-fail-under=97', |
| 49 | os.path.join('tests', 'unit'), |
| 50 | *session.posargs |
| 51 | ) |
| 52 | |
| 53 | |
Bu Sun Kim | 9f45e3c | 2018-10-10 11:04:44 -0700 | [diff] [blame^] | 54 | @nox.session(python=['2.7', '3.5', '3.6', '3.7']) |
| 55 | def unit(session): |
Danny Hermes | fd1d18f | 2017-11-01 21:47:55 -0700 | [diff] [blame] | 56 | """Run the unit test suite.""" |
Danny Hermes | fd1d18f | 2017-11-01 21:47:55 -0700 | [diff] [blame] | 57 | default(session) |
| 58 | |
| 59 | |
Bu Sun Kim | 9f45e3c | 2018-10-10 11:04:44 -0700 | [diff] [blame^] | 60 | @nox.session(python=['2.7', '3.5', '3.6', '3.7']) |
| 61 | def unit_grpc_gcp(session): |
Weiran Fang | 0a5c85c | 2018-07-27 11:30:48 -0700 | [diff] [blame] | 62 | """Run the unit test suite with grpcio-gcp installed.""" |
| 63 | |
Weiran Fang | 0a5c85c | 2018-07-27 11:30:48 -0700 | [diff] [blame] | 64 | # Install grpcio-gcp |
| 65 | session.install('grpcio-gcp') |
| 66 | |
| 67 | default(session) |
| 68 | |
| 69 | |
Bu Sun Kim | 9f45e3c | 2018-10-10 11:04:44 -0700 | [diff] [blame^] | 70 | @nox.session(python='3.6') |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 71 | def lint(session): |
| 72 | """Run linters. |
| 73 | |
| 74 | Returns a failure if the linters find linting errors or sufficiently |
| 75 | serious code quality issues. |
| 76 | """ |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 77 | session.install('flake8', 'flake8-import-order') |
| 78 | session.install('.') |
| 79 | session.run('flake8', 'google', 'tests') |
| 80 | |
| 81 | |
Bu Sun Kim | 9f45e3c | 2018-10-10 11:04:44 -0700 | [diff] [blame^] | 82 | @nox.session(python='3.6') |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 83 | def lint_setup_py(session): |
| 84 | """Verify that setup.py is valid (including RST check).""" |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 85 | |
| 86 | session.install('docutils', 'Pygments') |
| 87 | session.run( |
| 88 | 'python', 'setup.py', 'check', '--restructuredtext', '--strict') |
| 89 | |
| 90 | |
Rebecca Chen | 0fce637 | 2018-09-27 10:45:58 -0700 | [diff] [blame] | 91 | # No 2.7 due to https://github.com/google/importlab/issues/26. |
| 92 | # No 3.7 because pytype supports up to 3.6 only. |
Bu Sun Kim | 9f45e3c | 2018-10-10 11:04:44 -0700 | [diff] [blame^] | 93 | @nox.session(python='3.6') |
Rebecca Chen | 0fce637 | 2018-09-27 10:45:58 -0700 | [diff] [blame] | 94 | def pytype(session): |
| 95 | """Run type-checking.""" |
Rebecca Chen | 0fce637 | 2018-09-27 10:45:58 -0700 | [diff] [blame] | 96 | session.install('.', |
| 97 | 'grpcio >= 1.8.2', |
| 98 | 'grpcio-gcp >= 0.2.2', |
| 99 | 'pytype >= 2018.9.26') |
| 100 | session.run('pytype') |
| 101 | |
| 102 | |
Bu Sun Kim | 9f45e3c | 2018-10-10 11:04:44 -0700 | [diff] [blame^] | 103 | @nox.session(python='3.6') |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 104 | def cover(session): |
| 105 | """Run the final coverage report. |
| 106 | |
| 107 | This outputs the coverage report aggregating coverage from the unit |
| 108 | test runs (not system test runs), and then erases coverage data. |
| 109 | """ |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 110 | session.install('coverage', 'pytest-cov') |
| 111 | session.run('coverage', 'report', '--show-missing', '--fail-under=100') |
| 112 | session.run('coverage', 'erase') |