161 lines
4.9 KiB
Python
161 lines
4.9 KiB
Python
"""Tests for the pool naming convention helpers (src.core.naming)."""
|
|
|
|
import pytest
|
|
|
|
from src.core.naming import (
|
|
THREE_D_FORMATS,
|
|
canonical_pool_stem,
|
|
is_canonical_pool_stem,
|
|
is_valid_year,
|
|
parse_3d_format,
|
|
parse_pool_stem,
|
|
parse_tmdb_id,
|
|
three_d_format_from_filename,
|
|
year_from_filename,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"year,ok",
|
|
[
|
|
("1968", True),
|
|
(1968, True),
|
|
("968", False),
|
|
("19688", False),
|
|
("abcd", False),
|
|
("", False),
|
|
(" 1999 ", True),
|
|
],
|
|
)
|
|
def test_is_valid_year(year, ok):
|
|
assert is_valid_year(year) is ok
|
|
|
|
|
|
def test_canonical_pool_stem_builds_title_year():
|
|
assert canonical_pool_stem("Matrix", 1999) == "Matrix (1999)"
|
|
assert canonical_pool_stem(" Matrix ", "1999") == "Matrix (1999)"
|
|
|
|
|
|
def test_canonical_pool_stem_rejects_bad_year():
|
|
with pytest.raises(ValueError):
|
|
canonical_pool_stem("Matrix", "99")
|
|
|
|
|
|
def test_canonical_pool_stem_rejects_empty_title():
|
|
with pytest.raises(ValueError):
|
|
canonical_pool_stem(" ", "1999")
|
|
|
|
|
|
def test_parse_pool_stem_roundtrip():
|
|
assert parse_pool_stem("Matrix (1999)") == ("Matrix", 1999)
|
|
# title keeps its own parentheses; only the trailing year is peeled off
|
|
assert parse_pool_stem("Já, robot (2004)") == ("Já, robot", 2004)
|
|
assert parse_pool_stem("Kurz (special) (2019)") == ("Kurz (special)", 2019)
|
|
|
|
|
|
def test_parse_pool_stem_non_canonical():
|
|
assert parse_pool_stem("Matrix") is None
|
|
assert parse_pool_stem("Matrix (99)") is None
|
|
assert parse_pool_stem("Matrix 1999") is None
|
|
|
|
|
|
def test_canonical_pool_stem_with_tmdb_id():
|
|
assert canonical_pool_stem("Matrix", 1999, 603) == "Matrix (1999) [tmdbid-603]"
|
|
# empty/None id → plain stem, no brackets
|
|
assert canonical_pool_stem("Matrix", 1999, None) == "Matrix (1999)"
|
|
assert canonical_pool_stem("Matrix", 1999, "") == "Matrix (1999)"
|
|
|
|
|
|
def test_canonical_pool_stem_rejects_bad_id():
|
|
with pytest.raises(ValueError):
|
|
canonical_pool_stem("Matrix", 1999, "tt0133093")
|
|
|
|
|
|
def test_parse_pool_stem_strips_trailing_tmdb_id():
|
|
# title stays clean; the id is dropped from parse_pool_stem
|
|
assert parse_pool_stem("Matrix (1999) [tmdbid-603]") == ("Matrix", 1999)
|
|
|
|
|
|
def test_parse_tmdb_id():
|
|
assert parse_tmdb_id("Matrix (1999) [tmdbid-603]") == 603
|
|
assert parse_tmdb_id("Matrix (1999)") is None
|
|
assert parse_tmdb_id("Matrix") is None
|
|
|
|
|
|
def test_is_canonical_accepts_tmdb_id_form():
|
|
assert is_canonical_pool_stem("Matrix (1999) [tmdbid-603]")
|
|
|
|
|
|
def test_is_canonical_pool_stem():
|
|
assert is_canonical_pool_stem("Matrix (1999)")
|
|
assert not is_canonical_pool_stem("Matrix")
|
|
|
|
|
|
def test_canonical_pool_stem_with_3d_format():
|
|
assert (
|
|
canonical_pool_stem("Avatar", 2009, 19995, "hsbs")
|
|
== "Avatar (2009) [tmdbid-19995].3D.HSBS"
|
|
)
|
|
# upper-cased regardless of input case
|
|
assert canonical_pool_stem("Avatar", 2009, None, "fsbs") == "Avatar (2009).3D.FSBS"
|
|
# empty/None → no tag at all
|
|
assert canonical_pool_stem("Avatar", 2009, None, None) == "Avatar (2009)"
|
|
assert canonical_pool_stem("Avatar", 2009, None, "") == "Avatar (2009)"
|
|
|
|
|
|
def test_canonical_pool_stem_rejects_bad_3d_format():
|
|
with pytest.raises(ValueError):
|
|
canonical_pool_stem("Avatar", 2009, None, "bogus")
|
|
|
|
|
|
@pytest.mark.parametrize("fmt", THREE_D_FORMATS)
|
|
def test_parse_3d_format_roundtrip(fmt):
|
|
stem = canonical_pool_stem("Avatar", 2009, 19995, fmt)
|
|
assert parse_3d_format(stem) == fmt
|
|
assert parse_pool_stem(stem) == ("Avatar", 2009)
|
|
assert parse_tmdb_id(stem) == 19995
|
|
|
|
|
|
def test_parse_3d_format_case_insensitive_on_read():
|
|
assert parse_3d_format("Avatar (2009).3D.hsbs") == "HSBS"
|
|
|
|
|
|
def test_parse_3d_format_absent_is_none():
|
|
assert parse_3d_format("Avatar (2009) [tmdbid-19995]") is None
|
|
assert parse_3d_format("Avatar (2009)") is None
|
|
|
|
|
|
def test_canonical_pool_stem_3d_without_tmdb_id():
|
|
assert canonical_pool_stem("Avatar", 2009, None, "MVC") == "Avatar (2009).3D.MVC"
|
|
assert parse_3d_format("Avatar (2009).3D.MVC") == "MVC"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"name,year",
|
|
[
|
|
("Matrix.1999.1080p.BluRay.mkv", "1999"),
|
|
("Šíleně smutná princezna (1968).mkv", "1968"),
|
|
("Movie 2001 2010 remux.mkv", "2010"), # last standalone year wins
|
|
("No Year Here.mkv", None),
|
|
("Film 12345.mkv", None), # not a bare 4-digit year
|
|
],
|
|
)
|
|
def test_year_from_filename(name, year):
|
|
assert year_from_filename(name) == year
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"name,fmt",
|
|
[
|
|
("Avatar.2009.3D.HSBS.BluRay.mkv", "HSBS"),
|
|
("Avatar.2009.3d.hsbs.mkv", "HSBS"),
|
|
("Avatar (2009) 3D_FTAB 1080p.mkv", "FTAB"),
|
|
("Avatar (2009) - 3D-MVC.mkv", "MVC"),
|
|
("Avatar (2009).mkv", None),
|
|
("Premium3D.HSBS.mkv", None), # "3D" glued to a word doesn't count
|
|
("Avatar.2009.HSBS.mkv", None), # no "3D" token at all
|
|
],
|
|
)
|
|
def test_three_d_format_from_filename(name, fmt):
|
|
assert three_d_format_from_filename(name) == fmt
|