@@ -16,7 +16,7 @@ def is_empty(value):
1616def trace_test_cases_to_annos (db_path : Path , trace_file_path : Path ):
1717 db = DbClient (db_path )
1818
19- test_cases = set ()
19+ insertions = list ()
2020 logger .info ("Reading trace file and inserting annotations into table..." )
2121 with open (trace_file_path , mode = 'r' , newline = '' , encoding = 'utf-8' ) as trace_file :
2222 reader = csv .reader (trace_file )
@@ -29,27 +29,24 @@ def trace_test_cases_to_annos(db_path: Path, trace_file_path: Path):
2929 current_tc = row [1 ]
3030 test_script = EMPTY
3131 concat_summary = EMPTY
32- if not is_empty (current_tc ):
33- test_cases .add (current_tc )
3432 next (reader )
3533 elif row [0 ] == "Summary" :
3634 continue
3735 elif row [0 ] == "TestCaseEnd" :
3836 if not is_empty (current_tc ) and not is_empty (concat_summary ):
39- case_id = db .test_cases .insert (test_script = test_script , test_case = current_tc )
40- annotation_id = db .annotations .insert (summary = concat_summary )
41- db .cases_to_annos .insert (case_id = case_id , annotation_id = annotation_id )
37+ case_id = db .test_cases .get_or_insert (test_script = test_script , test_case = current_tc )
38+ annotation_id = db .annotations .get_or_insert (summary = concat_summary )
39+ insertions . append ( db .cases_to_annos .insert (case_id = case_id , annotation_id = annotation_id ) )
4240 else :
4341 if not is_empty (row [global_columns .index ("TestCase" )]):
4442 if current_tc != row [global_columns .index ("TestCase" )]:
4543 current_tc = row [global_columns .index ("TestCase" )]
46- test_cases .add (current_tc )
4744 if is_empty (test_script ) and not is_empty (row [global_columns .index ("TestScript" )]):
4845 test_script = row [global_columns .index ("TestScript" )]
4946 concat_summary += row [0 ]
5047
5148 db .conn .commit ()
52- logger .info (f"Inserted { len (test_cases )} testcase-annotations pairs to database." )
49+ logger .info (f"Inserted { len (insertions )} testcase-annotations pairs to database. Successful: { sum ( insertions ) } " )
5350
5451
5552if __name__ == '__main__' :
0 commit comments