Exemple #1
0
def run_tests(suites, config):
    test_runner = PrettyTestRunner(config)

    start_time = time.time()
    for suite in suites:
        if suite.countTestCases() == 0:
            continue

        log_dir = os.path.join(config.logs_path, 'test')
        ensure_dir(log_dir)
        log_filename = os.path.join(log_dir, '%s.log' % (get_suite_name(suite),))

        with open(log_filename, 'w') as logfile:
            test_runner.run(suite, logfile)

    seconds_elapsed = time.time() - start_time
    all_tests = sum(r.testsRun for r in test_runner.results)
    successes = sum(r.testsPassed for r in test_runner.results)
    errors = sum(r.testsErrors for r in test_runner.results)
    failures = sum(r.testsFailed for r in test_runner.results)

    print('\nFinished in %f s; %s%d/%d successes%s, %s%d/%d errors%s, %s%d/%d failures%s\n'
          % (seconds_elapsed,
             COLOR_GREEN if successes == all_tests else COLOR_YELLOW, successes, all_tests,
             COLOR_DEFAULT,
             COLOR_RED if errors else COLOR_GREEN, errors, all_tests, COLOR_DEFAULT,
             COLOR_RED if failures else COLOR_GREEN, failures, all_tests, COLOR_DEFAULT))

    return test_runner.results
Exemple #2
0
def merge_directory(src, dst):
    for item in os.listdir(src):
        src_item = os.path.join(src, item)
        dst_item = os.path.join(dst, item)

        if os.path.isdir(src_item):
            merge_directory(src_item, dst_item)
        else:
            ensure_dir(os.path.dirname(dst_item))
            shutil.copy2(src_item, dst_item)
Exemple #3
0
def merge_directory(src, dst):
    """
    Move all contents of SRC into DST, preserving directory structure.
    """
    for item in os.listdir(src):
        src_item = os.path.join(src, item)
        dst_item = os.path.join(dst, item)

        if os.path.isdir(src_item):
            merge_directory(src_item, dst_item)
        else:
            ensure_dir(os.path.dirname(dst_item))
            shutil.move(src_item, dst_item)
Exemple #4
0
def run_tests(suites, config):
    has_error = False

    test_runner = PrettyTestRunner(config)

    start_time = time.time()
    for suite in suites:
        if suite.countTestCases() == 0:
            continue

        log_dir = os.path.join(config.logs_path, 'test')
        ensure_dir(log_dir)
        log_filename = os.path.join(log_dir,
                                    '%s.log' % (get_suite_name(suite), ))

        with open(log_filename, 'w') as logfile:
            res = test_runner.run(suite, logfile)
            if not res.wasSuccessful():
                has_error = True

    seconds_elapsed = time.time() - start_time
    all_tests = sum(r.testsRun for r in test_runner.results)
    successes = sum(r.testsPassed for r in test_runner.results)
    errors = sum(r.testsErrors for r in test_runner.results)
    failures = sum(r.testsFailed for r in test_runner.results)

    print(
        '\nFinished in %f s; %s%d/%d successes%s, %s%d/%d errors%s, %s%d/%d failures%s\n'
        % (seconds_elapsed, COLOR_GREEN if successes == all_tests else
           COLOR_YELLOW, successes, all_tests, COLOR_DEFAULT, COLOR_RED if
           errors else COLOR_GREEN, errors, all_tests, COLOR_DEFAULT, COLOR_RED
           if failures else COLOR_GREEN, failures, all_tests, COLOR_DEFAULT))

    if has_error:
        for r in test_runner.results:
            print(r.errorSummary(log_root=config.target_logs_path))

        raise SystemError("Some tests failed, inspect log for details")
Exemple #5
0
                            if not k.startswith('_'))  # skip builtins

            max_key_len = max(len(k) for k, _ in config)

            return '\n  '.join(
                ['Test config:'] +
                ['%%-%ds = %%s' % max_key_len % kv for kv in config])

        test_suites = discover_test_suites(TestConfig)
        header = '%d tests:' % test_suites.countTestCases()

        if cmdline_args.query_regex:
            test_suites = filter_tests(test_suites, cmdline_args.query_regex)
            header = '%d tests match pattern %s:' % (
                test_suites.countTestCases(), cmdline_args.query_regex)

        list_tests(test_suites, header=header)

        result = None
        if not cmdline_args.list:
            sys.stderr.write('%s\n\n' % config_to_string(TestConfig))

            try:
                run_tests(test_suites, TestConfig)
            finally:
                # calculate logs path based on executable path to prevent it
                # from creating files in source directory if building out of source
                ensure_dir(os.path.dirname(TestConfig.target_logs_path))
                merge_directory(TestConfig.logs_path,
                                TestConfig.target_logs_path)