Skip to content

Commit

Permalink
Add unit tests for SystemTestsCompareTwo
Browse files Browse the repository at this point in the history
Note that I needed to extract pieces of the SystemTestsCommon __init__ method
into their own methods so that I could stub them out for testing.

Test suite: None
Test baseline: N/A
Test namelist changes: N/A
Test status: N/A

Ran new unit tests with:

[roo2:~/cime/utils/python]$ python -m unittest discover

Note: This fails with python3 due to use of python2 print in compare_env_run

Fixes: None

User interface changes?: No

Code review: None
  • Loading branch information
billsacks committed Jul 30, 2016
1 parent e887ef2 commit eee2b03
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 0 deletions.
19 changes: 19 additions & 0 deletions utils/python/CIME/SystemTests/system_tests_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,24 @@ def __init__(self, case, expected=None):
self._caseroot = caseroot
self._orig_caseroot = caseroot
self._runstatus = None

self._init_environment(caseroot)
self._init_locked_files(caseroot, expected)
self._init_case_setup()

def _init_environment(self, caseroot):
"""
Do initializations of environment variables that are needed in __init__
"""
# Needed for sh scripts
os.environ["CASEROOT"] = caseroot

def _init_locked_files(self, caseroot, expected):
"""
If the file LockedFiles/env_run.orig.xml does not exist, copy the current
env_run.xml file. If it does exist, restore values changed in a previous
run of the test.
"""
if os.path.isfile(os.path.join(caseroot, "LockedFiles", "env_run.orig.xml")):
self.compare_env_run(expected=expected)
elif os.path.isfile(os.path.join(caseroot, "env_run.xml")):
Expand All @@ -41,6 +56,10 @@ def __init__(self, case, expected=None):
shutil.copy(os.path.join(caseroot,"env_run.xml"),
os.path.join(lockedfiles, "env_run.orig.xml"))

def _init_case_setup(self):
"""
Do initial case setup needed in __init__
"""
if self._case.get_value("IS_FIRST_RUN"):
self._case.set_initial_test_values()

Expand Down
23 changes: 23 additions & 0 deletions utils/python/CIME/SystemTests/system_tests_compare_two.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def _pre_build(self):

def build(self, sharedlib_only=False, model_only=False):
self._pre_build()

if self._needs_two_builds(sharedlib_only = sharedlib_only,
model_only = model_only):
raise NotImplementedError('Two builds not yet implemented')
Expand All @@ -154,6 +155,7 @@ def run(self):
Runs both phases of the two-phase test and compares their results
"""

# First run
self._run_common_setup()
self._run_one_setup()
logger.info('Doing first run: ' + self._run_one_description)
Expand All @@ -164,6 +166,7 @@ def run(self):
self._status_run1 = "FAIL"
return False

# Second run
self._run_common_setup()
self._run_two_setup()
logger.info('Doing second run: ' + self._run_two_description)
Expand All @@ -174,6 +177,7 @@ def run(self):
self._status_run2 = "FAIL"
return False

# Compare results
success = self._component_compare_test(self._run_one_suffix, self._run_two_suffix)
if success:
self._status_compare = "PASS"
Expand All @@ -183,6 +187,25 @@ def run(self):

return success

def get_run_one_status(self):
"""
Returns a string specifying the status of run 1
"""
return self._status_run1

def get_run_two_status(self):
"""
Returns a string specifying the status of run 2
"""
return self._status_run2

def get_compare_status(self):
"""
Returns a string specifying the status of the comparison between run 1
and run 2
"""
return self._status_compare

# ========================================================================
# Private methods
# ========================================================================
Expand Down
Empty file.
Loading

0 comments on commit eee2b03

Please sign in to comment.