Bug 802227: add --testvars to runner to accept JSON file with test data; r=jgriffin
authorDavid Burns <dburns@mozilla.com>
Fri, 19 Oct 2012 20:32:36 +0100
changeset 110810 be7c882f0f851f2a51798819cb331bbdd571487d
parent 110809 d7464788b572006177f882d857ec143c5d32b34c
child 110811 9b7c3072b2a3564470b6c0f2fa25ea55d331f2b7
push id23716
push userryanvm@gmail.com
push dateSat, 20 Oct 2012 01:43:16 +0000
treeherdermozilla-central@ff4af83233dc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin
bugs802227
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 802227: add --testvars to runner to accept JSON file with test data; r=jgriffin
testing/marionette/client/marionette/marionette_test.py
testing/marionette/client/marionette/runtests.py
testing/marionette/client/setup.py
--- a/testing/marionette/client/marionette/marionette_test.py
+++ b/testing/marionette/client/marionette/marionette_test.py
@@ -38,17 +38,17 @@ class CommonTestCase(unittest.TestCase):
         using cls.match_re.
         """
         if not cls.match_re:
             return False
         m = cls.match_re.match(filename)
         return m is not None
 
     @classmethod
-    def add_tests_to_suite(cls, mod_name, filepath, suite, testloader, marionette):
+    def add_tests_to_suite(cls, mod_name, filepath, suite, testloader, marionette, testvars):
         """
         Adds all the tests in the specified file to the specified suite.
         """
         raise NotImplementedError
 
     def set_up_test_page(self, emulator, url="test.html", permissions=None):
         emulator.set_context("content")
         url = emulator.absolute_url(url)
@@ -90,32 +90,33 @@ class MarionetteTestCase(CommonTestCase)
 
     def __init__(self, marionette_weakref, methodName='runTest',
                  filepath='', **kwargs):
         self._marionette_weakref = marionette_weakref
         self.marionette = None
         self.extra_emulator_index = -1
         self.methodName = methodName
         self.filepath = filepath
+        self.testvars = kwargs.pop('testvars', None)
         CommonTestCase.__init__(self, methodName, **kwargs)
 
     @classmethod
-    def add_tests_to_suite(cls, mod_name, filepath, suite, testloader, marionette):
+    def add_tests_to_suite(cls, mod_name, filepath, suite, testloader, marionette, testvars):
         test_mod = imp.load_source(mod_name, filepath)
 
         for name in dir(test_mod):
             obj = getattr(test_mod, name)
             if (isinstance(obj, (type, types.ClassType)) and
                 issubclass(obj, unittest.TestCase)):
                 testnames = testloader.getTestCaseNames(obj)
                 for testname in testnames:
                     suite.addTest(obj(weakref.ref(marionette),
                                   methodName=testname,
-                                  filepath=filepath))
-
+                                  filepath=filepath,
+                                  testvars=testvars))
     def setUp(self):
         CommonTestCase.setUp(self)
         self.marionette.execute_script("log('TEST-START: %s:%s')" % 
                                        (self.filepath.replace('\\', '\\\\'), self.methodName))
 
     def tearDown(self):
         self.marionette.set_context("content")
         self.marionette.execute_script("log('TEST-END: %s:%s')" % 
--- a/testing/marionette/client/marionette/runtests.py
+++ b/testing/marionette/client/marionette/runtests.py
@@ -167,17 +167,17 @@ class MarionetteTextTestRunner(unittest.
 class MarionetteTestRunner(object):
 
     def __init__(self, address=None, emulator=None, emulatorBinary=None,
                  emulatorImg=None, emulator_res='480x800', homedir=None,
                  bin=None, profile=None, autolog=False, revision=None,
                  es_server=None, rest_server=None, logger=None,
                  testgroup="marionette", noWindow=False, logcat_dir=None,
                  xml_output=None, repeat=0, perf=False, perfserv=None,
-                 gecko_path=None):
+                 gecko_path=None, testvars=None):
         self.address = address
         self.emulator = emulator
         self.emulatorBinary = emulatorBinary
         self.emulatorImg = emulatorImg
         self.emulator_res = emulator_res
         self.homedir = homedir
         self.bin = bin
         self.profile = profile
@@ -193,16 +193,25 @@ class MarionetteTestRunner(object):
         self.marionette = None
         self.logcat_dir = logcat_dir
         self.perfrequest = None
         self.xml_output = xml_output
         self.repeat = repeat
         self.perf = perf
         self.perfserv = perfserv
         self.gecko_path = gecko_path
+        self.testvars = None
+
+        if testvars is not None:
+            if not os.path.exists(testvars):
+                raise Exception('--testvars file does not exist')
+
+            import json
+            with open(testvars) as f:
+                self.testvars = json.loads(f.read())
 
         # set up test handlers
         self.test_handlers = []
         self.register_handlers()
 
         self.reset_test_stats()
 
         if self.logger is None:
@@ -414,17 +423,17 @@ class MarionetteTestRunner(object):
             for i in manifest_tests:
                 self.run_test(i["path"], testtype)
             return
 
         self.logger.info('TEST-START %s' % os.path.basename(test))
 
         for handler in self.test_handlers:
             if handler.match(os.path.basename(test)):
-                handler.add_tests_to_suite(mod_name, filepath, suite, testloader, self.marionette)
+                handler.add_tests_to_suite(mod_name, filepath, suite, testloader, self.marionette, self.testvars)
                 break
 
         if suite.countTestCases():
             results = MarionetteTextTestRunner(verbosity=3, perf=self.perf).run(suite)
             self.results.append(results)
 
             self.failed += len(results.failures) + len(results.errors)
             if results.perfdata and options.perf:
@@ -607,16 +616,19 @@ def parse_options():
     parser.add_option('--repeat', dest='repeat', action='store', type=int,
                       default=0, help='number of times to repeat the test(s).')
     parser.add_option('-x', '--xml-output', action='store', dest='xml_output',
                       help='XML output.')
     parser.add_option('--gecko-path', dest='gecko_path', action='store',
                       default=None,
                       help='path to B2G gecko binaries that should be '
                       'installed on the device or emulator')
+    parser.add_option('--testvars', dest='testvars', action='store',
+                      default=None,
+                     help='path to a JSON file with any test data required')
 
     options, tests = parser.parse_args()
 
     if not tests:
         parser.print_usage()
         parser.exit()
 
     if not options.emulator and not options.address and not options.bin:
@@ -657,17 +669,18 @@ def startTestRunner(runner_class, option
                           noWindow=options.noWindow,
                           revision=options.revision,
                           testgroup=options.testgroup,
                           autolog=options.autolog,
                           xml_output=options.xml_output,
                           repeat=options.repeat,
                           perf=options.perf,
                           perfserv=options.perfserv,
-                          gecko_path=options.gecko_path)
+                          gecko_path=options.gecko_path,
+                          testvars=options.testvars)
     runner.run_tests(tests, testtype=options.type)
     return runner
 
 def cli(runner_class=MarionetteTestRunner):
     options, tests = parse_options()
     runner = startTestRunner(runner_class, options, tests)
     if runner.failed > 0:
         sys.exit(10)
--- a/testing/marionette/client/setup.py
+++ b/testing/marionette/client/setup.py
@@ -1,12 +1,12 @@
 import os
 from setuptools import setup, find_packages
 
-version = '0.4'
+version = '0.5'
 
 # get documentation from the README
 try:
     here = os.path.dirname(os.path.abspath(__file__))
     description = file(os.path.join(here, 'README.md')).read()
 except (OSError, IOError):
     description = ''