blob: fbc51ee4c425eb5c9e55686197ae170120215108 [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.
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080031 session.install("mock", "pytest", "pytest-cov", "grpcio >= 1.0.2")
32 session.install("-e", ".")
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070033
34 # Run py.test against the unit tests.
35 session.run(
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080036 "py.test",
37 "--quiet",
38 "--cov=google.api_core",
39 "--cov=tests.unit",
40 "--cov-append",
41 "--cov-config=.coveragerc",
42 "--cov-report=",
43 "--cov-fail-under=97",
44 os.path.join("tests", "unit"),
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070045 *session.posargs
46 )
47
48
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080049@nox.session(python=["2.7", "3.5", "3.6", "3.7"])
Bu Sun Kim9f45e3c2018-10-10 11:04:44 -070050def unit(session):
Danny Hermesfd1d18f2017-11-01 21:47:55 -070051 """Run the unit test suite."""
Danny Hermesfd1d18f2017-11-01 21:47:55 -070052 default(session)
53
54
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080055@nox.session(python=["2.7", "3.5", "3.6", "3.7"])
Bu Sun Kim9f45e3c2018-10-10 11:04:44 -070056def unit_grpc_gcp(session):
Weiran Fang0a5c85c2018-07-27 11:30:48 -070057 """Run the unit test suite with grpcio-gcp installed."""
58
Weiran Fang0a5c85c2018-07-27 11:30:48 -070059 # Install grpcio-gcp
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080060 session.install("grpcio-gcp")
Weiran Fang0a5c85c2018-07-27 11:30:48 -070061
62 default(session)
63
64
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080065@nox.session(python="3.6")
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070066def lint(session):
67 """Run linters.
68
69 Returns a failure if the linters find linting errors or sufficiently
70 serious code quality issues.
71 """
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080072 session.install("flake8", "flake8-import-order")
73 session.install(".")
74 session.run("flake8", "google", "tests")
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070075
76
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080077@nox.session(python="3.6")
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070078def lint_setup_py(session):
79 """Verify that setup.py is valid (including RST check)."""
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070080
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080081 session.install("docutils", "Pygments")
82 session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070083
84
Rebecca Chen0fce6372018-09-27 10:45:58 -070085# No 2.7 due to https://github.com/google/importlab/issues/26.
86# No 3.7 because pytype supports up to 3.6 only.
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080087@nox.session(python="3.6")
Rebecca Chen0fce6372018-09-27 10:45:58 -070088def pytype(session):
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080089 """Run type-checking."""
90 session.install(
91 ".", "grpcio >= 1.8.2", "grpcio-gcp >= 0.2.2", "pytype >= 2018.9.26"
92 )
93 session.run("pytype")
Rebecca Chen0fce6372018-09-27 10:45:58 -070094
95
Christopher Wilcox6f4070d2018-11-29 11:02:52 -080096@nox.session(python="3.6")
Jon Wayne Parrott77fb0f22017-10-18 12:52:35 -070097def cover(session):
98 """Run the final coverage report.
99
100 This outputs the coverage report aggregating coverage from the unit
101 test runs (not system test runs), and then erases coverage data.
102 """
Christopher Wilcox6f4070d2018-11-29 11:02:52 -0800103 session.install("coverage", "pytest-cov")
104 session.run("coverage", "report", "--show-missing", "--fail-under=100")
105 session.run("coverage", "erase")