-
Notifications
You must be signed in to change notification settings - Fork 949
/
test_rm.py
66 lines (49 loc) · 2.44 KB
/
test_rm.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
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
# Check it is importable from tools
from conan.tools.files import rm
from conans.client.tools.files import chdir
from conans.test.utils.test_files import temp_folder
from conans.util.files import save_files
def test_remove_files_by_mask_recursively():
tmpdir = temp_folder()
with chdir(tmpdir):
os.makedirs("subdir")
os.makedirs("dir.pdb")
os.makedirs(os.path.join("subdir", "deepdir"))
save_files(tmpdir, {"1.txt": "",
"1.pdb": "",
"1.pdb1": "",
os.path.join("subdir", "2.txt"): "",
os.path.join("subdir", "2.pdb"): "",
os.path.join("subdir", "2.pdb1"): "",
os.path.join("subdir", "deepdir", "3.txt"): "",
os.path.join("subdir", "deepdir", "3.pdb"): "",
os.path.join("subdir", "deepdir", "3.pdb1"): ""})
rm(None, "*.sh", tmpdir, recursive=True)
removed_files = rm(None, "*.pdb", tmpdir, recursive=True)
assert os.path.isdir(os.path.join(tmpdir, "dir.pdb"))
assert os.path.isfile(os.path.join(tmpdir, "1.txt"))
assert not os.path.isfile(os.path.join(tmpdir, "1.pdb"))
assert os.path.isfile(os.path.join(tmpdir, "1.pdb1"))
assert os.path.isfile(os.path.join(tmpdir, "subdir", "2.txt"))
assert not os.path.isfile(os.path.join(tmpdir, "subdir", "2.pdb"))
assert os.path.isfile(os.path.join(tmpdir, "subdir", "2.pdb1"))
assert os.path.isfile(os.path.join(tmpdir, "subdir", "deepdir", "3.txt"))
assert not os.path.isfile(os.path.join(tmpdir, "subdir", "deepdir", "3.pdb"))
assert os.path.isfile(os.path.join(tmpdir, "subdir", "deepdir", "3.pdb1"))
rm(None, "*.pdb", tmpdir, recursive=True)
def test_remove_files_by_mask_non_recursively():
tmpdir = temp_folder()
with chdir(tmpdir):
os.makedirs("subdir")
save_files(tmpdir, {"1.txt": "",
"1.pdb": "",
"1.pdb1": "",
os.path.join("subdir", "2.txt"): "",
os.path.join("subdir", "2.pdb"): "",
os.path.join("subdir", "2.pdb1"): ""})
rm(None, "*.pdb", tmpdir)
assert not os.path.exists(os.path.join(tmpdir, "1.pdb"))
assert os.path.exists(os.path.join(tmpdir, "subdir", "2.pdb"))
assert os.path.exists(os.path.join(tmpdir, "1.txt"))
assert os.path.exists(os.path.join(tmpdir, "subdir", "2.txt"))