Пример #1
0
def main(args=None):
    global runner

    if args is None:
        args = sys.argv[1:]

    options = _get_parser().parse_args(args)

    options.skip_dirs = []

    # read user prefs from ~/.testflo file.  create one if it
    # isn't there
    homedir = os.path.expanduser('~')
    rcfile = os.path.join(homedir, '.testflo')
    if not os.path.isfile(rcfile):
        with open(rcfile, 'w') as f:
            f.write("""[testflo]
skip_dirs=site-packages,
    dist-packages,
    build,
    contrib
""" )
    read_config_file(rcfile, options)
    if options.cfg:
        read_config_file(options.cfg, options)

    tests = options.tests
    if options.testfile:
        tests += list(read_test_file(options.testfile))

    if not tests:
        tests = [os.getcwd()]

    def dir_exclude(d):
        for skip in options.skip_dirs:
            if fnmatch(os.path.basename(d), skip):
                return True
        return False

    setup_coverage(options)
    setup_profile(options)

    with open(options.outfile, 'w') as report:
        pipeline = [
            TestDiscoverer(dir_exclude=dir_exclude).get_iter,
        ]

        if options.dryrun:
            pipeline.extend([
                dryrun,
            ])
        else:
            if options.isolated:
                try:
                    import mpi4py
                except ImportError:
                    runner = IsolatedTestRunner(options, args)
                else:
                    from testflo.mpi import IsolatedMPITestRunner
                    runner = IsolatedMPITestRunner(options, args)
            else:
                runner = ConcurrentTestRunner(options)

            pipeline.append(runner.get_iter)

            pipeline.extend([
                ResultPrinter(verbose=options.verbose).get_iter,
                ResultSummary().get_iter,
            ])
            if not options.noreport:
                # mirror results and summary to a report file
                pipeline.extend([
                    ResultPrinter(report, verbose=options.verbose).get_iter,
                    ResultSummary(report).get_iter,
                ])

        if options.maxtime > 0:
            pipeline.append(TimeFilter(options.maxtime).get_iter)

        retval = run_pipeline(tests, pipeline)

        finalize_coverage(options)
        finalize_profile(options)

        return retval
Пример #2
0
def main(args=None):
    # FIXME: get rid of this
    if args is None:
        args = sys.argv[1:]

    options = get_options(args)

    options.skip_dirs = []

    # read user prefs from ~/.testflo file.
    # create one if it doesn't exist
    homedir = os.path.expanduser('~')
    rcfile = os.path.join(homedir, '.testflo')
    if not os.path.isfile(rcfile):
        with open(rcfile, 'w') as f:
            f.write("""[testflo]
skip_dirs=site-packages,
    dist-packages,
    build,
    contrib
""")
    read_config_file(rcfile, options)
    if options.cfg:
        read_config_file(options.cfg, options)

    tests = options.tests
    if options.testfile:
        tests += list(read_test_file(options.testfile))

    if not tests:
        tests = [os.getcwd()]

    def dir_exclude(d):
        for skip in options.skip_dirs:
            if fnmatch(os.path.basename(d), skip):
                return True
        return False

    setup_coverage(options)
    setup_profile(options)

    if options.benchmark:
        options.num_procs = 1
        options.isolated = True
        discoverer = TestDiscoverer(module_pattern=six.text_type('benchmark*.py'),
                                    func_pattern=six.text_type('benchmark*'),
                                    dir_exclude=dir_exclude)
        benchmark_file = open(options.benchmarkfile, 'a')
    else:
        discoverer = TestDiscoverer(dir_exclude=dir_exclude)
        benchmark_file = open(os.devnull, 'a')

    try:
        retval = 0
        server_proc = None

        if options.isolated or not options.nompi:
            addr = get_open_address()
            authkey = 'foo'

            cmd = [sys.executable,
                   os.path.join(os.path.dirname(__file__), 'qman.py')]
            if sys.platform == 'win32':
                cmd.extend((addr, authkey))
            else:
                cmd.extend((addr[0], str(addr[1]), authkey))

            server_proc = subprocess.Popen(cmd, env=os.environ)

            # make sure the server is up before we continue onward
            retries = 10
            man = None
            while retries:
                try:
                    man = get_client_manager(addr, authkey)
                    break
                except:
                    msg = traceback.format_exc()
                    time.sleep(0.5)
                    retries -= 1

            if man is None:
                raise ConnectionRefusedError("Can't connect to queue server: %s"
                                             % msg)
            del man
        else:
            addr = authkey = None

        with open(options.outfile, 'w') as report, benchmark_file as bdata:
            pipeline = [
                discoverer.get_iter,
            ]

            if options.dryrun:
                pipeline.extend([
                    dryrun,
                ])
            else:
                runner = ConcurrentTestRunner(options, addr, authkey)

                pipeline.append(runner.get_iter)

                if options.benchmark:
                    pipeline.append(BenchmarkWriter(stream=bdata).get_iter)

                pipeline.extend([
                    ResultPrinter(verbose=options.verbose).get_iter,
                    ResultSummary(options).get_iter,
                ])
                if not options.noreport:
                    # print verbose results and summary to a report file
                    pipeline.extend([
                        ResultPrinter(report, verbose=True).get_iter,
                        ResultSummary(options, stream=report).get_iter,
                    ])

            if options.maxtime > 0:
                pipeline.append(TimeFilter(options.maxtime).get_iter)

            if options.save_fails:
                pipeline.append(FailFilter().get_iter)

            retval = run_pipeline(tests, pipeline)

            finalize_coverage(options)
            finalize_profile(options)
    finally:
        if server_proc is not None and (options.isolated or not options.nompi):
            try:
                server_proc.terminate()
            except:
                # send msg to stdout instead of stderr to avoid failures when
                # testing under PowerShell.
                print("failed to terminate queue server")

    return retval