-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathtest_cleanup.py
53 lines (43 loc) · 1.58 KB
/
test_cleanup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from pathlib import Path
import pytest
from plumbum import local
import copier
def test_cleanup(tmp_path: Path) -> None:
"""Copier creates dst_path, fails to copy and removes it."""
dst = tmp_path / "new_folder"
with pytest.raises(copier.errors.TaskError):
copier.run_copy("./tests/demo_cleanup", dst, quiet=True, unsafe=True)
assert not dst.exists()
def test_do_not_cleanup(tmp_path: Path) -> None:
"""Copier creates dst_path, fails to copy and keeps it."""
dst = tmp_path / "new_folder"
with pytest.raises(copier.errors.TaskError):
copier.run_copy(
"./tests/demo_cleanup", dst, quiet=True, unsafe=True, cleanup_on_error=False
)
assert dst.exists()
def test_no_cleanup_when_folder_existed(tmp_path: Path) -> None:
"""Copier will not delete a folder if it didn't create it."""
preexisting_file = tmp_path / "something"
preexisting_file.touch()
with pytest.raises(copier.errors.TaskError):
copier.run_copy(
"./tests/demo_cleanup",
tmp_path,
quiet=True,
unsafe=True,
cleanup_on_error=True,
)
assert tmp_path.exists()
assert preexisting_file.exists()
def test_no_cleanup_when_template_in_parent_folder(tmp_path: Path) -> None:
"""Copier will not delete a local template in a parent folder."""
src = tmp_path / "src"
src.mkdir()
dst = tmp_path / "dst"
dst.mkdir()
cwd = tmp_path / "cwd"
cwd.mkdir()
with local.cwd(cwd):
copier.run_copy(str(Path("..", "src")), dst, quiet=True)
assert src.exists()