From 9b267f5478671831f9b2a3048ee5fe58a435537d Mon Sep 17 00:00:00 2001 From: Paul Madden Date: Thu, 30 Jan 2025 15:59:53 +0000 Subject: [PATCH] Log PermissionError, add unit test --- src/uwtools/tests/utils/test_tasks.py | 9 +++++++++ src/uwtools/utils/tasks.py | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/uwtools/tests/utils/test_tasks.py b/src/uwtools/tests/utils/test_tasks.py index 2f72d626a..335dd767a 100644 --- a/src/uwtools/tests/utils/test_tasks.py +++ b/src/uwtools/tests/utils/test_tasks.py @@ -35,6 +35,15 @@ def test_tasks_directory(tmp_path): assert p.is_dir() +def test_tasks_directory_fail(caplog, tmp_path): + os.chmod(tmp_path, 0o550) + p = tmp_path / "foo" + assert not iotaa.ready(tasks.directory(path=p)) + assert not p.is_dir() + os.chmod(tmp_path, 0o750) + assert logged(caplog, "[Errno 13] Permission denied: '%s'" % p) + + def test_tasks_executable(tmp_path): p = tmp_path / "program" # Ensure that only our temp directory is on the path: diff --git a/src/uwtools/utils/tasks.py b/src/uwtools/utils/tasks.py index 8a38688c2..a876a29c5 100644 --- a/src/uwtools/utils/tasks.py +++ b/src/uwtools/utils/tasks.py @@ -30,8 +30,8 @@ def directory(path: Path): yield None try: path.mkdir(parents=True, exist_ok=True) - except PermissionError: - pass + except PermissionError as e: + log.error(str(e)) @external