Skip to content

Commit

Permalink
Implementation #1 of running other unit tests from scripts_regression…
Browse files Browse the repository at this point in the history
…_tests

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
  • Loading branch information
billsacks committed Aug 3, 2016
1 parent 6cdc316 commit de42303
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions utils/python/tests/scripts_regression_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ def do_unit_tests(self, script,from_dir=SCRIPT_DIR):
stat, output, _ = run_cmd("./%s --test 2>&1" % script, from_dir=from_dir)
self.assertEqual(stat, 0, msg=output)

def test_unittests(self):
# Finds all files contained in LIB_DIR or its subdirectories that match
# the pattern 'test*.py', and runs the unit tests found there (i.e.,
# tests defined using python's unittest module).
#
# This is analogous to running:
# python -m unittest discover
#
# It seems kind of funny to run a bunch of other unit test suites from
# within this single unit test, but doing it this way makes it
# consistent with how we run other tests in this module.

testsuite = unittest.defaultTestLoader.discover(
start_dir = LIB_DIR,
pattern = 'test*.py')

testrunner = unittest.TextTestRunner(buffer=False)

results = testrunner.run(testsuite)
self.assertTrue(results.wasSuccessful())

def test_cime_bisect_unit_test(self):
self.do_unit_tests("cime_bisect",from_dir=TOOLS_DIR)

Expand Down Expand Up @@ -66,14 +87,14 @@ def test_resolve_variable_name(self):
self.assertTrue(os.path.isfile(machinefile),
msg="Path did not resolve to existing file %s" % machinefile)

def test_CIME_unit_tests(self):
# Find and run all the unit tests in the CIME directory tree
def test_CIME_doctests(self):
# Find and run all the doctests in the CIME directory tree
os.environ["PYTHONPATH"] = LIB_DIR
stat, output, _ = run_cmd("python -m doctest *.py 2>&1", from_dir=os.path.join(LIB_DIR,"CIME"))
self.assertEqual(stat, 0, msg=output)

def test_CIMEXML_unit_tests(self):
# Find and run all the unit tests in the XML directory tree
def test_CIMEXML_doctests(self):
# Find and run all the doctests in the XML directory tree
os.environ["PYTHONPATH"] = LIB_DIR
stat, output, _ = run_cmd("python -m doctest *.py 2>&1", from_dir=os.path.join(LIB_DIR,"CIME","XML"))
self.assertEqual(stat, 0, msg=output)
Expand Down Expand Up @@ -1630,7 +1651,7 @@ def _main_func():

CIME.utils.handle_standard_logging_options(args)

unittest.main(verbosity=2)
unittest.main(verbosity=2, catchbreak=True)

if (__name__ == "__main__"):
_main_func()

0 comments on commit de42303

Please sign in to comment.