|
6 | 6 | logging.basicConfig(level=logging.INFO) |
7 | 7 | logger = logging.getLogger(__name__) |
8 | 8 |
|
| 9 | +EMPTY = "" |
| 10 | + |
| 11 | + |
| 12 | +def is_empty(value): |
| 13 | + return True if value == EMPTY else False |
| 14 | + |
| 15 | + |
9 | 16 | def trace_test_cases_to_annos(db_path: Path, trace_file_path: Path): |
10 | 17 | db = DbClient(db_path) |
11 | 18 |
|
12 | 19 | test_cases = set() |
13 | 20 | logger.info("Reading trace file and inserting annotations into table...") |
14 | 21 | with open(trace_file_path, mode='r', newline='', encoding='utf-8') as trace_file: |
15 | 22 | 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 |
19 | 26 | global_columns = next(reader) |
20 | 27 | for row in reader: |
21 | 28 | if row[0] == "TestCaseStart": |
22 | 29 | 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): |
26 | 33 | test_cases.add(current_tc) |
27 | 34 | next(reader) |
28 | 35 | elif row[0] == "Summary": |
29 | 36 | continue |
30 | 37 | elif row[0] == "TestCaseEnd": |
31 | | - if current_tc != "" and concat_summary != "": |
| 38 | + if not is_empty(current_tc) and not is_empty(concat_summary): |
32 | 39 | case_id = db.test_cases.insert(test_script=test_script, test_case=current_tc) |
33 | 40 | annotation_id = db.annotations.insert(summary=concat_summary) |
34 | 41 | db.cases_to_annos.insert(case_id=case_id, annotation_id=annotation_id) |
35 | 42 | else: |
36 | | - if row[global_columns.index("TestCase")] != "": |
| 43 | + if not is_empty(row[global_columns.index("TestCase")]): |
37 | 44 | if current_tc != row[global_columns.index("TestCase")]: |
38 | 45 | current_tc = row[global_columns.index("TestCase")] |
39 | 46 | 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")]): |
41 | 48 | test_script = row[global_columns.index("TestScript")] |
42 | 49 | concat_summary += row[0] |
43 | 50 |
|
44 | 51 | 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.") |
46 | 53 |
|
47 | 54 |
|
48 | 55 | if __name__ == '__main__': |
|
0 commit comments