115 lines
4.2 KiB
Python
115 lines
4.2 KiB
Python
"""Tests for series naming/scanning (src.core.series) + FileManager episodes."""
|
|
import pytest
|
|
|
|
from src.core.series import (
|
|
episode_filename,
|
|
is_canonical_episode,
|
|
parse_episode,
|
|
scan_series,
|
|
season_folder_name,
|
|
series_folder_stem,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("name,expected", [
|
|
("Breaking Bad S01E02.mkv", (1, 2)),
|
|
("bb.s1e2.mkv", (1, 2)),
|
|
("Show 01x02 x264.mkv", (1, 2)),
|
|
("Series.S01E02E03.mkv", (1, 2)), # multi-ep → first
|
|
("Series S12E145.mkv", (12, 145)),
|
|
("No code here.mkv", None),
|
|
])
|
|
def test_parse_episode(name, expected):
|
|
assert parse_episode(name) == expected
|
|
|
|
|
|
def test_season_folder_name():
|
|
assert season_folder_name(0) == "Specials"
|
|
assert season_folder_name(1) == "Season 01"
|
|
assert season_folder_name(12) == "Season 12"
|
|
|
|
|
|
def test_episode_filename():
|
|
assert episode_filename("Breaking Bad", 1, 2, ".mkv") == "Breaking Bad S01E02.mkv"
|
|
|
|
|
|
def test_series_folder_stem():
|
|
assert series_folder_stem("Breaking Bad", 2008, 1396) == "Breaking Bad (2008) [tmdbid-1396]"
|
|
assert series_folder_stem("Neznámý", None, 42) == "Neznámý [tmdbid-42]"
|
|
assert series_folder_stem("Jen název", None, None) == "Jen název"
|
|
|
|
|
|
def test_is_canonical_episode(tmp_path):
|
|
folder = tmp_path / "Breaking Bad (2008) [tmdbid-1396]" / "Season 01"
|
|
folder.mkdir(parents=True)
|
|
good = folder / "Breaking Bad S01E02.mkv"
|
|
good.write_bytes(b"x")
|
|
bad = folder / "bb.s01e02.mkv"
|
|
bad.write_bytes(b"x")
|
|
assert is_canonical_episode(good, "Breaking Bad")
|
|
assert not is_canonical_episode(bad, "Breaking Bad")
|
|
|
|
|
|
def test_scan_series(tmp_path):
|
|
lib = tmp_path / "Seriály"
|
|
s1 = lib / "Breaking Bad (2008) [tmdbid-1396]" / "Season 01"
|
|
s1.mkdir(parents=True)
|
|
(s1 / "Breaking Bad S01E01.mkv").write_bytes(b"x")
|
|
(s1 / "Breaking Bad S01E02.mkv").write_bytes(b"x")
|
|
(s1 / "poster.jpg").write_bytes(b"img") # sidecar → skipped
|
|
|
|
found = scan_series(lib, "Seriály")
|
|
assert len(found) == 1
|
|
ser = found[0]
|
|
assert ser.title == "Breaking Bad" and ser.year == "2008" and ser.tmdb_id == 1396
|
|
assert ser.library == "Seriály"
|
|
assert len(ser.episodes) == 2
|
|
seasons = ser.seasons()
|
|
assert list(seasons.keys()) == [1] and len(seasons[1]) == 2
|
|
|
|
|
|
class TestFileManagerSeries:
|
|
@pytest.fixture
|
|
def file_manager(self, tmp_path, monkeypatch):
|
|
import src.core.config as config_module
|
|
monkeypatch.setattr(config_module, "GLOBAL_CONFIG_FILE", tmp_path / ".gtag")
|
|
from src.core.tag_manager import TagManager
|
|
from src.core.file_manager import FileManager
|
|
fm = FileManager(TagManager())
|
|
fm.set_pool_dir(tmp_path / "pool")
|
|
return fm
|
|
|
|
def test_import_episodes_places_them(self, file_manager, tmp_path):
|
|
for n in ("bb.S01E01.mkv", "bb.S01E02.mkv", "notes.txt_S00.dummy"):
|
|
(tmp_path / n).write_bytes(b"x")
|
|
result = file_manager.import_episodes(
|
|
[tmp_path / "bb.S01E01.mkv", tmp_path / "bb.S01E02.mkv"],
|
|
"Breaking Bad", year=2008, tmdb_id=1396)
|
|
|
|
assert result["imported"] == 2
|
|
base = (tmp_path / "pool" / "Seriály"
|
|
/ "Breaking Bad (2008) [tmdbid-1396]" / "Season 01")
|
|
assert (base / "Breaking Bad S01E01.mkv").exists()
|
|
assert (base / "Breaking Bad S01E02.mkv").exists()
|
|
|
|
def test_import_episodes_skips_uncoded(self, file_manager, tmp_path):
|
|
(tmp_path / "random.mkv").write_bytes(b"x")
|
|
result = file_manager.import_episodes(
|
|
[tmp_path / "random.mkv"], "Breaking Bad", year=2008)
|
|
assert result["imported"] == 0
|
|
assert result["skipped_no_code"] == ["random.mkv"]
|
|
|
|
def test_rename_episodes_to_canonical(self, file_manager, tmp_path):
|
|
# a mis-named episode sitting in the wrong place
|
|
folder = (tmp_path / "pool" / "Seriály"
|
|
/ "Breaking Bad (2008) [tmdbid-1396]")
|
|
folder.mkdir(parents=True)
|
|
(folder / "bb.1x03.HDTV.mkv").write_bytes(b"x")
|
|
|
|
series_list = file_manager.load_series()
|
|
assert len(series_list) == 1
|
|
result = file_manager.rename_episodes_to_canonical(series_list[0])
|
|
|
|
assert result["renamed"] == [("bb.1x03.HDTV.mkv", "Breaking Bad S01E03.mkv")]
|
|
assert (folder / "Season 01" / "Breaking Bad S01E03.mkv").exists()
|