blob: 35c314d80aa856cea0d98be3298e873273ed9b33 [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
22@nox.parametrize('python_version', ['2.7', '3.4', '3.5', '3.6'])
23def unit_tests(session, python_version):
24 """Run the unit test suite."""
25
26 # Run unit tests against all supported versions of Python.
27 session.interpreter = 'python{}'.format(python_version)
28
29 # Set the virtualenv dirname.
30 session.virtualenv_dirname = 'unit-' + python_version
31
32 # Install all test dependencies, then install this package in-place.
33 session.install(
34 'mock',
35 'pytest',
36 'pytest-cov',
37 'grpcio >= 1.0.2',
38 )
39 session.install('-e', '.')
40
41 # Run py.test against the unit tests.
42 session.run(
43 'py.test',
44 '--quiet',
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070045 '--cov=google.api_core',
46 '--cov=tests.unit',
47 '--cov-append',
48 '--cov-config=.coveragerc',
49 '--cov-report=',
50 '--cov-fail-under=97',
51 os.path.join('tests', 'unit'),
52 *session.posargs
53 )
54
55
56@nox.session
57def lint(session):
58 """Run linters.
59
60 Returns a failure if the linters find linting errors or sufficiently
61 serious code quality issues.
62 """
63 session.interpreter = 'python3.6'
64 session.install('flake8', 'flake8-import-order')
65 session.install('.')
66 session.run('flake8', 'google', 'tests')
67
68
69@nox.session
70def lint_setup_py(session):
71 """Verify that setup.py is valid (including RST check)."""
72 session.interpreter = 'python3.6'
73
74 # Set the virtualenv dirname.
75 session.virtualenv_dirname = 'setup'
76
77 session.install('docutils', 'Pygments')
78 session.run(
79 'python', 'setup.py', 'check', '--restructuredtext', '--strict')
80
81
82@nox.session
83def cover(session):
84 """Run the final coverage report.
85
86 This outputs the coverage report aggregating coverage from the unit
87 test runs (not system test runs), and then erases coverage data.
88 """
89 session.interpreter = 'python3.6'
90 session.install('coverage', 'pytest-cov')
91 session.run('coverage', 'report', '--show-missing', '--fail-under=100')
92 session.run('coverage', 'erase')