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 | |
| 18 | import nox |
| 19 | |
| 20 | |
| 21 | @nox.session |
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 | |
| 54 | @nox.session |
Danny Hermes | fd1d18f | 2017-11-01 21:47:55 -0700 | [diff] [blame^] | 55 | @nox.parametrize('py', ['2.7', '3.4', '3.5', '3.6']) |
| 56 | def unit(session, py): |
| 57 | """Run the unit test suite.""" |
| 58 | |
| 59 | # Run unit tests against all supported versions of Python. |
| 60 | session.interpreter = 'python{}'.format(py) |
| 61 | |
| 62 | # Set the virtualenv dirname. |
| 63 | session.virtualenv_dirname = 'unit-' + py |
| 64 | |
| 65 | default(session) |
| 66 | |
| 67 | |
| 68 | @nox.session |
Jon Wayne Parrott | 77fb0f2 | 2017-10-18 12:52:35 -0700 | [diff] [blame] | 69 | def lint(session): |
| 70 | """Run linters. |
| 71 | |
| 72 | Returns a failure if the linters find linting errors or sufficiently |
| 73 | serious code quality issues. |
| 74 | """ |
| 75 | session.interpreter = 'python3.6' |
| 76 | session.install('flake8', 'flake8-import-order') |
| 77 | session.install('.') |
| 78 | session.run('flake8', 'google', 'tests') |
| 79 | |
| 80 | |
| 81 | @nox.session |
| 82 | def lint_setup_py(session): |
| 83 | """Verify that setup.py is valid (including RST check).""" |
| 84 | session.interpreter = 'python3.6' |
| 85 | |
| 86 | # Set the virtualenv dirname. |
| 87 | session.virtualenv_dirname = 'setup' |
| 88 | |
| 89 | session.install('docutils', 'Pygments') |
| 90 | session.run( |
| 91 | 'python', 'setup.py', 'check', '--restructuredtext', '--strict') |
| 92 | |
| 93 | |
| 94 | @nox.session |
| 95 | def cover(session): |
| 96 | """Run the final coverage report. |
| 97 | |
| 98 | This outputs the coverage report aggregating coverage from the unit |
| 99 | test runs (not system test runs), and then erases coverage data. |
| 100 | """ |
| 101 | session.interpreter = 'python3.6' |
| 102 | session.install('coverage', 'pytest-cov') |
| 103 | session.run('coverage', 'report', '--show-missing', '--fail-under=100') |
| 104 | session.run('coverage', 'erase') |