-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_excel_report.py
More file actions
201 lines (170 loc) · 6.56 KB
/
test_excel_report.py
File metadata and controls
201 lines (170 loc) · 6.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import datetime
from collections import deque
import polars as pl
import pytest
from dve.core_engine.message import FeedbackMessage
from dve.pipeline.utils import SubmissionStatus
from dve.reporting.error_report import (
create_error_dataframe,
generate_report_dataframes,
get_error_codes,
populate_error_codes,
)
from dve.reporting.excel_report import ExcelFormat, SummaryItems
from ..conftest import get_test_file_path
from ..fixtures import temp_dir
@pytest.fixture(scope="function")
def planet_error_codes():
codes = get_test_file_path("planets/error_codes.json")
return get_error_codes(codes.as_posix())
@pytest.fixture(scope="function")
def planet_errors():
return deque(
[
FeedbackMessage(
entity="Planet",
record={
"id": 1,
"name": None,
"mass": 0.33,
"diameter": 4879.0,
"density": 5427.0,
"gravity": 3.7,
"escapeVelocity": 4.3,
"rotationPeriod": 1407.6,
"lengthOfDay": 4222.6,
"distanceFromSun": 57.9,
"perihelion": 46.0,
"aphelion": 69.8,
"orbitalPeriod": 88.0,
"orbitalVelocity": 47.4,
"orbitalInclination": 7.0,
"orbitalEccentricity": 0.205,
"obliquityToOrbit": 0.034,
"meanTemperature": 167.0,
"surfacePressure": 0.0,
"numberOfMoons": 0,
"hasRingSystem": False,
"hasGlobalMagneticField": False,
},
failure_type="record",
is_informational=True,
error_type="Blank Value",
error_location="name",
error_message="is blank",
error_code="001",
reporting_field="name",
value=None,
category="Blank",
)
]
)
@pytest.fixture(scope="function")
def planet_error_df(planet_errors):
return create_error_dataframe(planet_errors, {"Planet": "Planet"})
@pytest.fixture(scope="function")
def report_dfs(planet_errors, planet_error_codes):
return generate_report_dataframes(planet_errors, planet_error_codes, {})
@pytest.fixture(scope="function")
def big_report_dfs(planet_errors, planet_error_codes):
errors = list(planet_errors) * 31
return generate_report_dataframes(errors, planet_error_codes, {})
def test_populate_error_codes(temp_dir, planet_error_codes, planet_error_df):
error_frame = populate_error_codes(planet_error_df, planet_error_codes)
assert list(error_frame["Error_Code"]) == ["001"]
def test_generate_report_dfs(planet_errors, planet_error_codes):
error_df, aggregates_df = generate_report_dataframes(planet_errors, planet_error_codes, {})
assert error_df["Category"].to_list() == ["Blank"]
assert aggregates_df["Count"].to_list() == [1]
def test_excel_report(report_dfs):
report = ExcelFormat(*report_dfs)
summary_items = SummaryItems(
summary_dict={
"Sender": "X26",
"Datetime_sent": datetime.datetime.now(),
"Datetime_processed": datetime.datetime.now(),
},
row_headings=["Submission Failure", "Warning"],
table_columns=["Planet", "Derived"],
)
workbook = report.excel_format(summary_items=summary_items)
assert workbook.sheetnames == ["Summary", "Error Summary", "Error Data"]
assert workbook["Summary"]["B2"].value == "Data Summary"
aggs = workbook["Error Summary"]
column_headings = [cell.value for cell in aggs["1"]]
assert column_headings == [
"Type",
"Group",
"Data Item Submission Name",
"Category",
"Error Code",
"Count",
]
details = workbook["Error Data"]
column_headings = [cell.value for cell in details["1"]]
assert column_headings == [
"Group",
"Type",
"Error Code",
"Data Item Submission Name",
"Errors and Warnings",
"Value",
"ID",
"Category",
]
def test_excel_report_overflow(big_report_dfs):
error_df, aggregate_df = big_report_dfs
error_dfs = {"MilkyWay": error_df}
report = ExcelFormat(error_dfs, aggregate_df, overflow=20)
summary_items = SummaryItems(
summary_dict={
"Sender": "X26",
"Datetime_sent": datetime.datetime.now(),
"Datetime_processed": datetime.datetime.now(),
},
row_headings=["Submission Failure", "Warning"],
table_columns=["Planet", "Derived"],
)
workbook = report.excel_format(
summary_items=summary_items,
)
assert workbook.sheetnames == [
"Summary",
"Error Summary",
"MilkyWay",
"MilkyWay_2",
]
def test_excel_report_empty_dfs():
"""Test that error reports with empty dataframes still produce the correct sheets
but without anything other than the headers in those sheets"""
report = ExcelFormat(pl.DataFrame(), pl.DataFrame(), overflow=20)
summary_items = SummaryItems(
summary_dict={
"Sender": "X26",
"Datetime_sent": datetime.datetime.now(),
"Datetime_processed": datetime.datetime.now(),
},
row_headings=["Submission Failure", "Warning"],
table_columns=["Planet", "Derived"],
)
workbook = report.excel_format(
summary_items=summary_items,
)
assert workbook.sheetnames == ["Summary", "Error Summary", "Error Data"]
assert not all(cell.value for cell in workbook["Error Data"]["2"]) # no errors
assert not all(cell.value for cell in workbook["Error Summary"]["2"]) # no aggregates
def test_sub_status_failed_processing():
"""Check that the submission status is used to determine the """
summary_items = SummaryItems(
submission_status=SubmissionStatus(processing_failed=True),
summary_dict={
"Sender": "X26",
"Datetime_sent": datetime.datetime.now(),
"Datetime_processed": datetime.datetime.now(),
},
row_headings=["Submission Failure", "Warning"],
table_columns=["Planet", "Derived"],
)
assert summary_items.get_submission_status(pl.DataFrame()) == "There was an issue processing the submission. This will be investigated."
summary_items.submission_status = SubmissionStatus(validation_failed=True)
assert summary_items.get_submission_status(pl.DataFrame()) == "File has been rejected"