forked from wandb/wandb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
70 lines (52 loc) · 1.81 KB
/
conftest.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from queue import Queue
from typing import Callable, Dict, Generator, List
import pytest
# --------------------------------
# Fixtures for user test point
# --------------------------------
class RecordsUtil:
def __init__(self, queue: "Queue") -> None:
self.records = []
while not queue.empty():
self.records.append(queue.get())
def __len__(self) -> int:
return len(self.records)
def __getitem__(self, name: str) -> Generator:
for record in self.records:
yield from self.resolve_item(record, name)
@staticmethod
def resolve_item(obj, attr: str, sep: str = ".") -> List:
for name in attr.split(sep):
if not obj.HasField(name):
return []
obj = getattr(obj, name)
return [obj]
@staticmethod
def dictify(obj, key: str = "key", value: str = "value_json") -> Dict:
return {getattr(item, key): getattr(item, value) for item in obj}
@property
def config(self) -> List:
return [self.dictify(_c.update) for _c in self["config"]]
@property
def history(self) -> List:
return [self.dictify(_h.item) for _h in self["history"]]
@property
def partial_history(self) -> List:
return [self.dictify(_h.item) for _h in self["request.partial_history"]]
@property
def preempting(self) -> List:
return list(self["preempting"])
@property
def summary(self) -> List:
return list(self["summary"])
@property
def files(self) -> List:
return list(self["files"])
@property
def metric(self):
return list(self["metric"])
@pytest.fixture
def parse_records() -> Generator[Callable, None, None]:
def records_parser_fn(q: "Queue") -> RecordsUtil:
return RecordsUtil(q)
yield records_parser_fn