"""Tests for the pool naming convention helpers (src.core.naming).""" import pytest from src.core.naming import ( canonical_pool_stem, is_canonical_pool_stem, is_valid_year, parse_pool_stem, 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_is_canonical_pool_stem(): assert is_canonical_pool_stem("Matrix (1999)") assert not is_canonical_pool_stem("Matrix") @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