forked from whtsky/resubname
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_resubname.py
63 lines (46 loc) · 1.76 KB
/
test_resubname.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
from pathlib import Path
import pytest
import shutil
from uuid import uuid4
from resubname import cli
FIXTURES_PATH = Path(__file__).parent / "fixtures"
def sorted_glob(p: Path, pattern="*"):
"""
return sorted filenames for matched files.
"""
names = [x.name for x in p.glob(pattern)]
names.sort()
return names
def copy_fixtures(src: Path, tmp_path: Path) -> Path:
fixture_path = tmp_path / uuid4().hex
shutil.copytree(src, fixture_path)
return fixture_path
def test_rename(capsys, tmp_path: Path, snapshot):
fixtures = copy_fixtures(FIXTURES_PATH / "basic", tmp_path)
files_before = sorted_glob(fixtures)
snapshot.assert_match(files_before)
cli([str(fixtures)])
files_after = sorted_glob(fixtures)
assert files_after != files_before
snapshot.assert_match(files_after)
def test_dryrun(capsys, tmp_path: Path, snapshot):
fixtures = copy_fixtures(FIXTURES_PATH / "basic", tmp_path)
files_before = sorted_glob(fixtures)
cli([str(fixtures), "--dryrun"])
files_after = sorted_glob(fixtures)
assert files_after == files_before
out, err = capsys.readouterr()
snapshot.assert_match(out.replace(str(fixtures.resolve()), ""))
def test_raise_when_subtitle_and_videos_number_dismatch():
path = FIXTURES_PATH / "exclude"
with pytest.raises(Exception):
cli([str(path)])
def test_exclude(capsys, tmp_path: Path, snapshot):
fixtures = copy_fixtures(FIXTURES_PATH / "exclude", tmp_path)
files_before = sorted_glob(fixtures)
cli([str(fixtures), "-e", "creditless"])
files_after = sorted_glob(fixtures)
assert files_after != files_before
snapshot.assert_match(files_after)
out, err = capsys.readouterr()
snapshot.assert_match(out.replace(str(fixtures.resolve()), ""))