Skip to content

Commit

Permalink
Merge 45f81b6 into a857635
Browse files Browse the repository at this point in the history
  • Loading branch information
jakehader committed Apr 29, 2022
2 parents a857635 + 45f81b6 commit 03776bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion armi/utils/directoryChangers.py
Expand Up @@ -50,7 +50,8 @@ class DirectoryChanger:
filesToMove : list of str, optional
Filenames to bring from the CWD into the destination
filesToRetrieve : list of str, optional
Filenames to bring back from the destination to the cwd
Filenames to bring back from the destination to the cwd. Note that if any of these
files do not exist then the file will be skipped and a warning will be provided.
dumpOnException : bool, optional
Flag to tell system to retrieve the entire directory if an exception
is raised within a the context manager.
Expand Down Expand Up @@ -185,6 +186,10 @@ def _transferFiles(initialPath, destinationPath, fileList):

for fromName, destName in copies:
fromPath = os.path.join(initialPath, fromName)
if not os.path.exists(fromPath):
runLog.warning(f"{fromPath} does not exist and will not be copied.")
continue

toPath = os.path.join(destinationPath, destName)
runLog.extra("Copying {} to {}".format(fromPath, toPath))
shutil.copy(fromPath, toPath)
Expand Down
16 changes: 16 additions & 0 deletions armi/utils/tests/test_directoryChangers.py
Expand Up @@ -142,3 +142,19 @@ def f(name):
self.assertTrue(os.path.exists(f("file2.txt")))
os.remove(f("file1.txt"))
os.remove(f("file2.txt"))

def test_file_retrieval_missing_file(self):
"""Tests that the directory changer still returns a subset of files even if all do not exist."""

def f(name):
"""Utility to avoid test clashes during cleanups"""
return self._testMethodName + name

with directoryChangers.TemporaryDirectoryChanger(
filesToRetrieve=[f("file1.txt"), f("file2.txt")]
):
Path(f("file1.txt")).touch()

self.assertTrue(os.path.exists(f("file1.txt")))
self.assertFalse(os.path.exists(f("file2.txt")))
os.remove(f("file1.txt"))

0 comments on commit 03776bb

Please sign in to comment.