Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into jgfouca/ignore_diff…
Browse files Browse the repository at this point in the history
…s_option

* origin/master:
  Removes workflow trigger
  Fixes black formatting
  Fixes finding termination message in logs
  Fix test
  Remove unneeded test
  Fixes ternary condition for testing jobs
  Trigger testing/building workflow
  Fixes workflow for forked repo pr
  case.submit: Always try to download input data
  • Loading branch information
jgfouca committed Mar 8, 2024
2 parents b3ed1b1 + eb13e2c commit 1b64379
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 20 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ permissions:
jobs:
build-containers:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
permissions:
packages: write
steps:
Expand Down Expand Up @@ -91,7 +92,7 @@ jobs:
if: ${{ github.event_name == 'pull_request' && always() && ! cancelled() }}
needs: build-containers
container:
image: ghcr.io/esmci/cime:sha-${{ github.sha }}
image: ghcr.io/esmci/cime:${{ github.event.pull_request.head.repo.full_name == github.repository && format('sha-{0}', github.sha) || 'latest' }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -127,7 +128,7 @@ jobs:
if: ${{ github.event_name == 'pull_request' && always() && ! cancelled() }}
needs: build-containers
container:
image: ghcr.io/esmci/cime:sha-${{ github.sha }}
image: ghcr.io/esmci/cime:${{ github.event.pull_request.head.repo.full_name == github.repository && format('sha-{0}', github.sha) || 'latest' }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
Expand Down
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
4 changes: 2 additions & 2 deletions CIME/case/case_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ def check_case(self, skip_pnl=False, chksum=False):
self.check_lockedfiles()
if not skip_pnl:
self.create_namelists() # Must be called before check_all_input_data

logger.info("Checking that inputdata is available as part of case submission")
if not self.get_value("TEST"):
self.check_all_input_data(chksum=chksum)
self.check_all_input_data(chksum=chksum)

if self.get_value("COMP_WAV") == "ww":
# the ww3 buildnml has dependencies on inputdata so we must run it again
Expand Down
10 changes: 1 addition & 9 deletions CIME/tests/test_unit_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,11 @@ class TestCaseSubmit(unittest.TestCase):
def test_check_case(self):
case = mock.MagicMock()
# get_value arguments TEST, COMP_WAV, COMP_INTERFACE, BUILD_COMPLETE
case.get_value.side_effect = [False, "", "", True]
case.get_value.side_effect = ["", "", True]
case_submit.check_case(case, chksum=True)

case.check_all_input_data.assert_called_with(chksum=True)

def test_check_case_test(self):
case = mock.MagicMock()
# get_value arguments TEST, COMP_WAV, COMP_INTERFACE, BUILD_COMPLETE
case.get_value.side_effect = [True, "", "", True]
case_submit.check_case(case, chksum=True)

case.check_all_input_data.assert_not_called()

@mock.patch("CIME.case.case_submit.lock_file")
@mock.patch("CIME.case.case_submit.unlock_file")
@mock.patch("os.path.basename")
Expand Down
50 changes: 50 additions & 0 deletions CIME/tests/test_unit_case_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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 1b64379

Please sign in to comment.