-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_dirganize.py
executable file
·77 lines (57 loc) · 1.38 KB
/
test_dirganize.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
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
# pylint: skip-file
import logging
import os
import shutil
import click
import pytest
from dirganize import cli
def create_files(folder, *files):
cwd = os.getcwd()
os.chdir(folder)
for file in files:
with open(file, "w"):
pass
os.chdir(cwd)
def test_dirganize():
sb = "sandbox"
try:
shutil.rmtree(sb)
except:
pass
os.makedirs(sb)
files = [
"a.mp4",
"b.mp3",
"c.png",
"d.py",
".dotfile",
"what",
"e.gif",
".dirganize.yml",
]
create_files(sb, *files)
with open(os.path.join(sb, ".dirganize.yml"), "w") as file:
file.write("Animations: [gif]")
with pytest.raises(click.exceptions.Exit):
cli.version_callback(value=True)
cli.verbosity_callback(value=True)
assert set(os.listdir(sb)) == set(files)
cli.main(sb) # cwd changes to sb
assert set(os.listdir()) == set(
[
".dirganize.yml",
".dotfile",
"Images",
"Others",
"Videos",
"Audios",
"Texts",
"Animations",
]
)
assert set(os.listdir("Others")) == set(["what"])
assert set(os.listdir("Animations")) == set(["e.gif"])
assert set(os.listdir("Audios")) == set(["b.mp3"])
if __name__ == "__main__":
test_dirganize()