skia2/infra/bots/infra_tests.py
Ben Wagner 9c17be5301 [infra] Update docs with respect to Go modules.
Docs-Preview: https://skia.org/?cl=255085
Change-Id: I8911862ca9814b89b8598ad743b1faa9c524399f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/255085
Commit-Queue: Ben Wagner aka dogben <benjaminwagner@google.com>
Commit-Queue: Joe Gregorio <jcgregorio@google.com>
Reviewed-by: Joe Gregorio <jcgregorio@google.com>
Reviewed-by: Eric Boren <borenet@google.com>
Auto-Submit: Ben Wagner aka dogben <benjaminwagner@google.com>
2019-11-18 18:04:19 +00:00

90 lines
1.8 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."""
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
def python_unit_tests(train):
if train:
return None
return test(
['python', '-m', 'unittest', 'discover', '-s', '.', '-p', '*_test.py'],
INFRA_BOTS_DIR)
def recipe_test(train):
cmd = [
'python', 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 >> sys.stderr, 'Test failures:\n'
for err in errs:
print >> sys.stderr, '=============================='
print >> sys.stderr, err
print >> sys.stderr, '=============================='
sys.exit(1)
if train:
print 'Trained tests successfully.'
else:
print 'All tests passed!'
if __name__ == '__main__':
main()