blob: bb10c6c0655f2c99654133fa655fec245340d9b9 [file] [log] [blame]
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -07001# Copyright 2016 Google Inc.
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
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',
45 '--cov=google.cloud',
46 '--cov=google.api_core',
47 '--cov=tests.unit',
48 '--cov-append',
49 '--cov-config=.coveragerc',
50 '--cov-report=',
51 '--cov-fail-under=97',
52 os.path.join('tests', 'unit'),
53 *session.posargs
54 )
55
56
57@nox.session
58def lint(session):
59 """Run linters.
60
61 Returns a failure if the linters find linting errors or sufficiently
62 serious code quality issues.
63 """
64 session.interpreter = 'python3.6'
65 session.install('flake8', 'flake8-import-order')
66 session.install('.')
67 session.run('flake8', 'google', 'tests')
68
69
70@nox.session
71def lint_setup_py(session):
72 """Verify that setup.py is valid (including RST check)."""
73 session.interpreter = 'python3.6'
74
75 # Set the virtualenv dirname.
76 session.virtualenv_dirname = 'setup'
77
78 session.install('docutils', 'Pygments')
79 session.run(
80 'python', 'setup.py', 'check', '--restructuredtext', '--strict')
81
82
83@nox.session
84def cover(session):
85 """Run the final coverage report.
86
87 This outputs the coverage report aggregating coverage from the unit
88 test runs (not system test runs), and then erases coverage data.
89 """
90 session.interpreter = 'python3.6'
91 session.install('coverage', 'pytest-cov')
92 session.run('coverage', 'report', '--show-missing', '--fail-under=100')
93 session.run('coverage', 'erase')