Skip to content

Commit 4e8f504

Browse files
authored
Merge pull request #555 from powerapi-ng/fix/csv-hwpc-report-creation
fix(report/hwpc): Raise `BadInputData` exception when csv line is incomplete
2 parents 5e9ff89 + 7bd26cc commit 4e8f504

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/powerapi/report/hwpc_report.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ def from_csv_lines(lines: CsvLines) -> HWPCReport:
156156
if timestamp != HWPCReport._extract_timestamp(row[TIMESTAMP_KEY]):
157157
raise BadInputData('csv line with different timestamp are mixed into one report', row)
158158

159+
for _, value in row.items():
160+
if not value:
161+
raise BadInputData('csv line incomplete', row)
162+
159163
HWPCReport._create_group(row, groups, group_name)
160164

161165
except KeyError as exn:

tests/unit/report/test_hwpc_report.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ def test_create_hwpc_report_from_csv_without_socket_field_raise_BadInputData():
149149
_ = HWPCReport.from_csv_lines(csv_lines)
150150

151151

152+
def test_create_hwpc_report_from_csv_without_some_values_raise_BadInputData():
153+
csv_lines = [('rapl',
154+
{'sensor': 'toto', 'timestamp': '1970-09-01T09:09:09.543', 'target': 'all', 'socket': '0', 'cpu': '7',
155+
'RAPL_VALUE': None}),
156+
('rapl',
157+
{'sensor': 'toto', 'timestamp': '1970-09-01T09:09:09.543', 'target': 'all', 'socket': '1', 'cpu': '7',
158+
'RAPL_VALUE': None})]
159+
with pytest.raises(BadInputData):
160+
_ = HWPCReport.from_csv_lines(csv_lines)
161+
162+
152163
############
153164
# EVENTS #
154165
############

0 commit comments

Comments
 (0)