fix tests

This commit is contained in:
cmcmarrow 2022-02-27 14:07:27 -06:00
parent 266c0e0e92
commit f51454733f
2 changed files with 8 additions and 7 deletions

View file

@ -400,7 +400,7 @@ def _remove_job_dir(job_path):
# Remove job dir
try:
shutil.rmtree(job_path)
except NotADirectoryError as err:
except (NotADirectoryError, OSError) as err:
log.error("Unable to remove %s: %s", job_path, err)

View file

@ -3,13 +3,14 @@ from tests.support.mock import patch
def test_remove_job_dir():
# Test that _remove_job_dir job will NotADirectoryError error
with patch("shutil.rmtree", side_effect=NotADirectoryError("Node Corruption!")):
_remove_job_dir("cache.json")
# Test that _remove_job_dir job will catch error
for e in (NotADirectoryError, OSError):
with patch("shutil.rmtree", side_effect=e("Node Corruption!")):
_remove_job_dir("cache.json")
# Test that _remove_job_dir job will not catch other file errors
with patch("shutil.rmtree", side_effect=OSError()):
# Test that _remove_job_dir job will not catch other errors
with patch("shutil.rmtree", side_effect=FileExistsError()):
try:
_remove_job_dir("cache.json")
except OSError:
except FileExistsError:
pass