Migrate from Poetry and pyenv to uv
This commit is contained in:
+304
-49
@@ -1,12 +1,16 @@
|
||||
"""Tests for series naming/scanning (src.core.series) + FileManager episodes."""
|
||||
|
||||
import pytest
|
||||
|
||||
from src.core.series import (
|
||||
Episode,
|
||||
collect_episode_files,
|
||||
episode_filename,
|
||||
is_canonical_episode,
|
||||
is_season_folder,
|
||||
parse_episode,
|
||||
parse_episode_code,
|
||||
parse_episode_part,
|
||||
sanitize_title,
|
||||
scan_series,
|
||||
season_folder_name,
|
||||
@@ -14,14 +18,17 @@ from src.core.series import (
|
||||
)
|
||||
|
||||
|
||||
@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),
|
||||
])
|
||||
@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
|
||||
|
||||
@@ -36,8 +43,10 @@ def test_episode_filename_is_code_plus_series_title():
|
||||
assert episode_filename(1, 2, "Most!", ".mkv") == "S01E02 - Most!.mkv"
|
||||
assert episode_filename(0, 3, "Most!", ".mkv") == "S00E03 - Most!.mkv"
|
||||
# release string is NOT kept — only the code + series title
|
||||
assert episode_filename(12, 145, "Breaking Bad", ".mkv") == \
|
||||
"S12E145 - Breaking Bad.mkv"
|
||||
assert (
|
||||
episode_filename(12, 145, "Breaking Bad", ".mkv")
|
||||
== "S12E145 - Breaking Bad.mkv"
|
||||
)
|
||||
# empty / unusable title → just the code
|
||||
assert episode_filename(3, 4, "", ".mkv") == "S03E04.mkv"
|
||||
assert episode_filename(3, 4, "/", ".mkv") == "S03E04.mkv"
|
||||
@@ -45,7 +54,7 @@ def test_episode_filename_is_code_plus_series_title():
|
||||
|
||||
def test_sanitize_title():
|
||||
assert sanitize_title("Most!") == "Most!"
|
||||
assert sanitize_title('A: B / C D') == "A B C D"
|
||||
assert sanitize_title("A: B / C D") == "A B C D"
|
||||
assert sanitize_title(" trailing. ") == "trailing"
|
||||
|
||||
|
||||
@@ -58,11 +67,61 @@ def test_is_season_folder():
|
||||
|
||||
|
||||
def test_series_folder_stem():
|
||||
assert series_folder_stem("Breaking Bad", 2008, 1396) == "Breaking Bad (2008) [tmdbid-1396]"
|
||||
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"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"name,expected",
|
||||
[
|
||||
("Show S01E02.pt2.mkv", 2),
|
||||
("Show S01E01-part-1.mkv", 1),
|
||||
("Show S01E01 part 1.mkv", 1),
|
||||
("Show S01E01_cd1.mkv", 1),
|
||||
("Show S01E01.disc2.mkv", 2),
|
||||
("Show S01E01.mkv", None),
|
||||
("Show Abcd2.mkv", None), # "cd2" mid-word — not a stacking suffix
|
||||
("Show Part of Something.mkv", None), # no digit right after → not a match
|
||||
],
|
||||
)
|
||||
def test_parse_episode_part(name, expected):
|
||||
assert parse_episode_part(name) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"text,expected",
|
||||
[
|
||||
("S01E02P3", (1, 2, 3)),
|
||||
("s1e2p3", (1, 2, 3)),
|
||||
("S01E02 pt3", (1, 2, 3)),
|
||||
("S01E02.part.3", (1, 2, 3)),
|
||||
("S01E02 cd2", (1, 2, 2)),
|
||||
("S01E02", (1, 2, None)),
|
||||
("1x02", (1, 2, None)),
|
||||
("no code here", None),
|
||||
],
|
||||
)
|
||||
def test_parse_episode_code(text, expected):
|
||||
assert parse_episode_code(text) == expected
|
||||
|
||||
|
||||
def test_episode_filename_with_part():
|
||||
assert episode_filename(1, 2, "Most!", ".mkv", part=3) == "S01E02 - Most!.pt3.mkv"
|
||||
assert episode_filename(1, 2, "", ".mkv", part=2) == "S01E02.pt2.mkv"
|
||||
# no part → unchanged from the plain form
|
||||
assert episode_filename(1, 2, "Most!", ".mkv", part=None) == "S01E02 - Most!.mkv"
|
||||
|
||||
|
||||
def test_episode_code_property_includes_part():
|
||||
assert Episode(None, 1, 2, part=3).code == "S01E02.pt3"
|
||||
assert Episode(None, 1, 2).code == "S01E02"
|
||||
assert Episode(None, None, None).code == "?"
|
||||
|
||||
|
||||
def test_is_canonical_episode(tmp_path):
|
||||
folder = tmp_path / "Breaking Bad (2008) [tmdbid-1396]" / "Season 01"
|
||||
folder.mkdir(parents=True)
|
||||
@@ -77,6 +136,17 @@ def test_is_canonical_episode(tmp_path):
|
||||
assert not is_canonical_episode(wrong_body, "Breaking Bad")
|
||||
|
||||
|
||||
def test_is_canonical_episode_with_part(tmp_path):
|
||||
folder = tmp_path / "Show (2008) [tmdbid-1]" / "Season 01"
|
||||
folder.mkdir(parents=True)
|
||||
good = folder / "S01E02 - Show.pt1.mkv"
|
||||
good.write_bytes(b"x")
|
||||
old_style = folder / "S01E02-part-1.mkv" # recognised, but not our own form
|
||||
old_style.write_bytes(b"x")
|
||||
assert is_canonical_episode(good, "Show")
|
||||
assert not is_canonical_episode(old_style, "Show")
|
||||
|
||||
|
||||
def test_scan_series(tmp_path):
|
||||
lib = tmp_path / "Seriály"
|
||||
s1 = lib / "Breaking Bad (2008) [tmdbid-1396]" / "Season 01"
|
||||
@@ -95,20 +165,36 @@ def test_scan_series(tmp_path):
|
||||
assert list(seasons.keys()) == [1] and len(seasons[1]) == 2
|
||||
|
||||
|
||||
def test_scan_series_reads_episode_parts(tmp_path):
|
||||
lib = tmp_path / "Seriály"
|
||||
s1 = lib / "Show (2008) [tmdbid-1]" / "Season 01"
|
||||
s1.mkdir(parents=True)
|
||||
(s1 / "Show S01E02.pt1.mkv").write_bytes(b"x")
|
||||
(s1 / "Show S01E02.pt2.mkv").write_bytes(b"x")
|
||||
|
||||
ser = scan_series(lib, "Seriály")[0]
|
||||
parts = sorted(ep.part for ep in ser.episodes)
|
||||
assert parts == [1, 2]
|
||||
assert {ep.code for ep in ser.episodes} == {"S01E02.pt1", "S01E02.pt2"}
|
||||
|
||||
|
||||
def test_collect_episode_files_walks_subfolders(tmp_path):
|
||||
root = tmp_path / "Breaking.Bad.COMPLETE"
|
||||
(root / "Season 01").mkdir(parents=True)
|
||||
(root / "Season 02").mkdir(parents=True)
|
||||
(root / "Season 01" / "BB S01E01.mkv").write_bytes(b"x")
|
||||
(root / "Season 01" / "BB S01E02.mkv").write_bytes(b"x")
|
||||
(root / "Season 01" / "BB S01E02.srt").write_bytes(b"x") # sidecar → skipped
|
||||
(root / "Season 01" / "BB S01E02.srt").write_bytes(b"x") # sidecar → skipped
|
||||
(root / "Season 02" / "BB S02E01.avi").write_bytes(b"x")
|
||||
(root / "readme.nfo").write_bytes(b"x") # sidecar → skipped
|
||||
(root / "readme.nfo").write_bytes(b"x") # sidecar → skipped
|
||||
|
||||
files = collect_episode_files(root)
|
||||
|
||||
assert [f.name for f in files] == [
|
||||
"BB S01E01.mkv", "BB S01E02.mkv", "BB S02E01.avi"]
|
||||
"BB S01E01.mkv",
|
||||
"BB S01E02.mkv",
|
||||
"BB S02E01.avi",
|
||||
]
|
||||
|
||||
|
||||
def test_collect_episode_files_missing_folder_is_empty(tmp_path):
|
||||
@@ -119,9 +205,11 @@ 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
|
||||
from src.core.tag_manager import TagManager
|
||||
|
||||
fm = FileManager(TagManager())
|
||||
fm.set_pool_dir(tmp_path / "pool")
|
||||
return fm
|
||||
@@ -131,11 +219,19 @@ class TestFileManagerSeries:
|
||||
(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)
|
||||
"Breaking Bad",
|
||||
year=2008,
|
||||
tmdb_id=1396,
|
||||
)
|
||||
|
||||
assert result["imported"] == 2
|
||||
base = (tmp_path / "pool" / "Seriály"
|
||||
/ "Breaking Bad (2008) [tmdbid-1396]" / "Season 01")
|
||||
base = (
|
||||
tmp_path
|
||||
/ "pool"
|
||||
/ "Seriály"
|
||||
/ "Breaking Bad (2008) [tmdbid-1396]"
|
||||
/ "Season 01"
|
||||
)
|
||||
assert (base / "S01E01 - Breaking Bad.mkv").exists()
|
||||
assert (base / "S01E02 - Breaking Bad.mkv").exists()
|
||||
|
||||
@@ -143,12 +239,22 @@ class TestFileManagerSeries:
|
||||
file_manager.set_libraries([{"name": "Hlavní", "kind": "mixed"}])
|
||||
(tmp_path / "bb.S01E01.mkv").write_bytes(b"x")
|
||||
result = file_manager.import_episodes(
|
||||
[tmp_path / "bb.S01E01.mkv"], "Breaking Bad", year=2008, tmdb_id=1396,
|
||||
library="Hlavní")
|
||||
[tmp_path / "bb.S01E01.mkv"],
|
||||
"Breaking Bad",
|
||||
year=2008,
|
||||
tmdb_id=1396,
|
||||
library="Hlavní",
|
||||
)
|
||||
|
||||
assert result["imported"] == 1
|
||||
assert (tmp_path / "pool" / "Hlavní" / "Breaking Bad (2008) [tmdbid-1396]"
|
||||
/ "Season 01" / "S01E01 - Breaking Bad.mkv").exists()
|
||||
assert (
|
||||
tmp_path
|
||||
/ "pool"
|
||||
/ "Hlavní"
|
||||
/ "Breaking Bad (2008) [tmdbid-1396]"
|
||||
/ "Season 01"
|
||||
/ "S01E01 - Breaking Bad.mkv"
|
||||
).exists()
|
||||
# a mixed library is scanned for series too
|
||||
found = file_manager.load_series()
|
||||
assert [s.title for s in found] == ["Breaking Bad"]
|
||||
@@ -156,7 +262,8 @@ class TestFileManagerSeries:
|
||||
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)
|
||||
[tmp_path / "random.mkv"], "Breaking Bad", year=2008
|
||||
)
|
||||
assert result["imported"] == 0
|
||||
assert result["skipped_no_code"] == ["random.mkv"]
|
||||
|
||||
@@ -165,7 +272,10 @@ class TestFileManagerSeries:
|
||||
(tmp_path / "bb.S02E01.mkv").write_bytes(b"x")
|
||||
file_manager.import_episodes(
|
||||
[tmp_path / "bb.S01E01.mkv", tmp_path / "bb.S02E01.mkv"],
|
||||
"Breaking Bad", year=2008, tmdb_id=1396)
|
||||
"Breaking Bad",
|
||||
year=2008,
|
||||
tmdb_id=1396,
|
||||
)
|
||||
(ser,) = file_manager.load_series()
|
||||
assert ser.folder.is_dir()
|
||||
|
||||
@@ -176,6 +286,7 @@ class TestFileManagerSeries:
|
||||
|
||||
def test_remove_series_refuses_folder_outside_pool(self, file_manager, tmp_path):
|
||||
from src.core.series import Series
|
||||
|
||||
outside = tmp_path / "not-the-pool" / "Show (2020)"
|
||||
outside.mkdir(parents=True)
|
||||
bogus = Series(outside, "Show", "2020", None, "Seriály")
|
||||
@@ -183,26 +294,141 @@ class TestFileManagerSeries:
|
||||
file_manager.remove_series(bogus)
|
||||
assert outside.is_dir() # untouched
|
||||
|
||||
def test_remove_episodes_deletes_files_and_subtitles(self, file_manager, tmp_path):
|
||||
(tmp_path / "bb.S01E01.mkv").write_bytes(b"x")
|
||||
(tmp_path / "bb.S01E02.mkv").write_bytes(b"x")
|
||||
file_manager.import_episodes(
|
||||
[tmp_path / "bb.S01E01.mkv", tmp_path / "bb.S01E02.mkv"],
|
||||
"Breaking Bad",
|
||||
year=2008,
|
||||
tmdb_id=1396,
|
||||
)
|
||||
(ser,) = file_manager.load_series()
|
||||
season = ser.seasons()[1]
|
||||
e1 = next(e for e in season if e.episode == 1)
|
||||
e2 = next(e for e in season if e.episode == 2)
|
||||
srt = e1.path.with_suffix(".srt")
|
||||
srt.write_bytes(b"x")
|
||||
|
||||
file_manager.remove_episodes([e1])
|
||||
|
||||
assert not e1.path.exists()
|
||||
assert not srt.exists()
|
||||
assert e2.path.exists() # untouched
|
||||
assert e1.path.parent.is_dir() # not empty — e2 is still there
|
||||
|
||||
def test_remove_episodes_cleans_up_the_now_empty_season_folder(
|
||||
self, file_manager, tmp_path
|
||||
):
|
||||
(tmp_path / "bb.S01E01.mkv").write_bytes(b"x")
|
||||
file_manager.import_episodes(
|
||||
[tmp_path / "bb.S01E01.mkv"], "Breaking Bad", year=2008, tmdb_id=1396
|
||||
)
|
||||
(ser,) = file_manager.load_series()
|
||||
(ep,) = ser.episodes
|
||||
season_folder = ep.path.parent
|
||||
|
||||
file_manager.remove_episodes([ep])
|
||||
|
||||
assert not ep.path.exists()
|
||||
assert not season_folder.exists()
|
||||
|
||||
def test_remove_season_deletes_every_episode_in_it(self, file_manager, tmp_path):
|
||||
(tmp_path / "bb.S01E01.mkv").write_bytes(b"x")
|
||||
(tmp_path / "bb.S01E02.mkv").write_bytes(b"x")
|
||||
(tmp_path / "bb.S02E01.mkv").write_bytes(b"x")
|
||||
file_manager.import_episodes(
|
||||
[
|
||||
tmp_path / "bb.S01E01.mkv",
|
||||
tmp_path / "bb.S01E02.mkv",
|
||||
tmp_path / "bb.S02E01.mkv",
|
||||
],
|
||||
"Breaking Bad",
|
||||
year=2008,
|
||||
tmdb_id=1396,
|
||||
)
|
||||
(ser,) = file_manager.load_series()
|
||||
season1_folder = ser.seasons()[1][0].path.parent
|
||||
|
||||
file_manager.remove_season(ser, 1)
|
||||
|
||||
assert not season1_folder.exists()
|
||||
(ser_after,) = file_manager.load_series()
|
||||
assert [ep.season for ep in ser_after.episodes] == [2]
|
||||
|
||||
def test_remove_season_raises_for_a_season_with_no_episodes(
|
||||
self, file_manager, tmp_path
|
||||
):
|
||||
(tmp_path / "bb.S01E01.mkv").write_bytes(b"x")
|
||||
file_manager.import_episodes(
|
||||
[tmp_path / "bb.S01E01.mkv"], "Breaking Bad", year=2008, tmdb_id=1396
|
||||
)
|
||||
(ser,) = file_manager.load_series()
|
||||
with pytest.raises(ValueError):
|
||||
file_manager.remove_season(ser, 9)
|
||||
|
||||
def test_import_episodes_uses_explicit_codes_override(self, file_manager, tmp_path):
|
||||
uncoded = tmp_path / "pilot.mkv"
|
||||
uncoded.write_bytes(b"x")
|
||||
misparsed = tmp_path / "bb 2008 e07.mkv" # "2008" would parse as 20x08
|
||||
misparsed.write_bytes(b"x")
|
||||
result = file_manager.import_episodes(
|
||||
[uncoded, misparsed], "Breaking Bad", year=2008, tmdb_id=1396,
|
||||
codes={uncoded: (1, 1), misparsed: (1, 7)})
|
||||
[uncoded, misparsed],
|
||||
"Breaking Bad",
|
||||
year=2008,
|
||||
tmdb_id=1396,
|
||||
codes={uncoded: (1, 1), misparsed: (1, 7)},
|
||||
)
|
||||
|
||||
assert result["imported"] == 2
|
||||
base = (tmp_path / "pool" / "Seriály"
|
||||
/ "Breaking Bad (2008) [tmdbid-1396]" / "Season 01")
|
||||
base = (
|
||||
tmp_path
|
||||
/ "pool"
|
||||
/ "Seriály"
|
||||
/ "Breaking Bad (2008) [tmdbid-1396]"
|
||||
/ "Season 01"
|
||||
)
|
||||
assert (base / "S01E01 - Breaking Bad.mkv").exists()
|
||||
assert (base / "S01E07 - Breaking Bad.mkv").exists()
|
||||
assert result["skipped_no_code"] == []
|
||||
|
||||
def test_import_episodes_uses_explicit_part_override(self, file_manager, tmp_path):
|
||||
tape1 = tmp_path / "tape1.mkv"
|
||||
tape1.write_bytes(b"x")
|
||||
tape2 = tmp_path / "tape2.mkv"
|
||||
tape2.write_bytes(b"x")
|
||||
result = file_manager.import_episodes(
|
||||
[tape1, tape2],
|
||||
"Breaking Bad",
|
||||
year=2008,
|
||||
tmdb_id=1396,
|
||||
codes={tape1: (1, 1, 1), tape2: (1, 1, 2)},
|
||||
)
|
||||
|
||||
assert result["imported"] == 2
|
||||
base = (
|
||||
tmp_path
|
||||
/ "pool"
|
||||
/ "Seriály"
|
||||
/ "Breaking Bad (2008) [tmdbid-1396]"
|
||||
/ "Season 01"
|
||||
)
|
||||
assert (base / "S01E01 - Breaking Bad.pt1.mkv").exists()
|
||||
assert (base / "S01E01 - Breaking Bad.pt2.mkv").exists()
|
||||
|
||||
def test_import_episodes_reads_part_from_filename(self, file_manager, tmp_path):
|
||||
tape = tmp_path / "Show.S01E01.pt2.mkv"
|
||||
tape.write_bytes(b"x")
|
||||
|
||||
result = file_manager.import_episodes([tape], "Show", year=2020, tmdb_id=5)
|
||||
|
||||
base = tmp_path / "pool" / "Seriály" / "Show (2020) [tmdbid-5]" / "Season 01"
|
||||
assert (base / "S01E01 - Show.pt2.mkv").exists()
|
||||
assert result["imported"] == 1
|
||||
|
||||
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 = tmp_path / "pool" / "Seriály" / "Breaking Bad (2008) [tmdbid-1396]"
|
||||
folder.mkdir(parents=True)
|
||||
(folder / "bb.1x03.HDTV.mkv").write_bytes(b"x")
|
||||
|
||||
@@ -213,16 +439,33 @@ class TestFileManagerSeries:
|
||||
assert result["renamed"] == [("bb.1x03.HDTV.mkv", "S01E03 - Breaking Bad.mkv")]
|
||||
assert (folder / "Season 01" / "S01E03 - Breaking Bad.mkv").exists()
|
||||
|
||||
def test_rename_episodes_to_canonical_keeps_the_part_tag(
|
||||
self, file_manager, tmp_path
|
||||
):
|
||||
folder = tmp_path / "pool" / "Seriály" / "Breaking Bad (2008) [tmdbid-1396]"
|
||||
folder.mkdir(parents=True)
|
||||
(folder / "bb.1x03.HDTV-part2.mkv").write_bytes(b"x")
|
||||
|
||||
result = file_manager.rename_episodes_to_canonical(
|
||||
file_manager.load_series()[0]
|
||||
)
|
||||
|
||||
assert result["renamed"] == [
|
||||
("bb.1x03.HDTV-part2.mkv", "S01E03 - Breaking Bad.pt2.mkv")
|
||||
]
|
||||
assert (folder / "Season 01" / "S01E03 - Breaking Bad.pt2.mkv").exists()
|
||||
|
||||
def test_rename_episodes_to_canonical_carries_subtitle_along(
|
||||
self, file_manager, tmp_path
|
||||
):
|
||||
folder = (tmp_path / "pool" / "Seriály"
|
||||
/ "Breaking Bad (2008) [tmdbid-1396]")
|
||||
folder = tmp_path / "pool" / "Seriály" / "Breaking Bad (2008) [tmdbid-1396]"
|
||||
folder.mkdir(parents=True)
|
||||
(folder / "bb.1x03.HDTV.mkv").write_bytes(b"x")
|
||||
(folder / "bb.1x03.HDTV.cs.srt").write_bytes(b"x")
|
||||
|
||||
result = file_manager.rename_episodes_to_canonical(file_manager.load_series()[0])
|
||||
result = file_manager.rename_episodes_to_canonical(
|
||||
file_manager.load_series()[0]
|
||||
)
|
||||
|
||||
assert result["renamed"] == [("bb.1x03.HDTV.mkv", "S01E03 - Breaking Bad.mkv")]
|
||||
assert (folder / "Season 01" / "S01E03 - Breaking Bad.cs.srt").exists()
|
||||
@@ -232,39 +475,51 @@ class TestFileManagerSeries:
|
||||
seri = tmp_path / "pool" / "Seriály"
|
||||
# series A: mis-named episodes in a non-padded season folder
|
||||
(seri / "Fargo (2014) [tmdbid-60622]" / "Season 1").mkdir(parents=True)
|
||||
(seri / "Fargo (2014) [tmdbid-60622]" / "Season 1"
|
||||
/ "fargo.1x01.1080p.WEB.mkv").write_bytes(b"x")
|
||||
(
|
||||
seri
|
||||
/ "Fargo (2014) [tmdbid-60622]"
|
||||
/ "Season 1"
|
||||
/ "fargo.1x01.1080p.WEB.mkv"
|
||||
).write_bytes(b"x")
|
||||
# series B: one good, one without a code
|
||||
(seri / "Most! (2019) [tmdbid-90000]" / "Season 01").mkdir(parents=True)
|
||||
(seri / "Most! (2019) [tmdbid-90000]" / "Season 01"
|
||||
/ "S01E02 - Most!.mkv").write_bytes(b"x")
|
||||
(seri / "Most! (2019) [tmdbid-90000]" / "Season 01"
|
||||
/ "necoZvlastniho.mkv").write_bytes(b"x")
|
||||
(
|
||||
seri / "Most! (2019) [tmdbid-90000]" / "Season 01" / "S01E02 - Most!.mkv"
|
||||
).write_bytes(b"x")
|
||||
(
|
||||
seri / "Most! (2019) [tmdbid-90000]" / "Season 01" / "necoZvlastniho.mkv"
|
||||
).write_bytes(b"x")
|
||||
|
||||
result = file_manager.rename_all_series_to_canonical()
|
||||
|
||||
assert result["series"] == 2
|
||||
assert ("Fargo", "fargo.1x01.1080p.WEB.mkv", "S01E01 - Fargo.mkv") in result["renamed"]
|
||||
assert (seri / "Fargo (2014) [tmdbid-60622]" / "Season 01"
|
||||
/ "S01E01 - Fargo.mkv").exists()
|
||||
assert ("Fargo", "fargo.1x01.1080p.WEB.mkv", "S01E01 - Fargo.mkv") in result[
|
||||
"renamed"
|
||||
]
|
||||
assert (
|
||||
seri / "Fargo (2014) [tmdbid-60622]" / "Season 01" / "S01E01 - Fargo.mkv"
|
||||
).exists()
|
||||
# emptied non-padded season folder swept
|
||||
assert not (seri / "Fargo (2014) [tmdbid-60622]" / "Season 1").exists()
|
||||
# the already-canonical one is untouched, the code-less one is reported
|
||||
assert ("Most!", "necoZvlastniho.mkv") in result["skipped_no_code"]
|
||||
assert (seri / "Most! (2019) [tmdbid-90000]" / "Season 01"
|
||||
/ "S01E02 - Most!.mkv").exists()
|
||||
assert (
|
||||
seri / "Most! (2019) [tmdbid-90000]" / "Season 01" / "S01E02 - Most!.mkv"
|
||||
).exists()
|
||||
|
||||
def test_apply_series_edits_renames_folder_and_episodes(self, file_manager, tmp_path):
|
||||
def test_apply_series_edits_renames_folder_and_episodes(
|
||||
self, file_manager, tmp_path
|
||||
):
|
||||
folder = tmp_path / "pool" / "Seriály" / "Wrong Name"
|
||||
(folder / "Season 01").mkdir(parents=True)
|
||||
(folder / "Season 01" / "old S01E01.mkv").write_bytes(b"x")
|
||||
|
||||
ser = file_manager.load_series()[0]
|
||||
result = file_manager.apply_series_edits(
|
||||
ser, title="Breaking Bad", year=2008, tmdb_id=1396)
|
||||
ser, title="Breaking Bad", year=2008, tmdb_id=1396
|
||||
)
|
||||
|
||||
new_folder = (tmp_path / "pool" / "Seriály"
|
||||
/ "Breaking Bad (2008) [tmdbid-1396]")
|
||||
new_folder = tmp_path / "pool" / "Seriály" / "Breaking Bad (2008) [tmdbid-1396]"
|
||||
assert result["folder"] == new_folder
|
||||
assert (new_folder / "Season 01" / "S01E01 - Breaking Bad.mkv").exists()
|
||||
assert not folder.exists()
|
||||
|
||||
Reference in New Issue
Block a user