Skip to content

Commit

Permalink
Reorganize unit tests based on discussion with Jim Edwards
Browse files Browse the repository at this point in the history
My original idea had been to have a 'tests' subdirectory of each
production code directory, and to have unit tests live there. However,
Jim Edwards suggested having a top-level tests directory, and then
having a directory structure under that that mirrors the production code
directory structure. This commit does that.

Note that I have also moved case_fake.py to a higher level within the
tests directory, mirroring the location of case.py.

Test suite: python -m unittest discover -s CIME/tests -t .
Test baseline: N/A
Test namelist changes: N/A
Test status: pass

Fixes: None

User interface changes?: No

Code review: None
  • Loading branch information
billsacks committed Aug 16, 2016
1 parent f2a27a2 commit 4560c5a
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 9 deletions.
6 changes: 6 additions & 0 deletions utils/python/CIME/tests/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The directory structure of this tests directory mirrors the directory structure
of the parent (production code) directory.

So, for example, unit tests for CIME/foo.py should live in
CIME/tests/test_foo.py, and unit tests for CIME/SystemTests/bar.py should live
in CIME/tests/SystemTests/test_bar.py.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from CIME.SystemTests.system_tests_compare_two import SystemTestsCompareTwo
import CIME.test_status as test_status
from CIME.SystemTests.tests.case_fake import CaseFake
from CIME.tests.case_fake import CaseFake

# ========================================================================
# Structure for storing information about calls made to methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import shutil
import tempfile
from CIME.SystemTests.system_tests_compare_two import SystemTestsCompareTwo
from CIME.SystemTests.tests.case_fake import CaseFake
from CIME.tests.case_fake import CaseFake

# ========================================================================
# Fake version of SystemTestsCompareTwo that overrides some functionality for
Expand Down
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os
import shutil

from CIME.SystemTests.tests.case_fake import CaseFake
from CIME.tests.case_fake import CaseFake

class TestCaseFake(unittest.TestCase):

Expand Down
14 changes: 8 additions & 6 deletions utils/python/tests/scripts_regression_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,21 @@ def test_resolve_variable_name(self):
msg="Path did not resolve to existing file %s" % machinefile)

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).
# Finds all files contained in CIME/tests 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
# python -m unittest discover -s CIME/tests -t .
# from cime/utils/python
#
# Yes, that means we have a bunch of unit tests run from this one unit
# test.

testsuite = unittest.defaultTestLoader.discover(
start_dir = LIB_DIR,
pattern = 'test*.py')
start_dir = os.path.join(LIB_DIR,"CIME","tests"),
pattern = 'test*.py',
top_level_dir = LIB_DIR)

testrunner = unittest.TextTestRunner(buffer=False)

Expand Down

0 comments on commit 4560c5a

Please sign in to comment.