2016-10-14 13:32:09 +00:00
|
|
|
#!/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."""
|
|
|
|
|
|
|
|
|
2021-03-25 13:04:43 +00:00
|
|
|
from __future__ import print_function
|
2016-10-14 13:32:09 +00:00
|
|
|
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)
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
return e.output
|
|
|
|
|
|
|
|
|
2017-04-13 14:22:11 +00:00
|
|
|
def python_unit_tests(train):
|
|
|
|
if train:
|
|
|
|
return None
|
2016-10-14 13:32:09 +00:00
|
|
|
return test(
|
2020-03-18 15:09:22 +00:00
|
|
|
['python', '-u', '-m', 'unittest', 'discover', '-s', '.', '-p',
|
|
|
|
'*_test.py'],
|
2016-10-14 13:32:09 +00:00
|
|
|
INFRA_BOTS_DIR)
|
|
|
|
|
|
|
|
|
2017-04-18 13:15:53 +00:00
|
|
|
def recipe_test(train):
|
2017-04-13 14:22:11 +00:00
|
|
|
cmd = [
|
2020-03-18 15:09:22 +00:00
|
|
|
'python', '-u', os.path.join(INFRA_BOTS_DIR, 'recipes.py'), 'test']
|
2017-04-13 14:22:11 +00:00
|
|
|
if train:
|
2017-06-28 17:50:22 +00:00
|
|
|
cmd.append('train')
|
|
|
|
else:
|
|
|
|
cmd.append('run')
|
2017-04-13 14:22:11 +00:00
|
|
|
return test(cmd, SKIA_DIR)
|
2016-10-14 13:32:09 +00:00
|
|
|
|
|
|
|
|
2017-04-13 14:22:11 +00:00
|
|
|
def gen_tasks_test(train):
|
|
|
|
cmd = ['go', 'run', 'gen_tasks.go']
|
|
|
|
if not train:
|
|
|
|
cmd.append('--test')
|
2016-10-14 13:32:09 +00:00
|
|
|
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():
|
2017-04-13 14:22:11 +00:00
|
|
|
train = False
|
|
|
|
if '--train' in sys.argv:
|
|
|
|
train = True
|
|
|
|
|
2016-10-14 13:32:09 +00:00
|
|
|
tests = (
|
|
|
|
python_unit_tests,
|
2017-04-18 13:15:53 +00:00
|
|
|
recipe_test,
|
2016-10-14 13:32:09 +00:00
|
|
|
gen_tasks_test,
|
|
|
|
)
|
|
|
|
errs = []
|
|
|
|
for t in tests:
|
2017-04-13 14:22:11 +00:00
|
|
|
err = t(train)
|
2016-10-14 13:32:09 +00:00
|
|
|
if err:
|
|
|
|
errs.append(err)
|
|
|
|
|
|
|
|
if len(errs) > 0:
|
2021-03-25 13:04:43 +00:00
|
|
|
print('Test failures:\n', file=sys.stderr)
|
2016-10-14 13:32:09 +00:00
|
|
|
for err in errs:
|
2021-03-25 13:04:43 +00:00
|
|
|
print('==============================', file=sys.stderr)
|
|
|
|
print(err, file=sys.stderr)
|
|
|
|
print('==============================', file=sys.stderr)
|
2016-10-14 13:32:09 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2017-04-13 14:22:11 +00:00
|
|
|
if train:
|
2021-03-25 13:04:43 +00:00
|
|
|
print('Trained tests successfully.')
|
2017-04-13 14:22:11 +00:00
|
|
|
else:
|
2021-03-25 13:04:43 +00:00
|
|
|
print('All tests passed!')
|
2016-10-14 13:32:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|