-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sorter.py
More file actions
32 lines (28 loc) · 1.11 KB
/
test_sorter.py
File metadata and controls
32 lines (28 loc) · 1.11 KB
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
import os
import shutil
import tempfile
from ImageSorterCore import move_to_type_folder, move_to_other_folder, is_image_file
def test_move_to_type_folder():
with tempfile.TemporaryDirectory() as tmpdir:
test_file = os.path.join(tmpdir, 'test.JPG')
with open(test_file, 'w') as f:
f.write('dummy')
ok, err = move_to_type_folder(test_file, tmpdir)
assert ok, f"Failed to move: {err}"
assert os.path.exists(os.path.join(tmpdir, 'JPG', 'test.JPG'))
def test_move_to_other_folder():
with tempfile.TemporaryDirectory() as tmpdir:
test_file = os.path.join(tmpdir, 'test.xyz')
with open(test_file, 'w') as f:
f.write('dummy')
ok, err = move_to_other_folder(test_file, tmpdir)
assert ok, f"Failed to move: {err}"
assert os.path.exists(os.path.join(tmpdir, 'Other', 'test.xyz'))
def test_is_image_file():
assert is_image_file('foo.JPG')
assert not is_image_file('foo.xyz')
if __name__ == '__main__':
test_move_to_type_folder()
test_move_to_other_folder()
test_is_image_file()
print('All tests passed!')