Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: tools/chrome_remote_control/chrome_remote_control/run_tests.py

Issue 10875044: Basic framework for devtools-based scrolling tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with the added files Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/chrome_remote_control/chrome_remote_control/run_tests.py
diff --git a/tools/chrome_remote_control/chrome_remote_control/run_tests.py b/tools/chrome_remote_control/chrome_remote_control/run_tests.py
new file mode 100644
index 0000000000000000000000000000000000000000..c8ab158b92607f62196a9f497d0ec78bfd948dd0
--- /dev/null
+++ b/tools/chrome_remote_control/chrome_remote_control/run_tests.py
@@ -0,0 +1,94 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+import fnmatch
+import os
+import sys
+import traceback
+import unittest
+
+def Discover(start_dir, pattern = "test*.py", top_level_dir = None):
+ if hasattr(unittest.defaultTestLoader, 'discover'):
+ return unittest.defaultTestLoader.discover(start_dir,
+ pattern,
+ top_level_dir)
+
+ # TODO(nduca): Do something with top_level_dir non-None
+ modules = []
+ for (dirpath, dirnames, filenames) in os.walk(start_dir):
+ for filename in filenames:
+ if not filename.endswith(".py"):
+ continue
+
+ if not fnmatch.fnmatch(filename, pattern):
+ continue
+
+ if filename.startswith('.') or filename.startswith('_'):
+ continue
+ name,ext = os.path.splitext(filename)
+ fqn = dirpath.replace('/', '.') + '.' + name
+
+ # load the module
+ try:
+ module = __import__(fqn, fromlist=[True])
+ except:
+ print "While importing [%s]\n" % fqn
+ traceback.print_exc()
+ continue
+ modules.append(module)
+
+ loader = unittest.defaultTestLoader
+ subsuites = []
+ for module in modules:
+ if hasattr(module, 'suite'):
+ new_suite = module.suite()
+ else:
+ new_suite = loader.loadTestsFromModule(module)
+ if new_suite.countTestCases():
+ subsuites.append(new_suite)
+ return unittest.TestSuite(subsuites)
+
+def FilterSuite(suite, predicate):
+ new_suite = unittest.TestSuite()
+ for x in suite:
+ if isinstance(x, unittest.TestSuite):
+ subsuite = FilterSuite(x, predicate)
+ if subsuite.countTestCases() == 0:
+ continue
+
+ new_suite.addTest(subsuite)
+ continue
+
+ assert isinstance(x, unittest.TestCase)
+ if predicate(x):
+ new_suite.addTest(x)
+
+ return new_suite
+
+'''Unit test suite that collects all test cases for chrome_remote_control.'''
+def Main(argv):
+ dir_name = os.path.join(os.path.dirname(__file__), "..")
+ olddir = os.getcwd()
+ try:
+ os.chdir(dir_name)
+ suite = Discover("chrome_remote_control", "*_unittest.py", ".")
+
+ def IsTestSelected(test):
+ if len(argv) == 1:
+ return True
+ for name in argv[1:]:
+ if str(test).find(name) != -1:
+ return True
+ return False
+
+ filtered_suite = FilterSuite(suite, IsTestSelected)
+ runner = unittest.TextTestRunner(verbosity = 2)
+ test_result = runner.run(filtered_suite)
+ return len(test_result.errors) + len(test_result.failures)
+
+ finally:
+ os.chdir(olddir)
+ return 1
+
+if __name__ == "__main__":
+ sys.exit(Main(sys.argv))

Powered by Google App Engine
This is Rietveld 408576698