Skip to content

Commit 97e2e8f

Browse files
author
anna.yamkovaya
committed
couple of improvements
1 parent 85d6493 commit 97e2e8f

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

convert_trace_annos.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,50 @@
66
logging.basicConfig(level=logging.INFO)
77
logger = logging.getLogger(__name__)
88

9+
EMPTY = ""
10+
11+
12+
def is_empty(value):
13+
return True if value == EMPTY else False
14+
15+
916
def trace_test_cases_to_annos(db_path: Path, trace_file_path: Path):
1017
db = DbClient(db_path)
1118

1219
test_cases = set()
1320
logger.info("Reading trace file and inserting annotations into table...")
1421
with open(trace_file_path, mode='r', newline='', encoding='utf-8') as trace_file:
1522
reader = csv.reader(trace_file)
16-
current_tc = ""
17-
concat_summary = ""
18-
test_script = ""
23+
current_tc = EMPTY
24+
concat_summary = EMPTY
25+
test_script = EMPTY
1926
global_columns = next(reader)
2027
for row in reader:
2128
if row[0] == "TestCaseStart":
2229
current_tc = row[1]
23-
test_script = ""
24-
concat_summary = ""
25-
if current_tc != "":
30+
test_script = EMPTY
31+
concat_summary = EMPTY
32+
if not is_empty(current_tc):
2633
test_cases.add(current_tc)
2734
next(reader)
2835
elif row[0] == "Summary":
2936
continue
3037
elif row[0] == "TestCaseEnd":
31-
if current_tc != "" and concat_summary != "":
38+
if not is_empty(current_tc) and not is_empty(concat_summary):
3239
case_id = db.test_cases.insert(test_script=test_script, test_case=current_tc)
3340
annotation_id = db.annotations.insert(summary=concat_summary)
3441
db.cases_to_annos.insert(case_id=case_id, annotation_id=annotation_id)
3542
else:
36-
if row[global_columns.index("TestCase")] != "":
43+
if not is_empty(row[global_columns.index("TestCase")]):
3744
if current_tc != row[global_columns.index("TestCase")]:
3845
current_tc = row[global_columns.index("TestCase")]
3946
test_cases.add(current_tc)
40-
if test_script == "" and row[global_columns.index("TestScript")] != "":
47+
if is_empty(test_script) and not is_empty(row[global_columns.index("TestScript")]):
4148
test_script = row[global_columns.index("TestScript")]
4249
concat_summary += row[0]
4350

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

4754

4855
if __name__ == '__main__':

0 commit comments

Comments
 (0)