70 lines
2.9 KiB
Python
70 lines
2.9 KiB
Python
import re
|
|
|
|
|
|
def filter_out_failed_test_timing(test_result, timing_result):
|
|
final_timing_result = {}
|
|
processed_test_result = {}
|
|
for test_name, test_passed in test_result.items():
|
|
test_path, test_case = test_name.split(":")
|
|
split_test_path = test_path.split(".")
|
|
if not split_test_path[-2].endswith("__perfinstrumented"):
|
|
raise ValueError(
|
|
"Didn't find the __perfinstrumented suffix for the perf instrumented test. Please check what test is being tested"
|
|
)
|
|
split_test_path[-2] = split_test_path[-2][: -len("__perfinstrumented")]
|
|
processed_test_result[".".join(split_test_path[:-1]) + ":" + test_case] = test_passed
|
|
|
|
for test_name_compound, time_taken in timing_result.items():
|
|
test_path, function_tested, test_case, test_case_id = test_name_compound.split(":")
|
|
search_key = test_path + ":" + test_case
|
|
if search_key in processed_test_result and processed_test_result[search_key]:
|
|
final_timing_result[test_name_compound] = time_taken
|
|
return final_timing_result
|
|
|
|
|
|
def parse_test_return_values_bin(file_location):
|
|
test_results = {}
|
|
if not os.path.exists(file_location):
|
|
return None
|
|
with open(file_location, "rb") as file:
|
|
while file:
|
|
len_next = file.read(4)
|
|
if not len_next:
|
|
return test_results
|
|
len_next = int.from_bytes(len_next, byteorder="big")
|
|
test_name = file.read(len_next).decode("ascii")
|
|
len_next = file.read(8)
|
|
duration = int.from_bytes(len_next, byteorder="big")
|
|
len_next = file.read(4)
|
|
if not len_next:
|
|
return test_results
|
|
len_next = int.from_bytes(len_next, byteorder="big")
|
|
test_pickle = pickle.loads(file.read(len_next))
|
|
test_results[test_name] = {"runtime": [duration], "results": [test_pickle]}
|
|
return test_results
|
|
|
|
|
|
def parse_unittest_output(output):
|
|
re_pattern = r"^(test\w+)\s\((.*?)\)\s\.\.\.\s.*?(ok|FAIL|ERROR)$"
|
|
matches = re.findall(re_pattern, output, re.MULTILINE | re.DOTALL)
|
|
test_results = {}
|
|
for match in matches:
|
|
if not str.isidentifier(match[0]):
|
|
print(f"Invalid test name {match[0]}. Test names must be valid python identifiers")
|
|
continue
|
|
if match[2] == "ok":
|
|
test_results[match[1] + ":" + match[0]] = True
|
|
elif match[2] in ["FAIL", "ERROR"]:
|
|
test_results[match[1] + ":" + match[0]] = False
|
|
else:
|
|
raise ValueError("Invalid test result, couldn't parse the test output")
|
|
return test_results
|
|
|
|
|
|
def parse_test_timing(test_results):
|
|
m = re.findall(r"#####([^#]*?)#####([\d\.]*?)\^\^\^\^\^", test_results)
|
|
parsed_results = {}
|
|
for test_name, time_taken in m:
|
|
time_taken = int(time_taken)
|
|
parsed_results[test_name] = time_taken
|
|
return parsed_results
|