Skip to content

Commit

Permalink
Create parent directories in file copy mode (ufs-community#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenp-noaa authored May 15, 2024
1 parent fcfe2ab commit fc0ca6f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/uwtools/tests/utils/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_tasks_file_present(tmp_path):
assert ready(tasks.file(path=path))


def test_tasks_filecopy(tmp_path):
def test_tasks_filecopy_simple(tmp_path):
src = tmp_path / "src"
dst = tmp_path / "dst"
src.touch()
Expand All @@ -73,10 +73,28 @@ def test_tasks_filecopy(tmp_path):
assert dst.is_file()


def test_tasks_symlink(tmp_path):
def test_tasks_filecopy_directory_hierarchy(tmp_path):
src = tmp_path / "src"
dst = tmp_path / "foo" / "bar" / "dst"
src.touch()
assert not dst.is_file()
tasks.filecopy(src=src, dst=dst)
assert dst.is_file()


def test_tasks_symlink_simple(tmp_path):
target = tmp_path / "target"
link = tmp_path / "link"
target.touch()
assert not link.is_file()
tasks.symlink(target=target, linkname=link)
assert link.is_symlink()


def test_tasks_symlink_directory_hierarchy(tmp_path):
target = tmp_path / "target"
link = tmp_path / "foo" / "bar" / "link"
target.touch()
assert not link.is_file()
tasks.symlink(target=target, linkname=link)
assert link.is_symlink()
2 changes: 1 addition & 1 deletion src/uwtools/utils/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def filecopy(src: Path, dst: Path):
yield "Copy %s -> %s" % (src, dst)
yield asset(dst, dst.is_file)
yield file(src)
dst.parent.mkdir(exist_ok=True)
dst.parent.mkdir(parents=True, exist_ok=True)
copy(src, dst)


Expand Down

0 comments on commit fc0ca6f

Please sign in to comment.