2f576263e4
This is a reland of commit 094bcdb9e5
Original change's description:
> [infra] Use Python3 for our Presubmits
>
> https://source.chromium.org/chromium/chromium/tools/depot_tools/+/main:presubmit_support.py;l=319;drc=443d9135cc33f3156d5fe25ebec33f9adffbab65
>
> This also makes any errors from `make train -C infra/bots`
> look well formatted because check_output returns a bytestring
> in Python3 and when that is printed, the newlines et al are not
> rendered correctly. Thus we want the output of check_output
> to be encoded to UTF-8.
>
> Without setting the USE_PYTHON3 = True in PRESUBMIT.py,
> it appears that `git cl upload` would try to run our
> infra_tests.py in Python2 mode, which does not have
> the encoding argument for check_output.
>
> Apparently cipd_bin_packages/vpython3 does not have the
> "six" package installed (but cipd_bin_packages/vpython does)
> so I replaced the six.StringIO with io.StringIO, which
> is where that is located in Python3.
>
> Change-Id: Ic8f61bf943531583ba3d110a85260d69bdbf5eb2
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/537677
> Reviewed-by: Ravi Mistry <rmistry@google.com>
> Reviewed-by: Eric Boren <borenet@google.com>
Change-Id: Ia7fb2f3b6d8b70ca95cf10763782d4a0122053e0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/537978
Reviewed-by: Eric Boren <borenet@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
92 lines
1.9 KiB
Python
Executable File
92 lines
1.9 KiB
Python
Executable File
#!/usr/bin/env python
|
|
#
|
|
# Copyright 2016 Google Inc.
|
|
#
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
|
|
"""Run all infrastructure-related tests."""
|
|
|
|
|
|
from __future__ import print_function
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
INFRA_BOTS_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
SKIA_DIR = os.path.abspath(os.path.join(INFRA_BOTS_DIR, os.pardir, os.pardir))
|
|
|
|
|
|
def test(cmd, cwd):
|
|
try:
|
|
subprocess.check_output(cmd, cwd=cwd, stderr=subprocess.STDOUT, encoding='utf-8')
|
|
except subprocess.CalledProcessError as e:
|
|
return e.output
|
|
|
|
|
|
def python_unit_tests(train):
|
|
if train:
|
|
return None
|
|
return test(
|
|
['python', '-u', '-m', 'unittest', 'discover', '-s', '.', '-p',
|
|
'*_test.py'],
|
|
INFRA_BOTS_DIR)
|
|
|
|
|
|
def recipe_test(train):
|
|
cmd = [
|
|
'python', '-u', os.path.join(INFRA_BOTS_DIR, 'recipes.py'), 'test']
|
|
if train:
|
|
cmd.append('train')
|
|
else:
|
|
cmd.append('run')
|
|
return test(cmd, SKIA_DIR)
|
|
|
|
|
|
def gen_tasks_test(train):
|
|
cmd = ['go', 'run', 'gen_tasks.go']
|
|
if not train:
|
|
cmd.append('--test')
|
|
try:
|
|
output = test(cmd, INFRA_BOTS_DIR)
|
|
except OSError:
|
|
return ('Failed to run "%s"; do you have Go installed on your machine?'
|
|
% ' '.join(cmd))
|
|
return output
|
|
|
|
|
|
def main():
|
|
train = False
|
|
if '--train' in sys.argv:
|
|
train = True
|
|
|
|
tests = (
|
|
python_unit_tests,
|
|
recipe_test,
|
|
gen_tasks_test,
|
|
)
|
|
errs = []
|
|
for t in tests:
|
|
err = t(train)
|
|
if err:
|
|
errs.append(err)
|
|
|
|
if len(errs) > 0:
|
|
print('Test failures:\n', file=sys.stderr)
|
|
for err in errs:
|
|
print('==============================', file=sys.stderr)
|
|
print(err, file=sys.stderr)
|
|
print('==============================', file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
if train:
|
|
print('Trained tests successfully.')
|
|
else:
|
|
print('All tests passed!')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|