Exemplo n.º 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)
Exemplo n.º 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
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
Exemplo n.º 4
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)