Skip to content

Commit

Permalink
Use argparser to make the script a CLI tool (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementWalter authored Jan 17, 2024
1 parent 2b5d7b9 commit f9f2313
Showing 1 changed file with 52 additions and 33 deletions.
85 changes: 52 additions & 33 deletions scripts/generate_skip_file.py
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)

0 comments on commit f9f2313

Please sign in to comment.