Example #1
0
def main(args=sys.argv[1:]):

    # parse command line options
    usage = '%prog [options] manifest.ini <manifest.ini> <...>'
    parser = optparse.OptionParser(usage=usage, description=__doc__)
    parser.add_option('-b', "--binary",
                      dest="binary", help="Binary path",
                      metavar=None, default=None)
    parser.add_option('--list', dest='list_tests',
                      action='store_true', default=False,
                      help="list paths of tests to be run")
    mozlog.commandline.add_logging_group(parser)
    options, args = parser.parse_args(args)
    logger = mozlog.commandline.setup_logging("mozbase", options,
                                              {"tbpl": sys.stdout})

    # read the manifest
    if args:
        manifests = args
    else:
        manifests = [os.path.join(here, 'test-manifest.ini')]
    missing = []
    for manifest in manifests:
        # ensure manifests exist
        if not os.path.exists(manifest):
            missing.append(manifest)
    assert not missing, 'manifest(s) not found: %s' % ', '.join(missing)
    manifest = manifestparser.TestManifest(manifests=manifests)

    if options.binary:
        # A specified binary should override the environment variable
        os.environ['BROWSER_PATH'] = options.binary

    # gather the tests
    tests = manifest.active_tests(disabled=False, **mozinfo.info)
    tests = [test['path'] for test in tests]
    logger.suite_start(tests)

    if options.list_tests:
        # print test paths
        print '\n'.join(tests)
        sys.exit(0)

    # create unittests
    unittestlist = []
    for test in tests:
        unittestlist.extend(unittests(test))

    # run the tests
    suite = unittest.TestSuite(unittestlist)
    runner = StructuredTestRunner(logger=logger)
    unittest_results = runner.run(suite)
    results = TestResultCollection.from_unittest_results(None, unittest_results)
    logger.suite_end()

    # exit according to results
    sys.exit(1 if results.num_failures else 0)
Example #2
0
def run(suite, logger, spawn_browser=True, verbosity=1, quiet=False,
        failfast=False, catch_break=False, buffer=True, **kwargs):
    """A simple test runner.

    This test runner is essentially equivalent to ``unittest.main``
    from the standard library, but adds support for loading test
    classes with extra keyword arguments.

    The easiest way to run a test is via the command line::

        python -m semiauto test_sms

    See the standard library unittest module for ways in which tests
    can be specified.

    For example it is possible to automatically discover tests::

        python -m semiauto discover ."""
    if catch_break:
        import unittest.signals
        unittest.signals.installHandler()

    env = environment.get(environment.InProcessTestEnvironment,
                          addr=None if spawn_browser else ("127.0.0.1", 6666),
                          verbose=(verbosity > 1))

    url = "http://%s:%d/" % (env.server.addr[0], env.server.addr[1])
    if spawn_browser:
        import webbrowser
        webbrowser.open(url)
    else:
        print >> sys.stderr, "Please connect your browser to %s" % url

    # Wait for browser to connect and get socket connection to client
    try:
        so = server.wait_for_client()
    except server.ConnectError as e:
        logger.error("%s: error: %s" % (sys.argv[0], e))
        sys.exit(1)

    tests = serialize_suite(suite)
    test_runner = StructuredTestRunner(logger=logger, test_list=tests)

    # This is a hack to make the test suite metadata and the handler
    # available to the tests.
    so.suite = suite
    environment.env.handler = so

    logger.suite_start(tests=tests)
    try:
        results = test_runner.run(suite)
    except (SystemExit, KeyboardInterrupt) as e:
        sys.exit(1)
    logger.suite_end()

    return results
Example #3
0
    def __init__(self, **kwargs):
        self.marionette = kwargs.pop('marionette')
        self.capabilities = kwargs.pop('capabilities')
        self.pre_run_functions = []
        self.b2g_pid = None
        self.logcat_stdout = kwargs.pop('logcat_stdout')

        if self.capabilities["device"] != "desktop" and self.capabilities["browserName"] == "B2G":
            def b2g_pre_run():
                dm_type = os.environ.get('DM_TRANS', 'adb')
                if dm_type == 'adb':
                    self.b2g_pid = get_b2g_pid(get_dm(self.marionette))
            self.pre_run_functions.append(b2g_pre_run)

        StructuredTestRunner.__init__(self, **kwargs)
Example #4
0
    def __init__(self, **kwargs):
        self.marionette = kwargs.pop('marionette')
        self.capabilities = kwargs.pop('capabilities')
        self.pre_run_functions = []
        self.b2g_pid = None
        self.logcat_stdout = kwargs.pop('logcat_stdout')

        if self.capabilities["device"] != "desktop" and self.capabilities["browserName"] == "B2G":
            def b2g_pre_run():
                dm_type = os.environ.get('DM_TRANS', 'adb')
                if dm_type == 'adb':
                    self.b2g_pid = get_b2g_pid(get_dm(self.marionette))
            self.pre_run_functions.append(b2g_pre_run)

        StructuredTestRunner.__init__(self, **kwargs)
Example #5
0
    def __init__(self, **kwargs):
        self.marionette = kwargs.pop("marionette")
        self.capabilities = kwargs.pop("capabilities")

        StructuredTestRunner.__init__(self, **kwargs)
Example #6
0
    def __init__(self, **kwargs):
        self.marionette = kwargs.pop('marionette')
        self.capabilities = kwargs.pop('capabilities')

        StructuredTestRunner.__init__(self, **kwargs)
Example #7
0
    def __init__(self, **kwargs):
        self.marionette = kwargs.pop('marionette')
        self.capabilities = kwargs.pop('capabilities')

        StructuredTestRunner.__init__(self, **kwargs)
Example #8
0
 def __init__(self, **kwargs):
     self.binary = kwargs.pop('binary')
     StructuredTestRunner.__init__(self, **kwargs)
def run(suite,
        logger,
        spawn_browser=True,
        verbosity=1,
        quiet=False,
        failfast=False,
        catch_break=False,
        buffer=True,
        **kwargs):
    """A simple test runner.

    This test runner is essentially equivalent to ``unittest.main``
    from the standard library, but adds support for loading test
    classes with extra keyword arguments.

    The easiest way to run a test is via the command line::

        python -m semiauto test_sms

    See the standard library unittest module for ways in which tests
    can be specified.

    For example it is possible to automatically discover tests::

        python -m semiauto discover ."""
    if catch_break:
        import unittest.signals
        unittest.signals.installHandler()

    env = environment.get(environment.InProcessTestEnvironment,
                          addr=None if spawn_browser else ("127.0.0.1", 6666),
                          verbose=(verbosity > 1))

    url = "http://%s:%d/" % (env.server.addr[0], env.server.addr[1])
    if spawn_browser:
        import webbrowser
        webbrowser.open(url)
    else:
        print >> sys.stderr, "Please connect your browser to %s" % url

    # Wait for browser to connect and get socket connection to client
    try:
        so = server.wait_for_client()
    except server.ConnectError as e:
        logger.error("%s: error: %s" % (sys.argv[0], e))
        sys.exit(1)

    tests = serialize_suite(suite)
    test_runner = StructuredTestRunner(logger=logger, test_list=tests)

    # This is a hack to make the test suite metadata and the handler
    # available to the tests.
    so.suite = suite
    environment.env.handler = so

    logger.suite_start(tests=tests)
    try:
        results = test_runner.run(suite)
    except (SystemExit, KeyboardInterrupt) as e:
        sys.exit(1)
    logger.suite_end()

    return results
Example #10
0
 def __init__(self, **kwargs):
     self.binary = kwargs.pop('binary')
     StructuredTestRunner.__init__(self, **kwargs)
Example #11
0
    def __init__(self, **kwargs):
        self.marionette = kwargs.pop("marionette")
        self.capabilities = kwargs.pop("capabilities")

        StructuredTestRunner.__init__(self, **kwargs)
Example #12
0
def main(args=sys.argv[1:]):

    # parse command line options
    usage = '%prog [options] manifest.ini <manifest.ini> <...>'
    parser = optparse.OptionParser(usage=usage, description=__doc__)
    parser.add_option('-b',
                      "--binary",
                      dest="binary",
                      help="Binary path",
                      metavar=None,
                      default=None)
    parser.add_option('--list',
                      dest='list_tests',
                      action='store_true',
                      default=False,
                      help="list paths of tests to be run")
    structured.commandline.add_logging_group(parser)
    options, args = parser.parse_args(args)
    logger = structured.commandline.setup_logging("mozbase", options,
                                                  {"tbpl": sys.stdout})

    # read the manifest
    if args:
        manifests = args
    else:
        manifests = [os.path.join(here, 'test-manifest.ini')]
    missing = []
    for manifest in manifests:
        # ensure manifests exist
        if not os.path.exists(manifest):
            missing.append(manifest)
    assert not missing, 'manifest(s) not found: %s' % ', '.join(missing)
    manifest = manifestparser.TestManifest(manifests=manifests)

    if options.binary:
        # A specified binary should override the environment variable
        os.environ['BROWSER_PATH'] = options.binary

    # gather the tests
    tests = manifest.active_tests(disabled=False, **mozinfo.info)
    tests = [test['path'] for test in tests]
    logger.suite_start(tests)

    if options.list_tests:
        # print test paths
        print '\n'.join(tests)
        sys.exit(0)

    # create unittests
    unittestlist = []
    for test in tests:
        unittestlist.extend(unittests(test))

    # run the tests
    suite = unittest.TestSuite(unittestlist)
    runner = StructuredTestRunner(logger=logger)
    unittest_results = runner.run(suite)
    results = TestResultCollection.from_unittest_results(
        None, unittest_results)
    logger.suite_end()

    # exit according to results
    sys.exit(1 if results.num_failures else 0)