From 492e0381946a69d9e99a2d90853edf3e5dd93bd5 Mon Sep 17 00:00:00 2001 From: Bill Sacks Date: Mon, 15 Aug 2016 15:00:47 -0600 Subject: [PATCH 1/2] Change implementation of default test_dir for TestStatus For some reason, some tests in scripts_regression_tests were failing for me with the old version of this code - maybe because default arguments are evaluated when the function is defined (not when it is called)? This new version seems more likely to be what's wanted - i.e., getting the current working directory at the time when the function is called, not the time when it's defined. From a quick look, it looks like this default could be removed entirely and made a required argument. Test suite: None Test baseline: N/A Test namelist changes: N/A Test status: N/A Fixes: None User interface changes?: No Code review: None --- utils/python/CIME/test_status.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/utils/python/CIME/test_status.py b/utils/python/CIME/test_status.py index 7398ccf7b23..c2bc9a04007 100644 --- a/utils/python/CIME/test_status.py +++ b/utils/python/CIME/test_status.py @@ -62,7 +62,14 @@ def _test_helper2(file_contents, wait_for_run=False, check_throughput=False, che class TestStatus(object): - def __init__(self, test_dir=os.getcwd(), test_name=None): + def __init__(self, test_dir=None, test_name=None): + """ + Create a TestStatus object + + If test_dir is not specified, it is set to the current working directory + """ + if test_dir is None: + test_dir = os.getcwd() self._filename = os.path.join(test_dir, TEST_STATUS_FILENAME) self._phase_statuses = OrderedDict() # {name -> (status, comments)} self._test_name = test_name From f210e1c013d4ed948322251890a4bdcbcec81dc2 Mon Sep 17 00:00:00 2001 From: Bill Sacks Date: Mon, 15 Aug 2016 15:34:53 -0600 Subject: [PATCH 2/2] Change implementation of default caseroot for check_lockedfiles For some reason, some tests in scripts_regression_tests were failing for me with the old version of this code - maybe because default arguments are evaluated when the function is defined (not when it is called)? This new version seems more likely to be what's wanted - i.e., getting the current working directory at the time when the function is called, not the time when it's defined. In particular, this seems like it could (in principle) be important in case_setup, which does: os.chdir(caseroot) before calling: check_lockedfiles() Test suite: None Test baseline: N/A Test namelist changes: N/A Test status: N/A Fixes: None User interface changes?: No Code review: None --- utils/python/CIME/check_lockedfiles.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utils/python/CIME/check_lockedfiles.py b/utils/python/CIME/check_lockedfiles.py index 5beee69dd47..664eab0244f 100644 --- a/utils/python/CIME/check_lockedfiles.py +++ b/utils/python/CIME/check_lockedfiles.py @@ -9,10 +9,14 @@ import glob -def check_lockedfiles(caseroot=os.getcwd()): +def check_lockedfiles(caseroot=None): """ Check that all lockedfiles match what's in case + + If caseroot is not specified, it is set to the current working directory """ + if caseroot is None: + caseroot = os.getcwd() lockedfiles = glob.glob(os.path.join(caseroot, "LockedFiles", "*.xml")) for lfile in lockedfiles: fpart = os.path.basename(lfile)