blob: 7d14ad9befb1d7ab0e3c3c33ebee6a0f4bb12f54 [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
17
Rebecca Chen0fce6372018-09-27 10:45:58 -070018# https://github.com/google/importlab/issues/25
19import nox # pytype: disable=import-error
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070020
21
22@nox.session
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.
32 session.install(
33 'mock',
34 'pytest',
35 'pytest-cov',
36 'grpcio >= 1.0.2',
37 )
38 session.install('-e', '.')
39
40 # Run py.test against the unit tests.
41 session.run(
42 'py.test',
43 '--quiet',
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070044 '--cov=google.api_core',
45 '--cov=tests.unit',
46 '--cov-append',
47 '--cov-config=.coveragerc',
48 '--cov-report=',
49 '--cov-fail-under=97',
50 os.path.join('tests', 'unit'),
51 *session.posargs
52 )
53
54
55@nox.session
Christopher Wilcoxb7a522b2018-05-04 09:01:24 -070056@nox.parametrize('py', ['2.7', '3.5', '3.6', '3.7'])
Danny Hermesfd1d18f2017-11-01 21:47:55 -070057def unit(session, py):
58 """Run the unit test suite."""
59
60 # Run unit tests against all supported versions of Python.
61 session.interpreter = 'python{}'.format(py)
62
63 # Set the virtualenv dirname.
64 session.virtualenv_dirname = 'unit-' + py
65
66 default(session)
67
68
69@nox.session
Weiran Fang0a5c85c2018-07-27 11:30:48 -070070@nox.parametrize('py', ['2.7', '3.5', '3.6', '3.7'])
71def unit_grpc_gcp(session, py):
72 """Run the unit test suite with grpcio-gcp installed."""
73
74 # Run unit tests against all supported versions of Python.
75 session.interpreter = 'python{}'.format(py)
76
77 # Set the virtualenv dirname.
78 session.virtualenv_dirname = 'unit-grpc-gcp-' + py
79
80 # Install grpcio-gcp
81 session.install('grpcio-gcp')
82
83 default(session)
84
85
86@nox.session
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070087def lint(session):
88 """Run linters.
89
90 Returns a failure if the linters find linting errors or sufficiently
91 serious code quality issues.
92 """
93 session.interpreter = 'python3.6'
94 session.install('flake8', 'flake8-import-order')
95 session.install('.')
96 session.run('flake8', 'google', 'tests')
97
98
99@nox.session
100def lint_setup_py(session):
101 """Verify that setup.py is valid (including RST check)."""
102 session.interpreter = 'python3.6'
103
104 # Set the virtualenv dirname.
105 session.virtualenv_dirname = 'setup'
106
107 session.install('docutils', 'Pygments')
108 session.run(
109 'python', 'setup.py', 'check', '--restructuredtext', '--strict')
110
111
Rebecca Chen0fce6372018-09-27 10:45:58 -0700112# No 2.7 due to https://github.com/google/importlab/issues/26.
113# No 3.7 because pytype supports up to 3.6 only.
114@nox.session
115def pytype(session):
116 """Run type-checking."""
117 session.interpreter = 'python3.6'
118 session.install('.',
119 'grpcio >= 1.8.2',
120 'grpcio-gcp >= 0.2.2',
121 'pytype >= 2018.9.26')
122 session.run('pytype')
123
124
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -0700125@nox.session
126def cover(session):
127 """Run the final coverage report.
128
129 This outputs the coverage report aggregating coverage from the unit
130 test runs (not system test runs), and then erases coverage data.
131 """
132 session.interpreter = 'python3.6'
133 session.install('coverage', 'pytest-cov')
134 session.run('coverage', 'report', '--show-missing', '--fail-under=100')
135 session.run('coverage', 'erase')