From a424abeedfc0b3cefa1772e791a7730453bee31e Mon Sep 17 00:00:00 2001 From: Micael Oliveira Date: Fri, 19 Sep 2025 09:28:12 +1000 Subject: [PATCH] Handle case where the FMS profiling data parser is unable to find a match. --- src/access/parsers/fms_profiling.py | 6 +++++- tests/test_fms_profiling.py | 23 +++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/access/parsers/fms_profiling.py b/src/access/parsers/fms_profiling.py index db6e1df..cdb0015 100644 --- a/src/access/parsers/fms_profiling.py +++ b/src/access/parsers/fms_profiling.py @@ -56,7 +56,11 @@ def read(self, stream: str) -> dict: # Parse data stats = {"region": []} stats.update({m: [] for m in self.metrics}) - profiling_section = profiling_section_p.search(stream).group(1) + match = profiling_section_p.search(stream) + if match == None: + raise ValueError("No FMS profiling data found") + else: + profiling_section = match.group(1) for line in profiling_region_p.finditer(profiling_section): stats["region"].append(line.group("region")) for metric in self.metrics: diff --git a/tests/test_fms_profiling.py b/tests/test_fms_profiling.py index 59a5518..8834167 100644 --- a/tests/test_fms_profiling.py +++ b/tests/test_fms_profiling.py @@ -123,7 +123,7 @@ def fms_hits_profiling(): @pytest.fixture(scope="module") def fms_hits_log_file(): - """Fixture returning a dict holding the parsed FMS timing content wiht hits.""" + """Fixture returning the FMS timing content with hits.""" return """ MPP_DOMAINS_STACK high water mark= 380512 Tabulating mpp_clock statistics across 1 PEs... @@ -144,6 +144,19 @@ def fms_hits_log_file(): """ +@pytest.fixture(scope="module") +def fms_incorrect_log_file(): + """Fixture returning an incorrect FMS timing content.""" + return """ MPP_DOMAINS_STACK high water mark= 380512 + +Tabulating mpp_clock statistics across 1 PEs... + + hits tmax tavg tstd tfrac grain pemin pemax +Total runtime 1 100.641190 100.641190 100.641190 0.000000 1.000 0 0 0 +high water mark= 0 +""" + + def test_fms_nohits_profiling(fms_nohits_parser, fms_nohits_log_file, fms_nohits_profiling): """Test the correct parsing of FMS timing information without hits column.""" 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 ), f"Incorrect {metric} for region {region} (idx: {idx})." -def test_mom6_profiling(fms_hits_parser, fms_hits_log_file, fms_hits_profiling): +def test_fms_hits_profiling(fms_hits_parser, fms_hits_log_file, fms_hits_profiling): """Test the correct parsing of FMS timing information with hits column.""" parsed_log = fms_hits_parser.read(fms_hits_log_file) 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): assert ( fms_hits_profiling[metric][idx] == parsed_log[metric][idx] ), f"Incorrect {metric} for region {region} (idx: {idx})." + + +def test_fms_incorrect_profiling(fms_hits_parser, fms_incorrect_log_file): + """Test the parsing of incorrect FMS timing information.""" + with pytest.raises(ValueError): + fms_hits_parser.read(fms_incorrect_log_file)