Skip to content

Commit 19c4678

Browse files
committed
add tests for raised errors in payujson parsers
1 parent 6ac2ba9 commit 19c4678

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/access/parsers/payujson_profiling.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ def read(self, stream: str) -> dict:
4848

4949
# remove known keys not relevant to profiling
5050
for unwanted_key in ("payu_start_time", "payu_finish_time"):
51-
try:
51+
if unwanted_key in timings:
5252
del timings[unwanted_key]
53-
except KeyError:
54-
continue
5553

5654
result = {"regions": [], "walltime": []}
5755

tests/test_payujson_profiling.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,18 @@ def payujson_log_file():
5454

5555
def test_payujson_profiling(payujson_parser, payujson_log_file, payujson_profiling):
5656
"""Test the correct parsing of Payu JSON timing information."""
57+
assert "walltime" in payujson_parser.metrics, "walltime metric not found in parsed log."
5758
parsed_log = payujson_parser.read(payujson_log_file)
5859
for idx, region in enumerate(payujson_profiling.keys()):
59-
assert region in parsed_log, f"{region} not found in Payu JSON parsed log"
60+
assert region in parsed_log, f"{region} not found in Payu JSON parsed log."
6061
assert (
6162
payujson_profiling["walltime"][idx] == parsed_log["walltime"][idx]
6263
), f"Incorrect walltime for region {region} (idx: {idx})."
64+
65+
66+
def test_payujson_errors(payujson_parser):
67+
"""Test that exceptions get raised appropriately."""
68+
with pytest.raises(KeyError):
69+
payujson_parser.read('{"a": 123}')
70+
with pytest.raises(ValueError):
71+
payujson_parser.read("abc def")

0 commit comments

Comments
 (0)