-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use argparser to make the script a CLI tool (#637)
- Loading branch information
1 parent
2b5d7b9
commit f9f2313
Showing
1 changed file
with
52 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,60 @@ | ||
import argparse | ||
import re | ||
from collections import defaultdict | ||
|
||
with open("data.txt", "r") as f: | ||
data = f.read() | ||
|
||
matches_failed = [ | ||
( | ||
m.split("::")[-2] | ||
.replace("_minus_", "-") | ||
.replace("_plus_", "+") | ||
.replace("_xor_", "^"), | ||
m.split("::")[-1] | ||
.replace("_minus_", "-") | ||
.replace("_plus_", "+") | ||
.replace("_xor_", "^"), | ||
) | ||
for m in re.findall(r"thread '(.*)' panicked at", data) | ||
] | ||
summary = next( | ||
re.finditer( | ||
r"test result: (?P<result>\w+). (?P<passed>\d+) passed; (?P<failed>\d+) failed; (?P<ignored>\d+) ignored", | ||
data, | ||
|
||
def parse_and_write_to_yaml(input_file, output_file): | ||
with open(input_file, "r") as f: | ||
data = f.read() | ||
|
||
matches_failed = [ | ||
( | ||
m.split("::")[-2] | ||
.replace("_minus_", "-") | ||
.replace("_plus_", "+") | ||
.replace("_xor_", "^"), | ||
m.split("::")[-1] | ||
.replace("_minus_", "-") | ||
.replace("_plus_", "+") | ||
.replace("_xor_", "^"), | ||
) | ||
for m in re.findall(r"thread '(.*)' panicked at", data) | ||
] | ||
summary = next( | ||
re.finditer( | ||
r"test result: (?P<result>\w+). (?P<passed>\d+) passed; (?P<failed>\d+) failed; (?P<ignored>\d+) ignored", | ||
data, | ||
) | ||
) | ||
) | ||
|
||
if len(matches_failed) != int(summary["failed"]): | ||
raise ValueError("Failed to parse file") | ||
if len(matches_failed) != int(summary["failed"]): | ||
raise ValueError("Failed to parse file") | ||
|
||
skip_dict = defaultdict(list) | ||
for [folder, file] in matches_failed: | ||
skip_dict[folder].append(file) | ||
|
||
skip = "testname:\n" | ||
for folder in skip_dict: | ||
skip += f" {folder}:\n" | ||
skip_dict[folder] = sorted(skip_dict[folder]) | ||
for file in skip_dict[folder]: | ||
skip += f" - {file[5:]}\n" | ||
|
||
with open(output_file, "w") as f: | ||
f.write(skip) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser( | ||
description="Generate skip file from ef tests logs" | ||
) | ||
parser.add_argument("input_file", help="Input file path") | ||
parser.add_argument("output_file", help="Output file path") | ||
|
||
skip_dict = defaultdict(list) | ||
for [folder, file] in matches_failed: | ||
skip_dict[folder].append(file) | ||
args = parser.parse_args() | ||
|
||
skip = "filename:\n" | ||
for folder in skip_dict: | ||
skip += f" {folder}:\n" | ||
for file in skip_dict[folder]: | ||
skip += f" - {file[5:]}\n" | ||
input_file = args.input_file | ||
output_file = args.output_file | ||
|
||
with open("blockchain-tests-skip.yml", "w") as f: | ||
f.write(skip) | ||
parse_and_write_to_yaml(input_file, output_file) |