diff options
| author | Gavin Mak <gavinmak@google.com> | 2023-03-30 05:06:01 +0000 |
|---|---|---|
| committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-31 04:25:53 +0000 |
| commit | 57cb42861d37eec074a729f33d1c5aa90be86b3f (patch) | |
| tree | a78a1a00714f3c1e484266a5870285b56331bee7 | |
| parent | e74d9046eeec52d7ccd433a4dad2cee30838c620 (diff) | |
| download | git-repo-57cb42861d37eec074a729f33d1c5aa90be86b3f.tar.gz | |
run_tests: Check flake8
This also gets enforced in CQ.
Bug: b/267675342
Change-Id: I8ffcc5d583275072fd61ae65ae4214b36bfa59f3
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/366799
Tested-by: Gavin Mak <gavinmak@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
| -rwxr-xr-x | run_tests | 26 | ||||
| -rw-r--r-- | run_tests.vpython3 | 23 | ||||
| -rw-r--r-- | tox.ini | 1 |
3 files changed, 43 insertions, 7 deletions
| @@ -13,7 +13,7 @@ | |||
| 13 | # See the License for the specific language governing permissions and | 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. | 14 | # limitations under the License. |
| 15 | 15 | ||
| 16 | """Wrapper to run black and pytest with the right settings.""" | 16 | """Wrapper to run linters and pytest with the right settings.""" |
| 17 | 17 | ||
| 18 | import os | 18 | import os |
| 19 | import subprocess | 19 | import subprocess |
| @@ -21,19 +21,31 @@ import sys | |||
| 21 | import pytest | 21 | import pytest |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | ROOT_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
| 25 | |||
| 26 | |||
| 24 | def run_black(): | 27 | def run_black(): |
| 25 | """Returns the exit code of running `black --check`.""" | 28 | """Returns the exit code from black.""" |
| 26 | dirpath = os.path.dirname(os.path.realpath(__file__)) | 29 | return subprocess.run( |
| 30 | [sys.executable, "-m", "black", "--check", ROOT_DIR], check=False | ||
| 31 | ).returncode | ||
| 32 | |||
| 33 | |||
| 34 | def run_flake8(): | ||
| 35 | """Returns the exit code from flake8.""" | ||
| 27 | return subprocess.run( | 36 | return subprocess.run( |
| 28 | [sys.executable, "-m", "black", "--check", dirpath], check=False | 37 | [sys.executable, "-m", "flake8", ROOT_DIR], check=False |
| 29 | ).returncode | 38 | ).returncode |
| 30 | 39 | ||
| 31 | 40 | ||
| 32 | def main(argv): | 41 | def main(argv): |
| 33 | """The main entry.""" | 42 | """The main entry.""" |
| 34 | pytest_ret = pytest.main(argv) | 43 | checks = ( |
| 35 | black_ret = run_black() | 44 | lambda: pytest.main(argv), |
| 36 | return 0 if not black_ret and not pytest_ret else 1 | 45 | run_black, |
| 46 | run_flake8, | ||
| 47 | ) | ||
| 48 | return 0 if all(not c() for c in checks) else 1 | ||
| 37 | 49 | ||
| 38 | 50 | ||
| 39 | if __name__ == "__main__": | 51 | if __name__ == "__main__": |
diff --git a/run_tests.vpython3 b/run_tests.vpython3 index 0c790bca..3d0cd78e 100644 --- a/run_tests.vpython3 +++ b/run_tests.vpython3 | |||
| @@ -100,3 +100,26 @@ wheel: < | |||
| 100 | name: "infra/python/wheels/click-py3" | 100 | name: "infra/python/wheels/click-py3" |
| 101 | version: "version:8.0.3" | 101 | version: "version:8.0.3" |
| 102 | > | 102 | > |
| 103 | |||
| 104 | wheel: < | ||
| 105 | name: "infra/python/wheels/flake8-py2_py3" | ||
| 106 | version: "version:6.0.0" | ||
| 107 | > | ||
| 108 | |||
| 109 | # Required by flake8==6.0.0 | ||
| 110 | wheel: < | ||
| 111 | name: "infra/python/wheels/mccabe-py2_py3" | ||
| 112 | version: "version:0.7.0" | ||
| 113 | > | ||
| 114 | |||
| 115 | # Required by flake8==6.0.0 | ||
| 116 | wheel: < | ||
| 117 | name: "infra/python/wheels/pyflakes-py2_py3" | ||
| 118 | version: "version:3.0.1" | ||
| 119 | > | ||
| 120 | |||
| 121 | # Required by flake8==6.0.0 | ||
| 122 | wheel: < | ||
| 123 | name: "infra/python/wheels/pycodestyle-py2_py3" | ||
| 124 | version: "version:2.10.0" | ||
| 125 | > | ||
| @@ -28,6 +28,7 @@ python = | |||
| 28 | [testenv] | 28 | [testenv] |
| 29 | deps = | 29 | deps = |
| 30 | black | 30 | black |
| 31 | flake8 | ||
| 31 | pytest | 32 | pytest |
| 32 | pytest-timeout | 33 | pytest-timeout |
| 33 | commands = {envpython} run_tests {posargs} | 34 | commands = {envpython} run_tests {posargs} |
