Skip to content

Commit

Permalink
Log PermissionError, add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenp-noaa committed Jan 30, 2025
1 parent 0cc613e commit 9b267f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/uwtools/tests/utils/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/uwtools/utils/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b267f5

Please sign in to comment.