-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
executable file
·101 lines (77 loc) · 2.54 KB
/
test.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env pytest
# SPDX-License-Identifier: WTFPL
import os
from pathlib import Path
from subprocess import check_call
from shutil import copy
from uuid import uuid4
import vignette
import pytest
os.chdir(Path(__file__).parent)
@pytest.fixture()
def src_path(tmp_path):
tmp_path.joinpath('foo').mkdir()
copy(
'test.png',
str(tmp_path.joinpath('foo/1.png'))
)
yield tmp_path.joinpath('foo')
@pytest.fixture(params=[0, 1])
def dst_path(tmp_path, request):
if request.param == 0:
ret = tmp_path.joinpath('bar')
else:
ret = Path(f'/run/user/{os.getuid()}/test-{uuid4()}/bar')
ret.parent.mkdir(parents=True)
ret.mkdir()
return ret
def test_file_file(src_path, dst_path):
othumb = vignette.get_thumbnail(str(src_path / '1.png'), 'large')
assert Path(othumb).exists()
assert src_path.joinpath('1.png').exists()
check_call([
'./mv-with-thumb',
str(src_path / '1.png'),
str(dst_path / '2.png'),
])
assert not src_path.joinpath('1.png').exists()
assert dst_path.joinpath('2.png').exists()
assert not Path(othumb).exists()
assert vignette.try_get_thumbnail(str(dst_path / '2.png'))
def test_file_dir(src_path, dst_path):
othumb = vignette.get_thumbnail(str(src_path / '1.png'))
assert Path(othumb).exists()
assert src_path.joinpath('1.png').exists()
check_call([
'./mv-with-thumb',
str(src_path / '1.png'),
str(dst_path),
])
assert not src_path.joinpath('1.png').exists()
assert dst_path.joinpath('1.png').exists()
assert not Path(othumb).exists()
assert vignette.try_get_thumbnail(str(dst_path / '1.png'))
def test_dir_name(src_path, dst_path):
othumb = vignette.get_thumbnail(str(src_path / '1.png'))
assert Path(othumb).exists()
assert src_path.joinpath('1.png').exists()
check_call([
'./mv-with-thumb',
str(src_path),
str(dst_path / 'quack'),
])
assert not src_path.exists()
assert dst_path.joinpath('quack').exists()
assert dst_path.joinpath('quack/1.png').exists()
assert not Path(othumb).exists()
assert vignette.try_get_thumbnail(str(dst_path / 'quack/1.png'))
def test_dir_subdir(src_path, dst_path):
othumb = vignette.get_thumbnail(str(src_path / '1.png'))
check_call([
'./mv-with-thumb',
str(src_path),
str(dst_path),
])
assert not Path(othumb).exists()
assert dst_path.joinpath('foo/1.png').exists()
assert vignette.try_get_thumbnail(str(dst_path.joinpath('foo/1.png')))