From 59b0aa5dba479dd6770ee263607cff1f10cf4f8a Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Thu, 2 Jan 2025 07:50:52 -0700 Subject: [PATCH 01/15] sometimes this is the same file, avoid error in this case --- cime_config/SystemTests/ssp.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cime_config/SystemTests/ssp.py b/cime_config/SystemTests/ssp.py index bd554aeae9..a99a57a1e8 100644 --- a/cime_config/SystemTests/ssp.py +++ b/cime_config/SystemTests/ssp.py @@ -97,8 +97,10 @@ def run_phase(self): os.symlink(item, link_name) for item in glob.glob("{}/*rpointer*".format(rest_path)): - shutil.copy(item, rundir) - + try: + shutil.copy(item, rundir) + except shutil.SameFileError: + pass self._case.set_value("CLM_ACCELERATED_SPINUP", "off") self._case.set_value("RUN_TYPE", "hybrid") self._case.set_value("GET_REFCASE", False) From 3b42fc19fb556224b7e3f7d73e39044a85f2941d Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Tue, 14 Jan 2025 12:00:25 -0700 Subject: [PATCH 02/15] Move the same change from ssp.py to sspmatrix.py in regard for checking that rpointer files are the same --- cime_config/SystemTests/sspmatrixcn.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cime_config/SystemTests/sspmatrixcn.py b/cime_config/SystemTests/sspmatrixcn.py index 29b6dce8e6..2d7b55f004 100644 --- a/cime_config/SystemTests/sspmatrixcn.py +++ b/cime_config/SystemTests/sspmatrixcn.py @@ -248,8 +248,10 @@ def run_phase(self): os.symlink(item, linkfile) for item in glob.glob("{}/*rpointer*".format(rest_path)): - shutil.copy(item, rundir) - + try: + shutil.copy(item, rundir) + except shutil.SameFileError: + pass # # Run the case (Archiving on) # From 4b20bbd7003e6f77dab4e3268cc4a43f9b5a3b5d Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Tue, 14 Jan 2025 12:07:38 -0700 Subject: [PATCH 03/15] Run black --- cime_config/SystemTests/sspmatrixcn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cime_config/SystemTests/sspmatrixcn.py b/cime_config/SystemTests/sspmatrixcn.py index 2d7b55f004..e35c6dbf8e 100644 --- a/cime_config/SystemTests/sspmatrixcn.py +++ b/cime_config/SystemTests/sspmatrixcn.py @@ -249,9 +249,9 @@ def run_phase(self): for item in glob.glob("{}/*rpointer*".format(rest_path)): try: - shutil.copy(item, rundir) + shutil.copy(item, rundir) except shutil.SameFileError: - pass + pass # # Run the case (Archiving on) # From c6677bbe9d1683c998e9d3d22b74e32e71177a30 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Tue, 14 Jan 2025 12:08:18 -0700 Subject: [PATCH 04/15] Add a black commit --- .git-blame-ignore-revs | 1 + 1 file changed, 1 insertion(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 089e9fbb12..50dc3bdb0b 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -53,3 +53,4 @@ aa04d1f7d86cc2503b98b7e2b2d84dbfff6c316b 753fda3ff0147837231a73c9c728dd9ce47b5997 f112ba0bbf96a61d5a4d354dc0dcbd8b0c68145c bd535c710db78420b8e8b9d71d88d8339e899c59 +4b20bbd7003e6f77dab4e3268cc4a43f9b5a3b5d From 57b68fb7d1d8e8a4cfcfe771d097cf726563361c Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Thu, 16 Jan 2025 01:01:08 -0700 Subject: [PATCH 05/15] Remove unneeded copy of rpointer files --- cime_config/SystemTests/ssp.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cime_config/SystemTests/ssp.py b/cime_config/SystemTests/ssp.py index a99a57a1e8..92cab0a961 100644 --- a/cime_config/SystemTests/ssp.py +++ b/cime_config/SystemTests/ssp.py @@ -81,7 +81,7 @@ def run_phase(self): ) refsec = "00000" - # obtain rpointer files and necessary restart files from short term archiving directory + # obtain necessary restart files from short term archiving directory rundir = self._case.get_value("RUNDIR") rest_path = os.path.join(dout_sr, "rest", "{}-{}".format(refdate, refsec)) @@ -96,11 +96,6 @@ def run_phase(self): else: os.symlink(item, link_name) - for item in glob.glob("{}/*rpointer*".format(rest_path)): - try: - shutil.copy(item, rundir) - except shutil.SameFileError: - pass self._case.set_value("CLM_ACCELERATED_SPINUP", "off") self._case.set_value("RUN_TYPE", "hybrid") self._case.set_value("GET_REFCASE", False) From deaf9331f8f24264f366911d60ad20c9e23bbfca Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Thu, 16 Jan 2025 08:37:42 -0700 Subject: [PATCH 06/15] Fix so working now Copy the logic from other CIME SystemTests about setting the driver rpointer file for branch run types. (requires setting the file and DRV_RESTART_POINTER xml variable). --- cime_config/SystemTests/sspmatrixcn.py | 30 ++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/cime_config/SystemTests/sspmatrixcn.py b/cime_config/SystemTests/sspmatrixcn.py index e35c6dbf8e..b8c921ac5a 100644 --- a/cime_config/SystemTests/sspmatrixcn.py +++ b/cime_config/SystemTests/sspmatrixcn.py @@ -13,6 +13,7 @@ Step 4: matrix Spinup off """ import shutil, glob, os, sys +from datetime import datetime if __name__ == "__main__": CIMEROOT = os.environ.get("CIMEROOT") @@ -225,6 +226,7 @@ def run_phase(self): self.append_user_nl(clone_path, n) dout_sr = clone.get_value("DOUT_S_ROOT") + ninst = self._case.get_value("NINST") self._skip_pnl = False # @@ -247,9 +249,17 @@ def run_phase(self): os.makedirs(rundir) os.symlink(item, linkfile) - for item in glob.glob("{}/*rpointer*".format(rest_path)): + # For a branch the cpl rpointer file needs to be handled + if self.runtyp[n] is "branch": + + drvrest = "rpointer.cpl" + if ninst > 1: + drvrest += "_0001" + drvrest += rest_time + + self._set_drv_restart_pointer(drvrest) try: - shutil.copy(item, rundir) + shutil.copy(drvrest, rundir) except shutil.SameFileError: pass # @@ -269,6 +279,7 @@ def run_phase(self): ) refsec = "00000" rest_path = os.path.join(dout_sr, "rest", "{}-{}".format(refdate, refsec)) + rest_time = "." + refdate + "-" + refsec # # Last step in original case @@ -296,8 +307,19 @@ def run_phase(self): os.remove(linkfile) os.symlink(item, linkfile) - for item in glob.glob("{}/*rpointer*".format(rest_path)): - shutil.copy(item, rundir) + # For a branch the cpl rpointer file needs to be handled + if self.runtyp[n] is "branch": + + drvrest = "rpointer.cpl" + if ninst > 1: + drvrest += "_0001" + drvrest += rest_time + + self._set_drv_restart_pointer(drvrest) + try: + shutil.copy(os.path.join( rest_path, drvrest), rundir) + except shutil.SameFileError: + pass self.append_user_nl(clone_path, n) # From d226e84cd54e5d754ec8d11fdbf1b0062b2434a9 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Mon, 27 Jan 2025 14:57:50 -0700 Subject: [PATCH 07/15] Add the cmeps expected fail file to the list --- parse_cime.cs.status | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/parse_cime.cs.status b/parse_cime.cs.status index 264ba0708f..daaaef2293 100755 --- a/parse_cime.cs.status +++ b/parse_cime.cs.status @@ -332,7 +332,9 @@ sub print_categories { if ( ! -f $expectedfailfile ) { $expectedfailfile = "$scrdir/cime_config/testdefs/ExpectedTestFails.xml"; } - my @failfiles = ( $expectedfailfile, "$scrdir/components/mizuRoute/cime_config/testdefs/ExpectedTestFails.xml" ); + my @failfiles = ( $expectedfailfile, "$scrdir/components/mizuRoute/cime_config/testdefs/ExpectedTestFails.xml", + #"$scrdir/components/mosart/cime_config/testdefs/ExpectedTestFails.xml", + "$scrdir/components/cmeps/cime_config/ExpectedTestFails.xml" ); my @passes; my @fails; my @pendings; From 796246edb8adcb864a31a471a310ee82f08ccc9e Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Wed, 29 Jan 2025 00:49:30 -0700 Subject: [PATCH 08/15] Remove unit testing at the end and move to a real unit tester in the python directory --- cime_config/SystemTests/sspmatrixcn.py | 68 +----------- python/ctsm/test/test_unit_sspmatrix.py | 135 ++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 65 deletions(-) create mode 100755 python/ctsm/test/test_unit_sspmatrix.py diff --git a/cime_config/SystemTests/sspmatrixcn.py b/cime_config/SystemTests/sspmatrixcn.py index b8c921ac5a..a937cdfbf3 100644 --- a/cime_config/SystemTests/sspmatrixcn.py +++ b/cime_config/SystemTests/sspmatrixcn.py @@ -251,7 +251,7 @@ def run_phase(self): # For a branch the cpl rpointer file needs to be handled if self.runtyp[n] is "branch": - + drvrest = "rpointer.cpl" if ninst > 1: drvrest += "_0001" @@ -309,7 +309,7 @@ def run_phase(self): # For a branch the cpl rpointer file needs to be handled if self.runtyp[n] is "branch": - + drvrest = "rpointer.cpl" if ninst > 1: drvrest += "_0001" @@ -317,7 +317,7 @@ def run_phase(self): self._set_drv_restart_pointer(drvrest) try: - shutil.copy(os.path.join( rest_path, drvrest), rundir) + shutil.copy(os.path.join(rest_path, drvrest), rundir) except shutil.SameFileError: pass @@ -331,65 +331,3 @@ def run_phase(self): # self._case.flush() self.run_indv(suffix="step{}".format(self.steps[n]), st_archive=False) - - -# -# Unit testing for above -# -import unittest -from CIME.case import Case -from CIME.utils import _LessThanFilter -from argparse import RawTextHelpFormatter - - -class test_ssp_matrixcn(unittest.TestCase): - def setUp(self): - self.ssp = SSPMATRIXCN() - - def test_logger(self): - # Test the logger - stream_handler = logging.StreamHandler(sys.stdout) - logger.addHandler(stream_handler) - logger.level = logging.DEBUG - logger.info("nyr_forcing = {}".format(self.ssp.nyr_forcing)) - for n in range(self.ssp.n_steps()): - self.ssp.__logger__(n) - if self.ssp.spin[n] == "sasu": - logger.info(" SASU spinup is .true.") - if self.ssp.sasu[n] != -999: - logger.info(" nyr_sasu = {}".format(self.ssp.sasu[n])) - if self.ssp.iloop[n] != -999: - logger.info(" iloop_avg = {}".format(self.ssp.iloop[n])) - - logger.info("Total number of years {}".format(self.ssp.total_years())) - logger.removeHandler(stream_handler) - - def test_n_steps(self): - self.assertTrue(self.ssp.n_steps() == 3) - - def test_valid_n(self): - for n in range(self.ssp.n_steps()): - self.ssp.check_n(n) - - def test_negative_n(self): - self.assertRaises(SystemExit, self.ssp.check_n, -1) - - def test_n_too_big(self): - self.assertRaises(SystemExit, self.ssp.check_n, self.ssp.n_steps()) - - def test_append_user_nl_step2(self): - ufile = "user_nl_clm" - if not os.path.exists(ufile): - os.mknod(ufile) - else: - expect(0, ufile + " file already exists, not overwritting it") - - self.ssp.append_user_nl(caseroot=".", n=2) - print(ufile + " for step 2") - log = open(ufile, "r").read() - print(log) - os.remove(ufile) - - -if __name__ == "__main__": - unittest.main() diff --git a/python/ctsm/test/test_unit_sspmatrix.py b/python/ctsm/test/test_unit_sspmatrix.py new file mode 100755 index 0000000000..6f4c253014 --- /dev/null +++ b/python/ctsm/test/test_unit_sspmatrix.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python3 +""" +Unit tests for the SystemTest sspmatrix.pty + +You can run this by: + python -m unittest test_unit_sspmatrix.py +""" + +import unittest +import os +import sys +import tempfile +import shutil +import logging + +from ctsm.path_utils import add_cime_lib_to_path +from ctsm import unit_testing + +_CIME_PATH = add_cime_lib_to_path(standalone_only=True) + +# -- add python/ctsm to path (needed if we want to run the test stand-alone) +_CTSM_PYTHON = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, os.pardir) +_CTSM_SYSTEST_DIR = os.path.join(_CIME_PATH, os.pardir, "cime_config") +sys.path.insert(1, _CTSM_PYTHON) +sys.path.insert(1, _CTSM_SYSTEST_DIR) +# pylint: disable=wrong-import-order +# pylint: disable=wrong-import-position +from SystemTests.sspmatrixcn import SSPMATRIXCN + +# pylint: disable=wrong-import-order +# pylint: disable=wrong-import-position +from CIME.tests.case_fake import CaseFake + +# pylint: disable=invalid-name + +logger = logging.getLogger(__name__) + + +class TestSSPMatrix(unittest.TestCase): + """ + Basic class for testing the sspmatrix.py SystemTest + """ + + def setUp(self): + """ + Setup test directory + """ + self._previous_dir = os.getcwd() + self._tempdir = tempfile.mkdtemp() + + # Set up the testing CaseFake + caseroot = os.path.join(self._tempdir, "case") + self._case = CaseFake(caseroot, create_case_root=True) + os.chdir(caseroot) + + # Set XML variables that will be needed in the case + self._case.set_value("DATM_YR_START", 2000) + self._case.set_value("DATM_YR_END", 2001) + self._case.set_value("COMP_LND", "clm") + self._case.set_value("NINST", "1") + + self.ssp = SSPMATRIXCN(self._case) + + def tearDown(self): + """ + Remove temporary directory + """ + os.chdir(self._previous_dir) + shutil.rmtree(self._tempdir, ignore_errors=True) + + def test_logger(self): + """ + Test the logger + """ + stream_handler = logging.StreamHandler(sys.stdout) + logger.addHandler(stream_handler) + logger.level = logging.DEBUG + logger.info("nyr_forcing = %s", self.ssp.nyr_forcing) + for n in range(self.ssp.n_steps()): + self.ssp.__logger__(n) + if self.ssp.spin[n] == "sasu": + logger.info(" SASU spinup is .true.") + if self.ssp.sasu[n] != -999: + logger.info(" nyr_sasu = %s", self.ssp.sasu[n]) + if self.ssp.iloop[n] != -999: + logger.info(" iloop_avg = %s", self.ssp.iloop[n]) + + logger.info("Total number of years %s", self.ssp.total_years()) + logger.removeHandler(stream_handler) + + def test_n_steps(self): + """ + Test that n_steps is as expected + """ + self.assertTrue(self.ssp.n_steps() == 3) + + def test_valid_n(self): + """ + Test that check of n-step is good for the range it runs in + """ + for n in range(self.ssp.n_steps()): + self.ssp.check_n(n) + + def test_negative_n(self): + """ + Test that fails when n-step is negative + """ + self.assertRaises(SystemExit, self.ssp.check_n, -1) + + def test_n_too_big(self): + """ + Test that fails when n-step is too big + """ + self.assertRaises(SystemExit, self.ssp.check_n, self.ssp.n_steps()) + + def test_append_user_nl_step2(self): + """ + Test appending to user_nl_clm file for step 2 + """ + ufile = "user_nl_clm" + if os.path.exists(ufile): + os.remove(ufile) + + os.mknod(ufile) + + expect = "\nhist_nhtfrq = -8760, hist_mfilt = 2\n" + self.ssp.append_user_nl(caseroot=".", n=2) + log = open(ufile, "r").read() + self.assertEqual(expect, log, "Append user_nl_clm file NOT as expected for step 2") + os.remove(ufile) + + +if __name__ == "__main__": + unit_testing.setup_for_tests() + unittest.main() From 708719b0edf018e1f190e5a2e869cd591e061c81 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Fri, 31 Jan 2025 02:36:59 -0700 Subject: [PATCH 09/15] Add passing test that runs the standard workflow for sspmatrix --- python/ctsm/test/test_unit_sspmatrix.py | 67 +++++++++++++++++++++---- 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/python/ctsm/test/test_unit_sspmatrix.py b/python/ctsm/test/test_unit_sspmatrix.py index 6f4c253014..6b08f9f9d8 100755 --- a/python/ctsm/test/test_unit_sspmatrix.py +++ b/python/ctsm/test/test_unit_sspmatrix.py @@ -1,9 +1,6 @@ #!/usr/bin/env python3 """ -Unit tests for the SystemTest sspmatrix.pty - -You can run this by: - python -m unittest test_unit_sspmatrix.py +Unit tests for the SystemTest sspmatrix.py """ import unittest @@ -12,6 +9,7 @@ import tempfile import shutil import logging +from pathlib import Path from ctsm.path_utils import add_cime_lib_to_path from ctsm import unit_testing @@ -35,6 +33,51 @@ logger = logging.getLogger(__name__) +class SSPCaseFake(CaseFake): + """ + Extend the CaseFake class with a couple things needed here + """ + def __init__(self, case_root, tempdir, create_case_root=True): + """ + Initialization handling the tempdir + """ + super().__init__( case_root, create_case_root) + self._tempdir = tempdir + + def create_clone( + self, + newcase, + keepexe=False, + ): + """ + Extend to handle creation of user_nl_clm file + """ + clone = super().create_clone( newcase, keepexe=keepexe) + os.mknod( os.path.join( newcase, "user_nl_clm") ) + # Also make the needed case directories + clone.make_case_dirs(self._tempdir) + return clone + + def make_case_dirs(self, tempdir): + """ + Create the directories needed for the CASE + """ + casename = self.get_value("CASE") + dout_s_root = Path( tempdir, "archive", casename ) + dout_s_root.mkdir( parents=True ) + self.set_value("DOUT_S_ROOT", str(dout_s_root) ) + rest_root = Path( dout_s_root, "rest" ) + rest_root.mkdir( ) + rundir = Path( tempdir, casename, "run" ) + rundir.mkdir() + self.set_value("RUNDIR", rundir ) + + + def __str__( self ): + """ + String method + """ + return "caseroot=%s" % (self.get_value("CASEROOT")) class TestSSPMatrix(unittest.TestCase): """ @@ -48,25 +91,26 @@ def setUp(self): self._previous_dir = os.getcwd() self._tempdir = tempfile.mkdtemp() - # Set up the testing CaseFake - caseroot = os.path.join(self._tempdir, "case") - self._case = CaseFake(caseroot, create_case_root=True) + # Set up the testing SSPCaseFake + caseroot = os.path.join(self._tempdir, "ssptestcase") + self._case = SSPCaseFake(caseroot, tempdir=self._tempdir, create_case_root=True) os.chdir(caseroot) # Set XML variables that will be needed in the case self._case.set_value("DATM_YR_START", 2000) self._case.set_value("DATM_YR_END", 2001) self._case.set_value("COMP_LND", "clm") - self._case.set_value("NINST", "1") + self._case.set_value("NINST", 1) self.ssp = SSPMATRIXCN(self._case) + self._case.make_case_dirs(self._tempdir) def tearDown(self): """ Remove temporary directory """ os.chdir(self._previous_dir) - shutil.rmtree(self._tempdir, ignore_errors=True) + #shutil.rmtree(self._tempdir, ignore_errors=True) def test_logger(self): """ @@ -129,6 +173,11 @@ def test_append_user_nl_step2(self): self.assertEqual(expect, log, "Append user_nl_clm file NOT as expected for step 2") os.remove(ufile) + def test_run_phase(self): + """ + Test doing the standard run_phase, that does each step + """ + self.ssp.run_phase() if __name__ == "__main__": unit_testing.setup_for_tests() From cf433215b58ba8776ec5edfb0b0d80c0836ed3a0 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Fri, 31 Jan 2025 02:44:20 -0700 Subject: [PATCH 10/15] Run black and add back cleanup --- python/ctsm/test/test_unit_sspmatrix.py | 31 ++++++++++++++----------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/python/ctsm/test/test_unit_sspmatrix.py b/python/ctsm/test/test_unit_sspmatrix.py index 6b08f9f9d8..21caf6198e 100755 --- a/python/ctsm/test/test_unit_sspmatrix.py +++ b/python/ctsm/test/test_unit_sspmatrix.py @@ -33,15 +33,17 @@ logger = logging.getLogger(__name__) + class SSPCaseFake(CaseFake): """ Extend the CaseFake class with a couple things needed here """ + def __init__(self, case_root, tempdir, create_case_root=True): """ Initialization handling the tempdir """ - super().__init__( case_root, create_case_root) + super().__init__(case_root, create_case_root) self._tempdir = tempdir def create_clone( @@ -52,33 +54,33 @@ def create_clone( """ Extend to handle creation of user_nl_clm file """ - clone = super().create_clone( newcase, keepexe=keepexe) - os.mknod( os.path.join( newcase, "user_nl_clm") ) + clone = super().create_clone(newcase, keepexe=keepexe) + os.mknod(os.path.join(newcase, "user_nl_clm")) # Also make the needed case directories clone.make_case_dirs(self._tempdir) return clone def make_case_dirs(self, tempdir): - """ + """ Create the directories needed for the CASE """ casename = self.get_value("CASE") - dout_s_root = Path( tempdir, "archive", casename ) - dout_s_root.mkdir( parents=True ) - self.set_value("DOUT_S_ROOT", str(dout_s_root) ) - rest_root = Path( dout_s_root, "rest" ) - rest_root.mkdir( ) - rundir = Path( tempdir, casename, "run" ) + dout_s_root = Path(tempdir, "archive", casename) + dout_s_root.mkdir(parents=True) + self.set_value("DOUT_S_ROOT", str(dout_s_root)) + rest_root = Path(dout_s_root, "rest") + rest_root.mkdir() + rundir = Path(tempdir, casename, "run") rundir.mkdir() - self.set_value("RUNDIR", rundir ) + self.set_value("RUNDIR", rundir) - - def __str__( self ): + def __str__(self): """ String method """ return "caseroot=%s" % (self.get_value("CASEROOT")) + class TestSSPMatrix(unittest.TestCase): """ Basic class for testing the sspmatrix.py SystemTest @@ -110,7 +112,7 @@ def tearDown(self): Remove temporary directory """ os.chdir(self._previous_dir) - #shutil.rmtree(self._tempdir, ignore_errors=True) + shutil.rmtree(self._tempdir, ignore_errors=True) def test_logger(self): """ @@ -179,6 +181,7 @@ def test_run_phase(self): """ self.ssp.run_phase() + if __name__ == "__main__": unit_testing.setup_for_tests() unittest.main() From 7c51a9df53b6b120498954ec46d9cb7b5f5b41b0 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Fri, 31 Jan 2025 02:45:32 -0700 Subject: [PATCH 11/15] Add black commit to ignore blame file --- .git-blame-ignore-revs | 1 + 1 file changed, 1 insertion(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index d04aeea2d4..9a25e82eab 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -55,3 +55,4 @@ aa04d1f7d86cc2503b98b7e2b2d84dbfff6c316b f112ba0bbf96a61d5a4d354dc0dcbd8b0c68145c bd535c710db78420b8e8b9d71d88d8339e899c59 4b20bbd7003e6f77dab4e3268cc4a43f9b5a3b5d +cf433215b58ba8776ec5edfb0b0d80c0836ed3a0 From ef520087b062b1174b9f56d403e00a88a7ee9305 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Fri, 31 Jan 2025 22:47:14 -0700 Subject: [PATCH 12/15] Spinoff add_ctsm_systests_to_path to path_utils and cleanup the rest of the pylint issues --- python/ctsm/path_utils.py | 9 +++++++++ python/ctsm/test/test_unit_sspmatrix.py | 16 +++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/python/ctsm/path_utils.py b/python/ctsm/path_utils.py index 0015822c03..f7827ecdfd 100644 --- a/python/ctsm/path_utils.py +++ b/python/ctsm/path_utils.py @@ -95,6 +95,15 @@ def add_cime_lib_to_path(standalone_only=False): prepend_to_python_path(cime_lib_path) return cime_path +def add_ctsm_systests_to_path(standalone_only=False): + """Adds the CTSM python SystemTests to the python path, to allow importing + modules from that library + """ + cime_path = path_to_cime(standalone_only=standalone_only) + ctsm_systest_dir = os.path.join(cime_path, os.pardir, "cime_config") + prepend_to_python_path(ctsm_systest_dir) + sys.path.insert(1, ctsm_systest_dir) + # ======================================================================== # Private functions diff --git a/python/ctsm/test/test_unit_sspmatrix.py b/python/ctsm/test/test_unit_sspmatrix.py index 21caf6198e..1b1bc60185 100755 --- a/python/ctsm/test/test_unit_sspmatrix.py +++ b/python/ctsm/test/test_unit_sspmatrix.py @@ -11,22 +11,20 @@ import logging from pathlib import Path -from ctsm.path_utils import add_cime_lib_to_path +from ctsm.path_utils import add_cime_lib_to_path, add_ctsm_systests_to_path from ctsm import unit_testing -_CIME_PATH = add_cime_lib_to_path(standalone_only=True) +add_ctsm_systests_to_path() +add_cime_lib_to_path() -# -- add python/ctsm to path (needed if we want to run the test stand-alone) -_CTSM_PYTHON = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, os.pardir) -_CTSM_SYSTEST_DIR = os.path.join(_CIME_PATH, os.pardir, "cime_config") -sys.path.insert(1, _CTSM_PYTHON) -sys.path.insert(1, _CTSM_SYSTEST_DIR) -# pylint: disable=wrong-import-order +# pylint: disable=import-error # pylint: disable=wrong-import-position +# pylint: disable=wrong-import-order from SystemTests.sspmatrixcn import SSPMATRIXCN -# pylint: disable=wrong-import-order +# pylint: disable=import-error # pylint: disable=wrong-import-position +# pylint: disable=wrong-import-order from CIME.tests.case_fake import CaseFake # pylint: disable=invalid-name From 534043558333572b518daea2cefe3203b8bb3cb9 Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Sat, 1 Feb 2025 01:54:14 -0700 Subject: [PATCH 13/15] Changes to get the unit tests all working as well as the actual runs, have to implement run_indv and have a unit test version and actual run version --- cime_config/SystemTests/sspmatrixcn.py | 30 ++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/cime_config/SystemTests/sspmatrixcn.py b/cime_config/SystemTests/sspmatrixcn.py index a937cdfbf3..98a580a8db 100644 --- a/cime_config/SystemTests/sspmatrixcn.py +++ b/cime_config/SystemTests/sspmatrixcn.py @@ -25,6 +25,7 @@ else: from CIME.status import append_testlog +from CIME.case import Case from CIME.XML.standard_module_setup import * from CIME.SystemTests.system_tests_common import SystemTestsCommon from CIME.SystemTests.test_utils import user_nl_utils @@ -187,6 +188,26 @@ def append_user_nl(self, caseroot, n=0): caseroot=caseroot, component=self.comp, contents=contents_to_append ) + def run_indv(self, nstep, st_archive=True): + """ + Individual run of a given step + """ + suffix = "step{}".format(self.steps[nstep]) + if isinstance(self._case, Case): + super().run_indv(suffix, st_archive=True) + else: + caseroot = self._case.get_value("CASEROOT") + dout_sr = self._case.get_value("DOUT_S_ROOT") + rest_r = os.path.join(dout_sr, "rest") + nyear = 1851 + nstep + rundate = "%s-01-01-00000" % nyear + restdir = os.path.join(rest_r, rundate) + os.mkdir(restdir) + rpoint = os.path.join(restdir, "rpointer.clm." + rundate) + os.mknod(rpoint) + rpoint = os.path.join(restdir, "rpointer.cpl." + rundate) + os.mknod(rpoint) + def run_phase(self): "Run phase" @@ -250,7 +271,7 @@ def run_phase(self): os.symlink(item, linkfile) # For a branch the cpl rpointer file needs to be handled - if self.runtyp[n] is "branch": + if self.runtyp[n] == "branch": drvrest = "rpointer.cpl" if ninst > 1: @@ -266,7 +287,7 @@ def run_phase(self): # Run the case (Archiving on) # self._case.flush() - self.run_indv(suffix="step{}".format(self.steps[n]), st_archive=True) + self.run_indv(nstep=n, st_archive=True) # # Get the reference case from this step for the next step @@ -305,10 +326,11 @@ def run_phase(self): linkfile = os.path.join(rundir, os.path.basename(item)) if os.path.exists(linkfile): os.remove(linkfile) + expect(True, os.path.exists(item), "expected file does NOT exist = " + item) os.symlink(item, linkfile) # For a branch the cpl rpointer file needs to be handled - if self.runtyp[n] is "branch": + if self.runtyp[n] == "branch": drvrest = "rpointer.cpl" if ninst > 1: @@ -330,4 +352,4 @@ def run_phase(self): # Run the case (short term archiving is off) # self._case.flush() - self.run_indv(suffix="step{}".format(self.steps[n]), st_archive=False) + self.run_indv(nstep=n, st_archive=False) From 16d57ff37859b34dab005693e3085d64e2bcd95a Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Sat, 1 Feb 2025 02:02:31 -0700 Subject: [PATCH 14/15] run_black --- python/ctsm/path_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/ctsm/path_utils.py b/python/ctsm/path_utils.py index f7827ecdfd..e8cf2989ce 100644 --- a/python/ctsm/path_utils.py +++ b/python/ctsm/path_utils.py @@ -95,6 +95,7 @@ def add_cime_lib_to_path(standalone_only=False): prepend_to_python_path(cime_lib_path) return cime_path + def add_ctsm_systests_to_path(standalone_only=False): """Adds the CTSM python SystemTests to the python path, to allow importing modules from that library From e1f21f267cf72704c8ba1bbc8012e2af2181614b Mon Sep 17 00:00:00 2001 From: Erik Kluzek Date: Sat, 1 Feb 2025 02:10:05 -0700 Subject: [PATCH 15/15] Add commit to git ignore blame --- .git-blame-ignore-revs | 1 + 1 file changed, 1 insertion(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 9a25e82eab..581503ccf7 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -56,3 +56,4 @@ f112ba0bbf96a61d5a4d354dc0dcbd8b0c68145c bd535c710db78420b8e8b9d71d88d8339e899c59 4b20bbd7003e6f77dab4e3268cc4a43f9b5a3b5d cf433215b58ba8776ec5edfb0b0d80c0836ed3a0 +16d57ff37859b34dab005693e3085d64e2bcd95a