Skip to content

Commit

Permalink
Be sure to save the original directory and change it it before deleti…
Browse files Browse the repository at this point in the history
…ng the temp one, which allows all tests to work
  • Loading branch information
ekluzek committed Jan 11, 2024
1 parent 69c5866 commit 59d45d0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/ctsm/test/test_sys_gen_mksurfdata_jobscript_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TestSysGenMkSurfJSMulti(unittest.TestCase):

def setUp(self):
"""Setp temporary directory to make the files in"""
self._original_wd = os.getcwd()
self._tempdir = tempfile.mkdtemp()
os.chdir(self._tempdir)
self.outfile = "jobscript.sh"
Expand All @@ -43,6 +44,7 @@ def tearDown(self):
"""
Remove temporary directory
"""
os.chdir(self._original_wd)
shutil.rmtree(self._tempdir, ignore_errors=True)

def createJS(self, nodes, tasks_per_node, scenario, option_list=[]):
Expand Down
2 changes: 2 additions & 0 deletions python/ctsm/test/test_sys_gen_mksurfdata_jobscript_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TestSysGenMkSurfJSSingle(unittest.TestCase):

def setUp(self):
"""Setp temporary directory to make the files in"""
self._original_wd = os.getcwd()
self._tempdir = tempfile.mkdtemp()
os.chdir(self._tempdir)
self.outfile = "jobscript.sh"
Expand All @@ -46,6 +47,7 @@ def tearDown(self):
"""
Remove temporary directory
"""
os.chdir(self._original_wd)
shutil.rmtree(self._tempdir, ignore_errors=True)

def createJS(self, nodes, tasks_per_node, option_list=[]):
Expand Down
2 changes: 2 additions & 0 deletions python/ctsm/test/test_sys_gen_mksurfdata_namelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def setUp(self):
"""Setp temporary directory to make the files in"""
testinputs_path = os.path.join(path_to_ctsm_root(), "python/ctsm/test/testinputs")
self._testinputs_path = testinputs_path
self._original_wd = os.getcwd()
self._tempdir = tempfile.mkdtemp()
os.chdir(self._tempdir)
self.outfile = "surfdata.namelist"
Expand All @@ -40,6 +41,7 @@ def tearDown(self):
"""
Remove temporary directory
"""
os.chdir(self._original_wd)
shutil.rmtree(self._tempdir, ignore_errors=True)

def test_simple_namelist(self):
Expand Down
5 changes: 5 additions & 0 deletions python/ctsm/test/test_sys_lilac_build_ctsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ def setUp(self):
else:
self._ncarhost = None

self._original_wd = os.getcwd()
os.chdir(self._tempdir)

def tearDown(self):
"""tear down"""
os.chdir(self._original_wd)
shutil.rmtree(self._tempdir, ignore_errors=True)
if self._ncarhost is not None:
os.environ["NCAR_HOST"] = self._ncarhost
Expand Down

0 comments on commit 59d45d0

Please sign in to comment.