Skip to content

Commit

Permalink
Add run_tower system tests of --overwrite.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsrabin committed Feb 14, 2025
1 parent 1a95351 commit 6fd238f
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions python/ctsm/test/test_sys_run_tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import tempfile
import shutil
import sys
import pathlib

from ctsm import unit_testing
from ctsm.site_and_regional.run_tower import main
Expand Down Expand Up @@ -231,6 +232,73 @@ def test_setup_only_plumber(self):
self.assertTrue(os.path.exists(build_dir_to_check))
self.assertTrue(len(os.listdir(build_dir_to_check)) == 0)

def test_overwrite_neon(self):
"""
This test checks that the --overwrite argument is obeyed for NEON sites
"""

# run the run_tower tool once
site_name = "BART"
sys.argv = [
os.path.join(path_to_ctsm_root(), "tools", "site_and_regional", "run_tower"),
"--neon-sites",
site_name,
"--no-input-data-check",
"--experiment",
"TEST",
"--output-root",
self._tempdir,
]
print(sys.argv)
main("")

# create a file that should be erased during the upcoming overwrite
case_dir = os.path.join(self._tempdir, site_name)
test_file = os.path.join(case_dir, "test_file")
pathlib.Path(test_file).touch()
self.assertTrue(os.path.exists(test_file))

# run the tool again, overwriting existing
sys.argv += ["--overwrite"]
print(sys.argv)
main("")

# ensure that file we created is gone
self.assertFalse(os.path.exists(test_file))

def test_overwrite_plumber(self):
"""
This test checks that the --overwrite argument is obeyed for PLUMBER sites
"""

# run the run_tower tool once
site_name = "AR-SLu"
sys.argv = [
os.path.join(path_to_ctsm_root(), "tools", "site_and_regional", "run_tower"),
"--plumber-sites",
site_name,
"--no-input-data-check",
"--experiment",
"TEST",
"--output-root",
self._tempdir,
]
main("")

# create a file that should be erased during the upcoming overwrite
case_dir = os.path.join(self._tempdir, site_name)
test_file = os.path.join(case_dir, "test_file")
pathlib.Path(test_file).touch()
self.assertTrue(os.path.exists(test_file))

# run the tool again, overwriting existing
sys.argv += ["--overwrite"]
print(sys.argv)
main("")

# ensure that file we created is gone
self.assertFalse(os.path.exists(test_file))


if __name__ == "__main__":
unit_testing.setup_for_tests()
Expand Down

0 comments on commit 6fd238f

Please sign in to comment.