|
12 | 12 | import tempfile |
13 | 13 | import inspect |
14 | 14 | import xarray as xr |
| 15 | +from CIME.scripts.create_newcase import _main_func as create_newcase # pylint: disable=import-error |
15 | 16 |
|
16 | 17 | # -- add python/ctsm to path (needed if we want to run the test stand-alone) |
17 | 18 | _CTSM_PYTHON = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, os.pardir) |
@@ -40,13 +41,35 @@ class TestSubsetDataSys(unittest.TestCase): |
40 | 41 | """ |
41 | 42 |
|
42 | 43 | def setUp(self): |
| 44 | + self.previous_dir = os.getcwd() |
43 | 45 | self.temp_dir_out = tempfile.TemporaryDirectory() |
44 | 46 | self.temp_dir_umd = tempfile.TemporaryDirectory() |
| 47 | + self.temp_dir_caseparent = tempfile.TemporaryDirectory() |
45 | 48 | self.inputdata_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir) |
46 | 49 |
|
47 | 50 | def tearDown(self): |
48 | 51 | self.temp_dir_out.cleanup() |
49 | 52 | 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() |
50 | 73 |
|
51 | 74 | def _check_result_file_matches_expected(self, expected_output_files, caller_n): |
52 | 75 | """ |
@@ -167,15 +190,21 @@ def _do_test_subset_data_reg_amazon(self, include_regname=True): |
167 | 190 | ] |
168 | 191 | self.assertTrue(self._check_result_file_matches_expected(expected_output_files, 2)) |
169 | 192 |
|
| 193 | + # Check that create_newcase works |
| 194 | + # SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES |
| 195 | + self._check_create_newcase() |
| 196 | + |
170 | 197 | def test_subset_data_reg_amazon(self): |
171 | 198 | """ |
172 | 199 | Test subset_data for Amazon region |
| 200 | + SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES |
173 | 201 | """ |
174 | 202 | self._do_test_subset_data_reg_amazon() |
175 | 203 |
|
176 | 204 | def test_subset_data_reg_amazon_noregname(self): |
177 | 205 | """ |
178 | 206 | Test subset_data for Amazon region |
| 207 | + SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES |
179 | 208 | """ |
180 | 209 | self._do_test_subset_data_reg_amazon(include_regname=False) |
181 | 210 |
|
@@ -298,22 +327,29 @@ def _do_test_subset_data_pt_surface(self, lon, include_sitename=True): |
298 | 327 | ] |
299 | 328 | self.assertTrue(self._check_result_file_matches_expected(expected_output_files, 2)) |
300 | 329 |
|
| 330 | + # Check that create_newcase works |
| 331 | + # SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES |
| 332 | + self._check_create_newcase() |
| 333 | + |
301 | 334 | def test_subset_data_pt_surface_amazon_type360(self): |
302 | 335 | """ |
303 | 336 | Test subset_data --create-surface for Amazon point with longitude type 360 |
| 337 | + SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES |
304 | 338 | """ |
305 | 339 | self._do_test_subset_data_pt_surface(291) |
306 | 340 |
|
307 | 341 | def test_subset_data_pt_surface_amazon_type180(self): |
308 | 342 | """ |
309 | 343 | Test subset_data --create-surface for Amazon point with longitude type 180 |
| 344 | + SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES |
310 | 345 | """ |
311 | 346 | self._do_test_subset_data_pt_surface(-69) |
312 | 347 |
|
313 | 348 | def test_subset_data_pt_surface_amazon_type180_nositename(self): |
314 | 349 | """ |
315 | 350 | Test subset_data --create-surface for Amazon point with longitude type 180 |
316 | 351 | without specifying a site name |
| 352 | + SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES |
317 | 353 | """ |
318 | 354 | self._do_test_subset_data_pt_surface(-69, include_sitename=False) |
319 | 355 |
|
@@ -367,21 +403,28 @@ def _do_test_subset_data_pt_landuse(self, lon, include_sitename=True): |
367 | 403 | ] |
368 | 404 | self.assertTrue(self._check_result_file_matches_expected(expected_output_files, 2)) |
369 | 405 |
|
| 406 | + # Check that create_newcase works |
| 407 | + # SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES |
| 408 | + self._check_create_newcase() |
| 409 | + |
370 | 410 | def test_subset_data_pt_landuse_amazon_type360(self): |
371 | 411 | """ |
372 | 412 | Test subset_data --create-landuse for Amazon point with longitude type 360 |
| 413 | + SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES |
373 | 414 | """ |
374 | 415 | self._do_test_subset_data_pt_landuse(291) |
375 | 416 |
|
376 | 417 | def test_subset_data_pt_landuse_amazon_type360_nositename(self): |
377 | 418 | """ |
378 | 419 | Test subset_data --create-landuse for Amazon point with longitude type 360 and no site name |
| 420 | + SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES |
379 | 421 | """ |
380 | 422 | self._do_test_subset_data_pt_landuse(291, include_sitename=False) |
381 | 423 |
|
382 | 424 | def test_subset_data_pt_landuse_amazon_type180(self): |
383 | 425 | """ |
384 | 426 | Test subset_data --create-landuse for Amazon point with longitude type 180 |
| 427 | + SHOULD WORK ONLY ON CESM-SUPPORTED MACHINES |
385 | 428 | """ |
386 | 429 | self._do_test_subset_data_pt_landuse(-69) |
387 | 430 |
|
@@ -431,6 +474,9 @@ def _do_test_subset_data_pt_datm(self, lon, include_sitename=True): |
431 | 474 | expected_output_files = [os.path.join("datmdata", x) for x in expected_output_files] |
432 | 475 | self.assertTrue(self._check_result_file_matches_expected(expected_output_files, 2)) |
433 | 476 |
|
| 477 | + # Check that create_newcase works |
| 478 | + self._check_create_newcase() |
| 479 | + |
434 | 480 | def test_subset_data_pt_datm_amazon_type360(self): |
435 | 481 | """ |
436 | 482 | Test subset_data --create-datm for Amazon point with longitude type 360 |
|
0 commit comments