blob: 2dabafe856909b0e340d7145cd9a2cb434663079 [file] [log] [blame]
Anna Arhipova7cdcc852023-11-15 18:20:45 +01001from parse import parse
2from typing import Dict, List
3
4
5def parse_title(test_name):
6 # Sometimes id can be without the closing ] symbol
7 if "[" in test_name and "]" not in test_name:
8 test_name += "]"
9 token_count = test_name.split(".").__len__()
10
11 if test_name.startswith("=="):
12 return test_name
13
14 if test_name.startswith(".setUp") or test_name.startswith(".tearDown"):
15 fmt = "{test_title}(" + "{}." * (token_count - 2) + "{class_name})"
16 r = parse(fmt, test_name)
17 return f"{r['class_name']}.{r['test_title']}".strip()
18 try:
19 fmt = "{}." * (token_count - 2) + "{class_name}.{test_title}[{id}]"
20 r = parse(fmt, test_name)
21 return f"{r['test_title']}[{r['id']}]"
22 except TypeError:
23 # return file_name.test_class.test_name in other complicated cases
24 return '.'.join(test_name.split(".")[:3])
25
26
27def short_names_for_dict(_dict):
28 __dict = {}
29 for _k in _dict.keys():
30 __k = parse_title(_k)
31 # Replace only those keys which are absent in the dict or empty
32 # (defined as "No result found")
33 if __dict.get(__k) == "No result found" or not __dict.get(__k):
34 __dict[__k] = _dict[_k]
35 return __dict
36
37
38def get_dict_diff(dict1: dict,
39 dict2: dict,
40 compare_by_key=None) -> Dict[str, List]:
41 all_keys = sorted(set(list(dict1.keys()) + list(dict2.keys())))
42
43 result = dict()
44 for k in all_keys:
45 if compare_by_key:
46 if dict1.get(k, {}).get(compare_by_key) == dict2.get(k, {}).get(
47 compare_by_key):
48 continue
49 else:
50 if dict1.get(k) == dict2.get(k):
51 continue
52 result[k] = [dict1.get(k), dict2.get(k)]
53 return result
54
55
56if __name__ == "__main__":
57 pass