Skip to content

Commit

Permalink
Fixes finding termination message in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonb5 committed Feb 22, 2024
1 parent 12142ee commit 9d7f460
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
10 changes: 3 additions & 7 deletions CIME/case/case_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import shutil, time, sys, os, glob

TERMINATION_TEXT = ("HAS ENDED", "END OF MODEL RUN", "SUCCESSFUL TERMINATION")

logger = logging.getLogger(__name__)

###############################################################################
Expand Down Expand Up @@ -331,13 +333,7 @@ def _post_run_check(case, lid):
break
with open(cpl_logfile, "r") as fd:
logfile = fd.read()
if (
comp_standalone
and "HAS ENDED" in logfile
or "END OF MODEL RUN" in logfile
):
count_ok += 1
elif not comp_standalone and "SUCCESSFUL TERMINATION" in logfile:
if any([x in logfile for x in TERMINATION_TEXT]):
count_ok += 1
if count_ok < cpl_ninst:
expect(False, "Model did not complete - see {} \n ".format(cpl_logfile))
Expand Down
49 changes: 49 additions & 0 deletions CIME/tests/test_unit_case_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import unittest
from unittest import mock

from CIME.utils import CIMEError
from CIME.case.case_run import TERMINATION_TEXT
from CIME.case.case_run import _post_run_check

def _case_post_run_check():
case = mock.MagicMock()

# RUNDIR, COMP_INTERFACE, COMP_CPL, COMP_ATM, COMP_OCN, MULTI_DRIVER
case.get_value.side_effect = (
"/tmp/run", "mct",
"cpl", "satm", "socn",
False
)

# COMP_CLASSES
case.get_values.return_value = ("CPL", "ATM", "OCN")

return case

class TestCaseSubmit(unittest.TestCase):
@mock.patch("os.stat")
@mock.patch("os.path.isfile")
def test_post_run_check(self, isfile, stat):
isfile.return_value = True

stat.return_value.st_size = 1024

# no exceptions means success
for x in TERMINATION_TEXT:
case = _case_post_run_check()

with mock.patch("builtins.open", mock.mock_open(read_data=x)) as mock_file:
_post_run_check(case, "1234")

@mock.patch("os.stat")
@mock.patch("os.path.isfile")
def test_post_run_check_no_termination(self, isfile, stat):
isfile.return_value = True

stat.return_value.st_size = 1024

case = _case_post_run_check()

with self.assertRaises(CIMEError):
with mock.patch("builtins.open", mock.mock_open(read_data="I DONT HAVE A TERMINATION MESSAGE")) as mock_file:
_post_run_check(case, "1234")

0 comments on commit 9d7f460

Please sign in to comment.