aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/bots/infra_tests.py
diff options
context:
space:
mode:
authorGravatar borenet <borenet@chromium.org>2016-10-14 06:32:09 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-10-14 06:32:09 -0700
commit2dbbfa5d376d7356df5e18bd41d7138aa6345512 (patch)
tree8792a2146578f238d48469117744edce80f3ca19 /infra/bots/infra_tests.py
parent2eaef920ebb241d718e0c1facb966eefb1f2aefb (diff)
Add infra_tests.py, recipe, buildbotless bot
Have the presubmit (upload) run infra_tests.py if anything in infra/ changed. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2415193002 Review-Url: https://codereview.chromium.org/2415193002
Diffstat (limited to 'infra/bots/infra_tests.py')
-rwxr-xr-xinfra/bots/infra_tests.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/infra/bots/infra_tests.py b/infra/bots/infra_tests.py
new file mode 100755
index 0000000000..779ea8d83b
--- /dev/null
+++ b/infra/bots/infra_tests.py
@@ -0,0 +1,77 @@
+#!/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():
+ return test(
+ ['python', '-m', 'unittest', 'discover', '-s', '.', '-p', '*_test.py'],
+ INFRA_BOTS_DIR)
+
+
+def recipe_simulation_test():
+ return test(
+ ['python', os.path.join(INFRA_BOTS_DIR, 'recipes.py'), 'simulation_test'],
+ SKIA_DIR)
+
+
+def gen_tasks_test():
+ cmd = ['go', 'run', 'gen_tasks.go', '--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))
+ if output and 'cannot find package "go.skia.org/infra' in output:
+ return ('Failed to run gen_tests.go:\n\n%s\nMaybe you need to run:\n\n'
+ '$ go get -u go.skia.org/infra/...' % output)
+ return output
+
+
+def main():
+ tests = (
+ python_unit_tests,
+ recipe_simulation_test,
+ gen_tasks_test,
+ )
+ errs = []
+ for t in tests:
+ err = t()
+ 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)
+
+ print 'All tests passed!'
+
+
+if __name__ == '__main__':
+ main()