make gm self-tests launch python unittests automatically
authorepoger <epoger@google.com>
Wed, 16 Jul 2014 15:28:23 +0000 (08:28 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 16 Jul 2014 15:28:23 +0000 (08:28 -0700)
(not just within the rebaseline_server subdirectory)

Generally useful, but needed asap for my work on http://skbug.com/2752 ('split existing "gpu" GM results into "gl" and "gles"')

BUG=skia:677
NOTREECHECKS=True
NOTRY=True
R=rmistry@google.com
TBR=rmistry

Author: epoger@google.com

Review URL: https://codereview.chromium.org/398043002

gm/rebaseline_server/__init__.py [new file with mode: 0644]
gm/rebaseline_server/base_unittest.py
gm/rebaseline_server/test_all.py
gm/test_all.py [new file with mode: 0755]
gm/tests/run.sh

diff --git a/gm/rebaseline_server/__init__.py b/gm/rebaseline_server/__init__.py
new file mode 100644 (file)
index 0000000..02d71e9
--- /dev/null
@@ -0,0 +1 @@
+# Needed so that test_all.py will recurse into this directory.
index 0699db6..32b4bb9 100755 (executable)
@@ -26,9 +26,14 @@ OUTPUT_DIR_EXPECTED = os.path.join(TESTDATA_DIR, 'outputs', 'expected')
 class TestCase(unittest.TestCase):
 
   def setUp(self):
+    # Get the name of this test, in such a way that it will be consistent
+    # regardless of the directory it is run from (throw away package names,
+    # if any).
+    test_name = '.'.join(self.id().split('.')[-3:])
+
     self._input_dir = os.path.join(TESTDATA_DIR, 'inputs')
-    self._output_dir_actual   = os.path.join(OUTPUT_DIR_ACTUAL, self.id())
-    self._output_dir_expected = os.path.join(OUTPUT_DIR_EXPECTED, self.id())
+    self._output_dir_actual   = os.path.join(OUTPUT_DIR_ACTUAL, test_name)
+    self._output_dir_expected = os.path.join(OUTPUT_DIR_EXPECTED, test_name)
     create_empty_dir(self._output_dir_actual)
     self._temp_dir = tempfile.mkdtemp()
 
@@ -125,4 +130,4 @@ def find_different_files(dir1, dir2, ignore_subtree_names=None):
 def main(test_case_class):
   """Run the unit tests within the given class."""
   suite = unittest.TestLoader().loadTestsFromTestCase(test_case_class)
-  results = unittest.TextTestRunner(verbosity=2).run(suite)
+  unittest.TextTestRunner(verbosity=2).run(suite)
index 299d134..282ec85 100755 (executable)
@@ -7,9 +7,6 @@ Use of this source code is governed by a BSD-style license that can be
 found in the LICENSE file.
 
 Run all unittests within this directory tree, recursing into subdirectories.
-
-TODO(epoger): Launch this automatically on the housekeeper bot, but first make
-sure it works properly after having been checked out (from both git and svn)
 """
 
 import os
diff --git a/gm/test_all.py b/gm/test_all.py
new file mode 100755 (executable)
index 0000000..282ec85
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+
+"""
+Copyright 2014 Google Inc.
+
+Use of this source code is governed by a BSD-style license that can be
+found in the LICENSE file.
+
+Run all unittests within this directory tree, recursing into subdirectories.
+"""
+
+import os
+import unittest
+
+
+def main():
+  suite = unittest.TestLoader().discover(os.path.dirname(__file__),
+                                         pattern='*_test.py')
+  results = unittest.TextTestRunner(verbosity=2).run(suite)
+  print repr(results)
+  if not results.wasSuccessful():
+    raise Exception('failed one or more unittests')
+
+if __name__ == '__main__':
+  main()
index 333f3ef..52ed6f3 100755 (executable)
@@ -264,8 +264,8 @@ for CASE in $FAILING_CASES; do
   assert_fails "python gm/display_json_results.py $GM_OUTPUTS/$CASE/$OUTPUT_EXPECTED_SUBDIR/json-summary.txt"
 done
 
-# Exercise all rebaseline_server unittests.
-assert_passes "python gm/rebaseline_server/test_all.py"
+# Exercise all Python unittests.
+assert_passes "python gm/test_all.py"
 
 echo
 if [ $ENCOUNTERED_ANY_ERRORS == 0 ]; then