blob: 77ef2cec9327a00b005fa9087b07dbe76a79ac8c [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
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
Bu Sun Kim9f45e3c2018-10-10 11:04:44 -070054@nox.session(python=['2.7', '3.5', '3.6', '3.7'])
55def unit(session):
Danny Hermesfd1d18f2017-11-01 21:47:55 -070056 """Run the unit test suite."""
Danny Hermesfd1d18f2017-11-01 21:47:55 -070057 default(session)
58
59
Bu Sun Kim9f45e3c2018-10-10 11:04:44 -070060@nox.session(python=['2.7', '3.5', '3.6', '3.7'])
61def unit_grpc_gcp(session):
Weiran Fang0a5c85c2018-07-27 11:30:48 -070062 """Run the unit test suite with grpcio-gcp installed."""
63
Weiran Fang0a5c85c2018-07-27 11:30:48 -070064 # Install grpcio-gcp
65 session.install('grpcio-gcp')
66
67 default(session)
68
69
Bu Sun Kim9f45e3c2018-10-10 11:04:44 -070070@nox.session(python='3.6')
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070071def 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 Parrott77fb0f22017-10-18 12:52:35 -070077 session.install('flake8', 'flake8-import-order')
78 session.install('.')
79 session.run('flake8', 'google', 'tests')
80
81
Bu Sun Kim9f45e3c2018-10-10 11:04:44 -070082@nox.session(python='3.6')
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070083def lint_setup_py(session):
84 """Verify that setup.py is valid (including RST check)."""
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070085
86 session.install('docutils', 'Pygments')
87 session.run(
88 'python', 'setup.py', 'check', '--restructuredtext', '--strict')
89
90
Rebecca Chen0fce6372018-09-27 10:45:58 -070091# 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 Kim9f45e3c2018-10-10 11:04:44 -070093@nox.session(python='3.6')
Rebecca Chen0fce6372018-09-27 10:45:58 -070094def pytype(session):
95 """Run type-checking."""
Rebecca Chen0fce6372018-09-27 10:45:58 -070096 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 Kim9f45e3c2018-10-10 11:04:44 -0700103@nox.session(python='3.6')
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -0700104def 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 Parrott77fb0f22017-10-18 12:52:35 -0700110 session.install('coverage', 'pytest-cov')
111 session.run('coverage', 'report', '--show-missing', '--fail-under=100')
112 session.run('coverage', 'erase')