|
1 | | -# Copyright 2016 Google LLC |
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright 2018 Google LLC |
2 | 4 | # |
3 | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 6 | # you may not use this file except in compliance with the License. |
5 | 7 | # You may obtain a copy of the License at |
6 | 8 | # |
7 | | -# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# https://www.apache.org/licenses/LICENSE-2.0 |
8 | 10 | # |
9 | 11 | # Unless required by applicable law or agreed to in writing, software |
10 | 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | 15 | # limitations under the License. |
14 | 16 |
|
15 | 17 | from __future__ import absolute_import |
16 | | - |
17 | 18 | import os |
18 | 19 |
|
19 | 20 | import nox |
20 | 21 |
|
21 | 22 |
|
22 | | -LOCAL_DEPS = ( |
23 | | - os.path.join('..', 'api_core'), |
24 | | - os.path.join('..', 'core'), |
25 | | -) |
| 23 | +LOCAL_DEPS = (os.path.join("..", "api_core"), os.path.join("..", "core")) |
26 | 24 |
|
| 25 | +@nox.session(python="3.7") |
| 26 | +def blacken(session): |
| 27 | + """Run black. |
27 | 28 |
|
28 | | -def default(session): |
29 | | - """Default unit test session. |
| 29 | + Format code to uniform standard. |
| 30 | + """ |
| 31 | + session.install("black") |
| 32 | + session.run( |
| 33 | + "black", |
| 34 | + "google", |
| 35 | + "tests", |
| 36 | + "docs", |
| 37 | + "--exclude", |
| 38 | + ".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py", |
| 39 | + ) |
| 40 | + |
| 41 | + |
| 42 | +@nox.session(python="3.7") |
| 43 | +def lint(session): |
| 44 | + """Run linters. |
30 | 45 |
|
31 | | - This is intended to be run **without** an interpreter set, so |
32 | | - that the current ``python`` (on the ``PATH``) or the version of |
33 | | - Python corresponding to the ``nox`` binary the ``PATH`` can |
34 | | - run the tests. |
| 46 | + Returns a failure if the linters find linting errors or sufficiently |
| 47 | + serious code quality issues. |
35 | 48 | """ |
36 | | - # Install all test dependencies, then install local packages in-place. |
37 | | - session.install('mock', 'pytest', 'pytest-cov') |
| 49 | + session.install("flake8", "black", *LOCAL_DEPS) |
| 50 | + session.run( |
| 51 | + "black", |
| 52 | + "--check", |
| 53 | + "google", |
| 54 | + "tests", |
| 55 | + "docs", |
| 56 | + "--exclude", |
| 57 | + ".*/proto/.*|.*/gapic/.*|.*/.*_pb2.py", |
| 58 | + ) |
| 59 | + session.run("flake8", "google", "tests") |
| 60 | + |
| 61 | + |
| 62 | +@nox.session(python="3.7") |
| 63 | +def lint_setup_py(session): |
| 64 | + """Verify that setup.py is valid (including RST check).""" |
| 65 | + session.install("docutils", "pygments") |
| 66 | + session.run("python", "setup.py", "check", "--restructuredtext", "--strict") |
| 67 | + |
| 68 | + |
| 69 | +def default(session): |
| 70 | + # Install all test dependencies, then install this package in-place. |
| 71 | + session.install("mock", "pytest", "pytest-cov") |
38 | 72 | for local_dep in LOCAL_DEPS: |
39 | | - session.install('-e', local_dep) |
40 | | - session.install('-e', '.') |
| 73 | + session.install("-e", local_dep) |
| 74 | + session.install("-e", ".") |
41 | 75 |
|
42 | 76 | # Run py.test against the unit tests. |
43 | 77 | session.run( |
44 | | - 'py.test', '--quiet', |
45 | | - '--cov=google.cloud.language_v1', |
46 | | - '--cov=google.cloud.language_v1beta2', |
47 | | - '--cov-append', |
48 | | - '--cov-config=.coveragerc', |
49 | | - '--cov-report=', |
50 | | - '--cov-fail-under=97', |
51 | | - 'tests/unit', |
52 | | - *session.posargs |
| 78 | + "py.test", |
| 79 | + "--quiet", |
| 80 | + "--cov=google.cloud", |
| 81 | + "--cov=tests.unit", |
| 82 | + "--cov-append", |
| 83 | + "--cov-config=.coveragerc", |
| 84 | + "--cov-report=", |
| 85 | + "--cov-fail-under=97", |
| 86 | + os.path.join("tests", "unit"), |
| 87 | + *session.posargs, |
53 | 88 | ) |
54 | 89 |
|
55 | 90 |
|
56 | | -@nox.session(python=['2.7', '3.5', '3.6', '3.7']) |
| 91 | +@nox.session(python=["2.7", "3.5", "3.6", "3.7"]) |
57 | 92 | def unit(session): |
58 | 93 | """Run the unit test suite.""" |
59 | 94 | default(session) |
60 | 95 |
|
61 | 96 |
|
62 | | -@nox.session(python=['2.7', '3.6']) |
| 97 | +@nox.session(python=["2.7", "3.7"]) |
63 | 98 | def system(session): |
64 | 99 | """Run the system test suite.""" |
65 | | - |
66 | | - # Sanity check: Only run system tests if the environment variable is set. |
67 | | - if not os.environ.get('GOOGLE_APPLICATION_CREDENTIALS', ''): |
68 | | - session.skip('Credentials must be set via environment variable.') |
| 100 | + system_test_path = os.path.join("tests", "system.py") |
| 101 | + system_test_folder_path = os.path.join("tests", "system") |
| 102 | + # Sanity check: Only run tests if the environment variable is set. |
| 103 | + if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", ""): |
| 104 | + session.skip("Credentials must be set via environment variable") |
| 105 | + |
| 106 | + system_test_exists = os.path.exists(system_test_path) |
| 107 | + system_test_folder_exists = os.path.exists(system_test_folder_path) |
| 108 | + # Sanity check: only run tests if found. |
| 109 | + if not system_test_exists and not system_test_folder_exists: |
| 110 | + session.skip("System tests were not found") |
69 | 111 |
|
70 | 112 | # Use pre-release gRPC for system tests. |
71 | | - session.install('--pre', 'grpcio') |
| 113 | + session.install("--pre", "grpcio") |
72 | 114 |
|
73 | | - # Install all test dependencies, then install local packages in-place. |
74 | | - session.install('mock', 'pytest') |
| 115 | + # Install all test dependencies, then install this package into the |
| 116 | + # virtualenv's dist-packages. |
| 117 | + session.install("mock", "pytest") |
75 | 118 | for local_dep in LOCAL_DEPS: |
76 | | - session.install('-e', local_dep) |
77 | | - session.install('-e', '../storage/') |
78 | | - session.install('-e', '../test_utils/') |
79 | | - session.install('-e', '.') |
| 119 | + session.install("-e", local_dep) |
| 120 | + session.install("-e", "../test_utils/") |
| 121 | + session.install("-e", ".") |
80 | 122 |
|
81 | 123 | # Run py.test against the system tests. |
82 | | - session.run('py.test', '--quiet', 'tests/system/') |
83 | | - |
84 | | - |
85 | | -@nox.session(python='3.6') |
86 | | -def 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.install('flake8', *LOCAL_DEPS) |
93 | | - session.install('.') |
94 | | - session.run('flake8', 'google', 'tests') |
| 124 | + if system_test_exists: |
| 125 | + session.run("py.test", "--quiet", system_test_path, *session.posargs) |
| 126 | + if system_test_folder_exists: |
| 127 | + session.run("py.test", "--quiet", system_test_folder_path, *session.posargs) |
95 | 128 |
|
96 | 129 |
|
97 | | -@nox.session(python='3.6') |
98 | | -def lint_setup_py(session): |
99 | | - """Verify that setup.py is valid (including RST check).""" |
100 | | - session.install('docutils', 'Pygments') |
101 | | - session.run( |
102 | | - 'python', 'setup.py', 'check', '--restructuredtext', '--strict') |
103 | | - |
104 | | - |
105 | | -@nox.session(python='3.6') |
| 130 | +@nox.session(python="3.7") |
106 | 131 | def cover(session): |
107 | 132 | """Run the final coverage report. |
108 | 133 |
|
109 | 134 | This outputs the coverage report aggregating coverage from the unit |
110 | 135 | test runs (not system test runs), and then erases coverage data. |
111 | 136 | """ |
112 | | - session.install('coverage', 'pytest-cov') |
113 | | - session.run('coverage', 'report', '--show-missing', '--fail-under=100') |
114 | | - session.run('coverage', 'erase') |
| 137 | + session.install("coverage", "pytest-cov") |
| 138 | + session.run("coverage", "report", "--show-missing", "--fail-under=100") |
| 139 | + |
| 140 | + session.run("coverage", "erase") |
0 commit comments