|
1 | | -# Copyright 2017 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 | | -import nox.command |
21 | 21 |
|
22 | 22 |
|
23 | | -LOCAL_DEPS = ( |
24 | | - os.path.join('..', 'api_core'), |
25 | | - os.path.join('..', 'core'), |
26 | | -) |
| 23 | +LOCAL_DEPS = (os.path.join("..", "api_core"), os.path.join("..", "core")) |
27 | 24 |
|
| 25 | +@nox.session(python="3.7") |
| 26 | +def blacken(session): |
| 27 | + """Run black. |
28 | 28 |
|
29 | | -def default(session): |
30 | | - """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. |
31 | 45 |
|
32 | | - This is intended to be run **without** an interpreter set, so |
33 | | - that the current ``python`` (on the ``PATH``) or the version of |
34 | | - Python corresponding to the ``nox`` binary the ``PATH`` can |
35 | | - run the tests. |
| 46 | + Returns a failure if the linters find linting errors or sufficiently |
| 47 | + serious code quality issues. |
36 | 48 | """ |
37 | | - # Install all test dependencies, then install local packages in-place. |
38 | | - 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") |
39 | 72 | for local_dep in LOCAL_DEPS: |
40 | | - session.install('-e', local_dep) |
41 | | - session.install('-e', '.') |
| 73 | + session.install("-e", local_dep) |
| 74 | + session.install("-e", ".") |
42 | 75 |
|
43 | 76 | # Run py.test against the unit tests. |
44 | 77 | session.run( |
45 | | - 'py.test', |
46 | | - '--quiet', |
47 | | - '--cov=google.cloud.firestore', |
48 | | - '--cov=google.cloud.firestore_v1beta1', |
49 | | - '--cov=tests.unit', |
50 | | - '--cov-append', |
51 | | - '--cov-config=.coveragerc', |
52 | | - '--cov-report=', |
53 | | - '--cov-fail-under=97', |
54 | | - os.path.join('tests', 'unit'), |
55 | | - *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, |
56 | 88 | ) |
57 | 89 |
|
58 | 90 |
|
59 | | -@nox.session(python=['2.7', '3.5', '3.6', '3.7']) |
| 91 | +@nox.session(python=["2.7", "3.5", "3.6", "3.7"]) |
60 | 92 | def unit(session): |
61 | 93 | """Run the unit test suite.""" |
62 | | - |
63 | 94 | default(session) |
64 | 95 |
|
65 | 96 |
|
66 | | -@nox.session(python=['2.7', '3.6']) |
| 97 | +@nox.session(python=["2.7", "3.7"]) |
67 | 98 | def system(session): |
68 | 99 | """Run the system test suite.""" |
69 | | - # Sanity check: Only run system tests if the environment variable is set. |
70 | | - if not os.environ.get('FIRESTORE_APPLICATION_CREDENTIALS'): |
71 | | - 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") |
72 | 111 |
|
73 | 112 | # Use pre-release gRPC for system tests. |
74 | | - session.install('--pre', 'grpcio') |
| 113 | + session.install("--pre", "grpcio") |
75 | 114 |
|
76 | | - # Install all test dependencies, then install local packages in-place. |
77 | | - 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") |
78 | 118 | for local_dep in LOCAL_DEPS: |
79 | | - session.install('-e', local_dep) |
80 | | - session.install('-e', os.path.join('..', 'test_utils')) |
81 | | - session.install('-e', '.') |
| 119 | + session.install("-e", local_dep) |
| 120 | + session.install("-e", "../test_utils/") |
| 121 | + session.install("-e", ".") |
82 | 122 |
|
83 | 123 | # Run py.test against the system tests. |
84 | | - session.run( |
85 | | - 'py.test', |
86 | | - os.path.join('tests', 'system.py'), |
87 | | - *session.posargs |
88 | | - ) |
| 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) |
89 | 128 |
|
90 | 129 |
|
91 | | -@nox.session(python='3.6') |
92 | | -def lint(session): |
93 | | - """Run linters. |
94 | | -
|
95 | | - Returns a failure if the linters find linting errors or sufficiently |
96 | | - serious code quality issues. |
97 | | - """ |
98 | | - session.install('flake8', *LOCAL_DEPS) |
99 | | - session.install('.') |
100 | | - session.run('flake8', 'google', 'tests') |
101 | | - |
102 | | - |
103 | | -@nox.session(python='3.6') |
104 | | -def lint_setup_py(session): |
105 | | - """Verify that setup.py is valid (including RST check).""" |
106 | | - session.install('docutils', 'Pygments') |
107 | | - session.run( |
108 | | - 'python', 'setup.py', 'check', '--restructuredtext', '--strict') |
109 | | - |
110 | | - |
111 | | -@nox.session(python='3.6') |
| 130 | +@nox.session(python="3.7") |
112 | 131 | def cover(session): |
113 | 132 | """Run the final coverage report. |
114 | 133 |
|
115 | 134 | This outputs the coverage report aggregating coverage from the unit |
116 | 135 | test runs (not system test runs), and then erases coverage data. |
117 | 136 | """ |
118 | | - session.chdir(os.path.dirname(__file__)) |
119 | | - session.install('coverage', 'pytest-cov') |
120 | | - session.run('coverage', 'report', '--show-missing', '--fail-under=100') |
121 | | - 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