Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_runner.py
Show First 20 Lines • Show All 489 Lines • ▼ Show 20 Lines | def execute_test_processes(num_jobs, test_list, tests_dir, tmpdir, flags): | ||||
return test_results | return test_results | ||||
def print_results(test_results, tests_dir, max_len_name, runtime, combined_logs_len): | def print_results(test_results, tests_dir, max_len_name, runtime, combined_logs_len): | ||||
results = "\n" + BOLD[1] + "{} | {} | {}\n\n".format( | results = "\n" + BOLD[1] + "{} | {} | {}\n\n".format( | ||||
"TEST".ljust(max_len_name), "STATUS ", "DURATION") + BOLD[0] | "TEST".ljust(max_len_name), "STATUS ", "DURATION") + BOLD[0] | ||||
test_results.sort(key=lambda result: result.name.lower()) | test_results.sort(key=TestResult.sort_key) | ||||
all_passed = True | all_passed = True | ||||
time_sum = 0 | time_sum = 0 | ||||
for test_result in test_results: | for test_result in test_results: | ||||
all_passed = all_passed and test_result.was_successful | all_passed = all_passed and test_result.was_successful | ||||
time_sum += test_result.time | time_sum += test_result.time | ||||
test_result.padding = max_len_name | test_result.padding = max_len_name | ||||
results += str(test_result) | results += str(test_result) | ||||
testdir = test_result.testdir | testdir = test_result.testdir | ||||
if combined_logs_len and os.path.isdir(testdir): | if combined_logs_len and os.path.isdir(testdir): | ||||
# Print the final `combinedlogslen` lines of the combined logs | # Print the final `combinedlogslen` lines of the combined logs | ||||
print('{}Combine the logs and print the last {} lines ...{}'.format( | print('{}Combine the logs and print the last {} lines ...{}'.format( | ||||
BOLD[1], combined_logs_len, BOLD[0])) | BOLD[1], combined_logs_len, BOLD[0])) | ||||
print('\n============') | print('\n============') | ||||
print('{}Combined log for {}:{}'.format(BOLD[1], testdir, BOLD[0])) | print('{}Combined log for {}:{}'.format(BOLD[1], testdir, BOLD[0])) | ||||
print('============\n') | print('============\n') | ||||
combined_logs, _ = subprocess.Popen([sys.executable, os.path.join( | combined_logs, _ = subprocess.Popen([sys.executable, os.path.join( | ||||
tests_dir, 'combine_logs.py'), '-c', testdir], universal_newlines=True, stdout=subprocess.PIPE).communicate() | tests_dir, 'combine_logs.py'), '-c', testdir], universal_newlines=True, stdout=subprocess.PIPE).communicate() | ||||
print("\n".join(deque(combined_logs.splitlines(), combined_logs_len))) | print("\n".join(deque(combined_logs.splitlines(), combined_logs_len))) | ||||
status = TICK + "Passed" if all_passed else CROSS + "Failed" | status = TICK + "Passed" if all_passed else CROSS + "Failed" | ||||
if not all_passed: | |||||
results += RED[1] | |||||
results += BOLD[1] + "\n{} | {} | {} s (accumulated) \n".format( | results += BOLD[1] + "\n{} | {} | {} s (accumulated) \n".format( | ||||
"ALL".ljust(max_len_name), status.ljust(9), time_sum) + BOLD[0] | "ALL".ljust(max_len_name), status.ljust(9), time_sum) + BOLD[0] | ||||
if not all_passed: | |||||
results += RED[0] | |||||
results += "Runtime: {} s\n".format(runtime) | results += "Runtime: {} s\n".format(runtime) | ||||
print(results) | print(results) | ||||
class TestResult(): | class TestResult(): | ||||
""" | """ | ||||
Simple data structure to store test result values and print them properly | Simple data structure to store test result values and print them properly | ||||
""" | """ | ||||
def __init__(self, num, name, testdir, status, time, stdout, stderr): | def __init__(self, num, name, testdir, status, time, stdout, stderr): | ||||
self.num = num | self.num = num | ||||
self.name = name | self.name = name | ||||
self.testdir = testdir | self.testdir = testdir | ||||
self.status = status | self.status = status | ||||
self.time = time | self.time = time | ||||
self.padding = 0 | self.padding = 0 | ||||
self.stdout = stdout | self.stdout = stdout | ||||
self.stderr = stderr | self.stderr = stderr | ||||
def sort_key(self): | |||||
if self.status == "Passed": | |||||
return 0, self.name.lower() | |||||
elif self.status == "Failed": | |||||
return 2, self.name.lower() | |||||
elif self.status == "Skipped": | |||||
return 1, self.name.lower() | |||||
def __repr__(self): | def __repr__(self): | ||||
if self.status == "Passed": | if self.status == "Passed": | ||||
color = BLUE | color = BLUE | ||||
glyph = TICK | glyph = TICK | ||||
elif self.status == "Failed": | elif self.status == "Failed": | ||||
color = RED | color = RED | ||||
glyph = CROSS | glyph = CROSS | ||||
elif self.status == "Skipped": | elif self.status == "Skipped": | ||||
▲ Show 20 Lines • Show All 200 Lines • Show Last 20 Lines |