Skip to content

Commit aca0a5d

Browse files
committed
test_sys_subset_data.py: Check that create_newcase works.
Makes it so that NO tests in that file will work outside CESM-supported machines.
1 parent 8050c3b commit aca0a5d

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

python/ctsm/test/test_sys_subset_data.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import tempfile
1313
import inspect
1414
import xarray as xr
15+
from CIME.scripts.create_newcase import _main_func as create_newcase # pylint: disable=import-error
1516

1617
# -- add python/ctsm to path (needed if we want to run the test stand-alone)
1718
_CTSM_PYTHON = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, os.pardir)
@@ -40,13 +41,35 @@ class TestSubsetDataSys(unittest.TestCase):
4041
"""
4142

4243
def setUp(self):
44+
self.previous_dir = os.getcwd()
4345
self.temp_dir_out = tempfile.TemporaryDirectory()
4446
self.temp_dir_umd = tempfile.TemporaryDirectory()
47+
self.temp_dir_caseparent = tempfile.TemporaryDirectory()
4548
self.inputdata_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)
4649

4750
def tearDown(self):
4851
self.temp_dir_out.cleanup()
4952
self.temp_dir_umd.cleanup()
53+
os.chdir(self.previous_dir)
54+
55+
def _check_create_newcase(self):
56+
"""
57+
Check that you can call create_newcase using the usermods from subset_data
58+
"""
59+
case_dir = os.path.join(self.temp_dir_caseparent.name, "case")
60+
sys.argv = [
61+
"create_newcase",
62+
"--case",
63+
case_dir,
64+
"--res",
65+
"CLM_USRDAT",
66+
"--compset",
67+
"I2000Clm60Bgc",
68+
"--run-unsupported",
69+
"--user-mods-dir",
70+
self.temp_dir_umd.name,
71+
]
72+
create_newcase()
5073

5174
def _check_result_file_matches_expected(self, expected_output_files, caller_n):
5275
"""
@@ -167,15 +190,21 @@ def _do_test_subset_data_reg_amazon(self, include_regname=True):
167190
]
168191
self.assertTrue(self._check_result_file_matches_expected(expected_output_files, 2))
169192

193+
# Check that create_newcase works
194+
# SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES
195+
self._check_create_newcase()
196+
170197
def test_subset_data_reg_amazon(self):
171198
"""
172199
Test subset_data for Amazon region
200+
SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES
173201
"""
174202
self._do_test_subset_data_reg_amazon()
175203

176204
def test_subset_data_reg_amazon_noregname(self):
177205
"""
178206
Test subset_data for Amazon region
207+
SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES
179208
"""
180209
self._do_test_subset_data_reg_amazon(include_regname=False)
181210

@@ -298,22 +327,29 @@ def _do_test_subset_data_pt_surface(self, lon, include_sitename=True):
298327
]
299328
self.assertTrue(self._check_result_file_matches_expected(expected_output_files, 2))
300329

330+
# Check that create_newcase works
331+
# SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES
332+
self._check_create_newcase()
333+
301334
def test_subset_data_pt_surface_amazon_type360(self):
302335
"""
303336
Test subset_data --create-surface for Amazon point with longitude type 360
337+
SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES
304338
"""
305339
self._do_test_subset_data_pt_surface(291)
306340

307341
def test_subset_data_pt_surface_amazon_type180(self):
308342
"""
309343
Test subset_data --create-surface for Amazon point with longitude type 180
344+
SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES
310345
"""
311346
self._do_test_subset_data_pt_surface(-69)
312347

313348
def test_subset_data_pt_surface_amazon_type180_nositename(self):
314349
"""
315350
Test subset_data --create-surface for Amazon point with longitude type 180
316351
without specifying a site name
352+
SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES
317353
"""
318354
self._do_test_subset_data_pt_surface(-69, include_sitename=False)
319355

@@ -367,21 +403,28 @@ def _do_test_subset_data_pt_landuse(self, lon, include_sitename=True):
367403
]
368404
self.assertTrue(self._check_result_file_matches_expected(expected_output_files, 2))
369405

406+
# Check that create_newcase works
407+
# SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES
408+
self._check_create_newcase()
409+
370410
def test_subset_data_pt_landuse_amazon_type360(self):
371411
"""
372412
Test subset_data --create-landuse for Amazon point with longitude type 360
413+
SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES
373414
"""
374415
self._do_test_subset_data_pt_landuse(291)
375416

376417
def test_subset_data_pt_landuse_amazon_type360_nositename(self):
377418
"""
378419
Test subset_data --create-landuse for Amazon point with longitude type 360 and no site name
420+
SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES
379421
"""
380422
self._do_test_subset_data_pt_landuse(291, include_sitename=False)
381423

382424
def test_subset_data_pt_landuse_amazon_type180(self):
383425
"""
384426
Test subset_data --create-landuse for Amazon point with longitude type 180
427+
SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES
385428
"""
386429
self._do_test_subset_data_pt_landuse(-69)
387430

@@ -431,6 +474,9 @@ def _do_test_subset_data_pt_datm(self, lon, include_sitename=True):
431474
expected_output_files = [os.path.join("datmdata", x) for x in expected_output_files]
432475
self.assertTrue(self._check_result_file_matches_expected(expected_output_files, 2))
433476

477+
# Check that create_newcase works
478+
self._check_create_newcase()
479+
434480
def test_subset_data_pt_datm_amazon_type360(self):
435481
"""
436482
Test subset_data --create-datm for Amazon point with longitude type 360

0 commit comments

Comments
 (0)