Skip to content

Commit 92d2a5c

Browse files
authored
Merge pull request #3314 from billsacks/fix_lreprstruct_grain_replacement
Fix string replacements in lreprstruct test
2 parents 7774316 + 96d44ea commit 92d2a5c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

cime_config/SystemTests/lreprstruct.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
1717
"""
1818

19+
import re
20+
1921
from CIME.SystemTests.system_tests_compare_two import SystemTestsCompareTwo
2022
from CIME.XML.standard_module_setup import *
2123
from CIME.SystemTests.test_utils.user_nl_utils import append_to_user_nl_files
@@ -53,13 +55,16 @@ def _case_one_setup(self):
5355
user_nl_clm_path = os.path.join(self._get_caseroot(), "user_nl_clm")
5456
with open(user_nl_clm_path) as f:
5557
user_nl_clm_text = f.read()
56-
for grain_output in re.findall("GRAIN\w*", user_nl_clm_text):
57-
user_nl_clm_text = user_nl_clm_text.replace(
58-
grain_output,
58+
59+
def replace_grain(match):
60+
grain_output = match.group()
61+
return (
5962
grain_output.replace("GRAIN", "REPRODUCTIVE1")
6063
+ "', '"
61-
+ grain_output.replace("GRAIN", "REPRODUCTIVE2"),
64+
+ grain_output.replace("GRAIN", "REPRODUCTIVE2")
6265
)
66+
67+
user_nl_clm_text = re.sub(r"GRAIN\w*", replace_grain, user_nl_clm_text)
6368
with open(user_nl_clm_path, "w") as f:
6469
f.write(user_nl_clm_text)
6570

0 commit comments

Comments
 (0)