Skip to content

Commit 85d6493

Browse files
author
anna.yamkovaya
committed
improved reading of trace files
1 parent 47ecd2f commit 85d6493

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

convert_trace_annos.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,37 @@ def trace_test_cases_to_annos(db_path: Path, trace_file_path: Path):
1212
test_cases = set()
1313
logger.info("Reading trace file and inserting annotations into table...")
1414
with open(trace_file_path, mode='r', newline='', encoding='utf-8') as trace_file:
15-
reader = csv.DictReader(trace_file)
15+
reader = csv.reader(trace_file)
1616
current_tc = ""
1717
concat_summary = ""
18+
test_script = ""
19+
global_columns = next(reader)
1820
for row in reader:
19-
if row.get("TestCase", "") != "":
20-
if current_tc != row["TestCase"]:
21-
if current_tc:
22-
case_id = db.test_cases.insert(test_script=row["TestScript"], test_case=row["TestCase"])
23-
annotation_id = db.annotations.insert(summary=concat_summary)
24-
db.cases_to_annos.insert(case_id=case_id, annotation_id=annotation_id)
25-
concat_summary = ""
26-
current_tc = row["TestCase"]
21+
if row[0] == "TestCaseStart":
22+
current_tc = row[1]
23+
test_script = ""
24+
concat_summary = ""
25+
if current_tc != "":
2726
test_cases.add(current_tc)
28-
concat_summary += row["Summary"]
27+
next(reader)
28+
elif row[0] == "Summary":
29+
continue
30+
elif row[0] == "TestCaseEnd":
31+
if current_tc != "" and concat_summary != "":
32+
case_id = db.test_cases.insert(test_script=test_script, test_case=current_tc)
33+
annotation_id = db.annotations.insert(summary=concat_summary)
34+
db.cases_to_annos.insert(case_id=case_id, annotation_id=annotation_id)
35+
else:
36+
if row[global_columns.index("TestCase")] != "":
37+
if current_tc != row[global_columns.index("TestCase")]:
38+
current_tc = row[global_columns.index("TestCase")]
39+
test_cases.add(current_tc)
40+
if test_script == "" and row[global_columns.index("TestScript")] != "":
41+
test_script = row[global_columns.index("TestScript")]
42+
concat_summary += row[0]
2943

3044
db.conn.commit()
31-
logger.info(f"Inserted {len(test_cases)} testcase-annotations pairs to database.")
45+
logger.info(f"Inserted {len(test_cases)} testcase-annotations pairs to database.{[tc for tc in test_cases]}")
3246

3347

3448
if __name__ == '__main__':

0 commit comments

Comments
 (0)