-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_report.py
97 lines (89 loc) · 2.89 KB
/
new_report.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
class Report:
def __init__(
self,
include_error_data: bool = False,
max_count_error_data: int = 1000,
):
self.include_error_data = include_error_data
self.max_count_error_data = max_count_error_data
self.success_dict = 0
self.success_data = 0
self.error_in_dict = 0
self.error_in_data = 0
self.error_in_other = 0
self.summary_report = {}
if include_error_data:
self.dict_errors = []
self.data_errors = []
self.other_errors = []
def add_success_dict_message(
self,
increment: int = 1,
):
self.success_dict += increment
def add_success_data_message(
self,
increment: int = 1,
):
self.success_data += increment
def add_error_dict_message(
self,
increment: int = 1,
exception=None,
data=None,
index=None,
):
self.error_in_dict += increment
if self.include_error_data:
if self.error_in_dict < self.max_count_error_data or self.max_count_error_data == 0:
error_report = {
'exception': exception,
'index': index,
'data': data,
}
self.dict_errors.append(error_report)
def add_error_data_message(
self,
increment: int = 1,
exception=None,
data=None,
index=None,
):
self.error_in_data += increment
if self.include_error_data:
if self.error_in_data < self.max_count_error_data or self.max_count_error_data == 0:
error_report = {
'exception': exception,
'index': index,
'data': data,
}
self.data_errors.append(error_report)
def add_error_other_message(
self,
increment: int = 1,
exception=None,
data=None,
index=None,
):
self.error_in_other += increment
if self.include_error_data:
if self.error_in_other < self.max_count_error_data or self.max_count_error_data == 0:
error_report = {
'exception': exception,
'index': index,
'data': data,
}
self.other_errors.append(error_report)
def serialize(
self,
location: str = 'both',
):
valid_locations = ['dict', 'data', 'both']
if location not in valid_locations:
return f'Invalid location. Choose one {valid_locations}'
if location == 'dict':
pass
if location == 'data':
pass
if location == 'both':
pass