Skip to content

Commit 287eb1f

Browse files
Handle case where the FMS profiling data parser is unable to find a match.
1 parent d178fb9 commit 287eb1f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/access/parsers/fms_profiling.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ def read(self, stream: str) -> dict:
5656
# Parse data
5757
stats = {"region": []}
5858
stats.update({m: [] for m in self.metrics})
59-
profiling_section = profiling_section_p.search(stream).group(1)
59+
match = profiling_section_p.search(stream)
60+
if match == None:
61+
raise ValueError("No FMS profiling data found")
62+
else:
63+
profiling_section = match.group(1)
6064
for line in profiling_region_p.finditer(profiling_section):
6165
stats["region"].append(line.group("region"))
6266
for metric in self.metrics:

tests/test_fms_profiling.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def fms_hits_profiling():
123123

124124
@pytest.fixture(scope="module")
125125
def fms_hits_log_file():
126-
"""Fixture returning a dict holding the parsed FMS timing content wiht hits."""
126+
"""Fixture returning the FMS timing content with hits."""
127127
return """ MPP_DOMAINS_STACK high water mark= 380512
128128
129129
Tabulating mpp_clock statistics across 1 PEs...
@@ -144,6 +144,19 @@ def fms_hits_log_file():
144144
"""
145145

146146

147+
@pytest.fixture(scope="module")
148+
def fms_incorrect_log_file():
149+
"""Fixture returning an incorrect FMS timing content."""
150+
return """ MPP_DOMAINS_STACK high water mark= 380512
151+
152+
Tabulating mpp_clock statistics across 1 PEs...
153+
154+
hits tmax tavg tstd tfrac grain pemin pemax
155+
Total runtime 1 100.641190 100.641190 100.641190 0.000000 1.000 0 0 0
156+
high water mark= 0
157+
"""
158+
159+
147160
def test_fms_nohits_profiling(fms_nohits_parser, fms_nohits_log_file, fms_nohits_profiling):
148161
"""Test the correct parsing of FMS timing information without hits column."""
149162
parsed_log = fms_nohits_parser.read(fms_nohits_log_file)
@@ -155,7 +168,7 @@ def test_fms_nohits_profiling(fms_nohits_parser, fms_nohits_log_file, fms_nohits
155168
), f"Incorrect {metric} for region {region} (idx: {idx})."
156169

157170

158-
def test_mom6_profiling(fms_hits_parser, fms_hits_log_file, fms_hits_profiling):
171+
def test_fms_hits_profiling(fms_hits_parser, fms_hits_log_file, fms_hits_profiling):
159172
"""Test the correct parsing of FMS timing information with hits column."""
160173
parsed_log = fms_hits_parser.read(fms_hits_log_file)
161174
for idx, region in enumerate(fms_hits_profiling.keys()):
@@ -164,3 +177,9 @@ def test_mom6_profiling(fms_hits_parser, fms_hits_log_file, fms_hits_profiling):
164177
assert (
165178
fms_hits_profiling[metric][idx] == parsed_log[metric][idx]
166179
), f"Incorrect {metric} for region {region} (idx: {idx})."
180+
181+
182+
def test_fms_incorrect_profiling(fms_hits_parser, fms_incorrect_log_file):
183+
"""Test the parsing of incorrect FMS timing information."""
184+
with pytest.raises(ValueError):
185+
fms_hits_parser.read(fms_incorrect_log_file)

0 commit comments

Comments
 (0)