75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
import os
|
|
import shutil
|
|
import pytest
|
|
|
|
_test_filenames = [
|
|
"[Erai-raws] Fate Stay Night - Heaven s Feel - THE MOVIE III. spring song [1080p CR WEB-DL AVC AAC][MultiSub][BE0BDDA7]",
|
|
"[Erai-raws] fugukan - 03 [1080p CR WEB-DL AVC AAC][MultiSub][983AA6EF]",
|
|
"[Erai-raws] Golden Kamuy OVA - 02 [1080p CR WEB-DL AVC AAC][MultiSub][A731ADF8]",
|
|
"[Erai-raws] Goukon ni Ittara Onna ga Inakatta Hanashi - 12 [1080p HIDIVE WEB-DL AVC AAC][23F96132]",
|
|
"[Erai-raws] Grisaia Phantom Trigger - 04 [1080p CR WEBRip HEVC EAC3][MultiSub][27B78FFC]",
|
|
"[Erai-raws] Detective Conan - 1147 [1080p CR WEBRip HEVC EAC3][476E9FBE]",
|
|
"[Erai-raws] 2_5 Jigen no Ririsa - 23 [1080p HIDIVE WEB-DL AVC AAC][F6A89707]"
|
|
]
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def test_setup():
|
|
os.makedirs("tests/test_data", exist_ok=True)
|
|
for filename in _test_filenames:
|
|
with open(os.path.join("tests/test_data", filename), 'w') as f:
|
|
f.write("test content")
|
|
|
|
yield
|
|
|
|
shutil.rmtree("tests/test_data", ignore_errors=True)
|
|
|
|
def test_filemoving_nodownloads():
|
|
from src.filemoving import group_files_by_prefix
|
|
patterns = [r"^\[Erai-raws\] (.*)(?= - ).*$"]
|
|
|
|
|
|
expected_dirs = [
|
|
"Fate Stay Night - Heaven s Feel",
|
|
"fugukan",
|
|
"Golden Kamuy OVA",
|
|
"Goukon ni Ittara Onna ga Inakatta Hanashi",
|
|
"Grisaia Phantom Trigger",
|
|
"Detective Conan",
|
|
"2_5 Jigen no Ririsa"
|
|
]
|
|
|
|
group_files_by_prefix("tests/test_data", [], patterns)
|
|
|
|
for i in range(len(expected_dirs)):
|
|
assert os.path.exists(os.path.join("tests/test_data", expected_dirs[i]))
|
|
assert os.path.exists(os.path.join("tests/test_data", expected_dirs[i], _test_filenames[i]))
|
|
assert not os.path.exists(os.path.join("tests/test_data", _test_filenames[i]))
|
|
|
|
|
|
def test_filemoving_ignores_downloads():
|
|
from src.filemoving import group_files_by_prefix
|
|
patterns = [r"^\[Erai-raws\] (.*)(?= - ).*$"]
|
|
|
|
downloads = [
|
|
_test_filenames[0],
|
|
_test_filenames[2],
|
|
_test_filenames[4]
|
|
]
|
|
|
|
expected_dirs = [
|
|
"fugukan",
|
|
"Goukon ni Ittara Onna ga Inakatta Hanashi",
|
|
"Detective Conan",
|
|
"2_5 Jigen no Ririsa"
|
|
]
|
|
|
|
|
|
group_files_by_prefix("tests/test_data", downloads, patterns)
|
|
|
|
|
|
for root, dirs, files in os.walk("tests/test_data"):
|
|
if root == "tests/test_data":
|
|
for dir in dirs:
|
|
assert dir in expected_dirs
|
|
for file in files:
|
|
assert file in downloads |