forked from UnitTestBot/UTBotJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
56 lines (47 loc) · 1.56 KB
/
utils.py
File metadata and controls
56 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import re
from collections import defaultdict
from typing import List
from monitoring_settings import DEFAULT_PROJECT_VERSION
def parse_name_and_version(full_name: str) -> tuple[str, str]:
"""
Parse from string name and version of project
:param full_name: string with format <name>-<version>
:return: pair of name and version strings
"""
regex = re.compile(r'([^.]+)-([\d.]+)')
result = regex.fullmatch(full_name)
if result is None:
return full_name, DEFAULT_PROJECT_VERSION
name = result.group(1)
version = result.group(2)
return name, version
def postprocess_targets(targets: dict) -> List[dict]:
"""
Transform dictionary with fullname target keys into array with target objects
:param targets: dictionary with fullname target keys
:return: array of targets
"""
result = []
for target in targets:
(name, version) = parse_name_and_version(target)
result.append({
'id': name,
'version': version,
**targets[target]
})
return result
def get_default_metrics_dict() -> dict:
return defaultdict(lambda: {
'parameters': [],
'metrics': []
})
def update_target(target: dict, stats: dict) -> dict:
"""
Update dictionary with target by new stats
:param target: dictionary with target metrics and parameters
:param stats: new metrics and parameters
:return: updated target dictionary
"""
target['parameters'].append(stats['parameters'])
target['metrics'].append(stats['metrics'])
return target