blob: dacfbb53e74db5fba1fb5456856f42006d43135a [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
18import nox
19
20
21@nox.session
Danny Hermesfd1d18f2017-11-01 21:47:55 -070022def default(session):
23 """Default unit test session.
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070024
Danny Hermesfd1d18f2017-11-01 21:47:55 -070025 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 Parrott77fb0f22017-10-18 12:52:35 -070030 # 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 Parrott77fb0f22017-10-18 12:52:35 -070043 '--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
Christopher Wilcoxb7a522b2018-05-04 09:01:24 -070055@nox.parametrize('py', ['2.7', '3.5', '3.6', '3.7'])
Danny Hermesfd1d18f2017-11-01 21:47:55 -070056def 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
Weiran Fang0a5c85c2018-07-27 11:30:48 -070069@nox.parametrize('py', ['2.7', '3.5', '3.6', '3.7'])
70def unit_grpc_gcp(session, py):
71 """Run the unit test suite with grpcio-gcp installed."""
72
73 # Run unit tests against all supported versions of Python.
74 session.interpreter = 'python{}'.format(py)
75
76 # Set the virtualenv dirname.
77 session.virtualenv_dirname = 'unit-grpc-gcp-' + py
78
79 # Install grpcio-gcp
80 session.install('grpcio-gcp')
81
82 default(session)
83
84
85@nox.session
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070086def lint(session):
87 """Run linters.
88
89 Returns a failure if the linters find linting errors or sufficiently
90 serious code quality issues.
91 """
92 session.interpreter = 'python3.6'
93 session.install('flake8', 'flake8-import-order')
94 session.install('.')
95 session.run('flake8', 'google', 'tests')
96
97
98@nox.session
99def lint_setup_py(session):
100 """Verify that setup.py is valid (including RST check)."""
101 session.interpreter = 'python3.6'
102
103 # Set the virtualenv dirname.
104 session.virtualenv_dirname = 'setup'
105
106 session.install('docutils', 'Pygments')
107 session.run(
108 'python', 'setup.py', 'check', '--restructuredtext', '--strict')
109
110
111@nox.session
112def cover(session):
113 """Run the final coverage report.
114
115 This outputs the coverage report aggregating coverage from the unit
116 test runs (not system test runs), and then erases coverage data.
117 """
118 session.interpreter = 'python3.6'
119 session.install('coverage', 'pytest-cov')
120 session.run('coverage', 'report', '--show-missing', '--fail-under=100')
121 session.run('coverage', 'erase')