Skip to content

Commit

Permalink
reformat new and updated systests with black
Browse files Browse the repository at this point in the history
  • Loading branch information
glemieux committed Jul 17, 2024
1 parent e4142b9 commit 75cd2f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
15 changes: 9 additions & 6 deletions cime_config/SystemTests/pvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

logger = logging.getLogger(__name__)


class PVT(SystemTestsCommon):
def __init__(self,case):
SystemTestsCommon.__init__(self,case)
def __init__(self, case):
SystemTestsCommon.__init__(self, case)

# Do not allow PVT to be run with certain testmods
# Should this be targeted to a specific testmod for simplicity for now?
Expand All @@ -27,14 +28,16 @@ def __init__(self,case):
casebaseid = self._case.get_value("CASEBASEID")
casebaseid = casebaseid.split("-")[-1]
if casebaseid[0:10] != "FatesLUPFT":
error_message = (f"Only call PVT with testmod FatesLUPFT. {casebaseid} selected.")
error_message = f"Only call PVT with testmod FatesLUPFT. {casebaseid} selected."

# Only allow to run if resolution is 4x5 for now
# Other grid resolutions will be pre-processed and included in the namelist defaults at a future date.
# Potentially we could generate these on the fly although doing so would result in increased build time
lnd_grid = self._case.get_value("LND_GRID")
if lnd_grid != "4x5":
error_message = (f"PVT can currently only be run with 4x5 resolution. {lnd_grid} selected.")
error_message = (
f"PVT can currently only be run with 4x5 resolution. {lnd_grid} selected."
)

if error_message is not None:
logger.error(error_message)
Expand Down Expand Up @@ -79,7 +82,7 @@ def run_phase(self):
# Turn off fates_harvest_mode for the spin up.

logger.info("PVT log: modify user_nl_clm file for spin up run")
added_content = ["use_fates_potentialveg = .true.","fates_harvest_mode = 'no_harvest'"]
added_content = ["use_fates_potentialveg = .true.", "fates_harvest_mode = 'no_harvest'"]
append_to_user_nl_files(clone_path, "clm", added_content)

# Run the spin up case
Expand All @@ -100,7 +103,7 @@ def run_phase(self):
# obtain rpointer files and necessary restart files from short term archiving directory
rundir = self._case.get_value("RUNDIR")

refdate = str(refcase_year) + '-01-01-00000'
refdate = str(refcase_year) + "-01-01-00000"
rest_path = os.path.join(dout_sr, "rest", "{}".format(refdate))

for item in glob.glob("{}/*{}*".format(rest_path, refdate)):
Expand Down
7 changes: 4 additions & 3 deletions cime_config/SystemTests/systemtest_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,15 @@ def run_python_script(caseroot, this_conda_env, command_in, tool_path):
print(f"ERROR trying to run {tool_name}.")
raise


# Read a user_nl file and return the namelist option if found
def find_user_nl_option(caseroot, component, namelist_option):

# This is a copy of the CIME _get_list_of_user_nl_files
# which could be used if this moved into the CIME project
file_pattern = "user_nl_" + component + "*"
file_list = glob.glob(os.path.join(caseroot, file_pattern))

# Check that there is at least one file
if len(file_list) == 0:
raise RuntimeError("No user_nl files found for component " + component)
Expand All @@ -103,7 +104,7 @@ def find_user_nl_option(caseroot, component, namelist_option):
for one_file in file_list:
with open(one_file, "r") as user_nl_file:
user_nl_text = user_nl_file.read()
reg = fr'{namelist_option}.*?(?=,|\n)'
reg = rf"{namelist_option}.*?(?=,|\n)"
find_out = re.findall(reg, user_nl_text)
output[one_file] = find_out
return output

0 comments on commit 75cd2f4

Please sign in to comment.