Migrate from Poetry and pyenv to uv
This commit is contained in:
+44
-20
@@ -1,4 +1,5 @@
|
||||
"""Tests for the lean ČSFD title-bridge scraper (`src.core.csfd`)."""
|
||||
|
||||
import hashlib
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -78,12 +79,16 @@ SEARCH_HTML = """
|
||||
|
||||
class TestCleanFilenameToQuery:
|
||||
def test_strips_release_tags_and_keeps_year(self):
|
||||
assert clean_filename_to_query(
|
||||
"Matrix.1999.1080p.BluRay.x264-GROUP.mkv") == "Matrix 1999"
|
||||
assert (
|
||||
clean_filename_to_query("Matrix.1999.1080p.BluRay.x264-GROUP.mkv")
|
||||
== "Matrix 1999"
|
||||
)
|
||||
|
||||
def test_handles_spaces_and_parens_year(self):
|
||||
assert clean_filename_to_query(
|
||||
"Forrest Gump (1994) 2160p HDR.mkv") == "Forrest Gump 1994"
|
||||
assert (
|
||||
clean_filename_to_query("Forrest Gump (1994) 2160p HDR.mkv")
|
||||
== "Forrest Gump 1994"
|
||||
)
|
||||
|
||||
def test_no_year_no_markers(self):
|
||||
assert clean_filename_to_query("Amelie.mkv") == "Amelie"
|
||||
@@ -97,8 +102,9 @@ class TestCleanFilenameToQuery:
|
||||
|
||||
class TestExtractCsfdId:
|
||||
def test_extract_from_various_urls(self):
|
||||
assert _extract_csfd_id(
|
||||
"https://www.csfd.cz/film/2294-vykoupeni/prehled/") == 2294
|
||||
assert (
|
||||
_extract_csfd_id("https://www.csfd.cz/film/2294-vykoupeni/prehled/") == 2294
|
||||
)
|
||||
assert _extract_csfd_id("/film/999/") == 999
|
||||
|
||||
def test_none_when_absent(self):
|
||||
@@ -119,13 +125,17 @@ class TestAnubisPoW:
|
||||
class TestParseOrigin:
|
||||
def test_country_and_year_from_bullet_format(self):
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
soup = BeautifulSoup(FILM_HTML, "html.parser")
|
||||
assert _parse_origin(soup) == ("USA", "1994")
|
||||
|
||||
def test_first_country_of_coproduction(self):
|
||||
from bs4 import BeautifulSoup
|
||||
html = ('<div class="origin">Francie / Německo <span class="bullet"></span>'
|
||||
'<span>2001</span> 120 min</div>')
|
||||
|
||||
html = (
|
||||
'<div class="origin">Francie / Německo <span class="bullet"></span>'
|
||||
"<span>2001</span> 120 min</div>"
|
||||
)
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
assert _parse_origin(soup) == ("Francie", "2001")
|
||||
|
||||
@@ -133,6 +143,7 @@ class TestParseOrigin:
|
||||
class TestParseOriginalTitle:
|
||||
def test_picks_name_matching_origin_country(self):
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
soup = BeautifulSoup(FILM_HTML, "html.parser")
|
||||
assert _parse_original_title(soup, "USA") == "The Shawshank Redemption"
|
||||
|
||||
@@ -140,22 +151,29 @@ class TestParseOriginalTitle:
|
||||
# A Czech film lists only foreign/festival alt-titles here — none match
|
||||
# the origin country, so we must NOT return one of them.
|
||||
from bs4 import BeautifulSoup
|
||||
html = ('<ul class="film-names">'
|
||||
'<li><img class="flag" title="angličtina"/> Loners</li>'
|
||||
'<li><img class="flag" title="Slovinsko"/> Samotarji</li></ul>')
|
||||
|
||||
html = (
|
||||
'<ul class="film-names">'
|
||||
'<li><img class="flag" title="angličtina"/> Loners</li>'
|
||||
'<li><img class="flag" title="Slovinsko"/> Samotarji</li></ul>'
|
||||
)
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
assert _parse_original_title(soup, "Česko") is None
|
||||
|
||||
def test_cesko_matches_ceskoslovensko_flag(self):
|
||||
from bs4 import BeautifulSoup
|
||||
html = ('<ul class="film-names">'
|
||||
'<li><img class="flag" title="Československo"/> Ostře sledované vlaky</li>'
|
||||
'</ul>')
|
||||
|
||||
html = (
|
||||
'<ul class="film-names">'
|
||||
'<li><img class="flag" title="Československo"/> Ostře sledované vlaky</li>'
|
||||
"</ul>"
|
||||
)
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
assert _parse_original_title(soup, "Česko") == "Ostře sledované vlaky"
|
||||
|
||||
def test_none_when_no_names(self):
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
soup = BeautifulSoup("<div>x</div>", "html.parser")
|
||||
assert _parse_original_title(soup, "USA") is None
|
||||
|
||||
@@ -189,10 +207,13 @@ class TestFetchFilm:
|
||||
def test_wraps_network_error_in_csfd_error(self):
|
||||
import requests
|
||||
|
||||
with patch("src.core.csfd._get_page",
|
||||
side_effect=requests.RequestException("boom")):
|
||||
with pytest.raises(CsfdError):
|
||||
fetch_film("https://www.csfd.cz/film/1/")
|
||||
with (
|
||||
patch(
|
||||
"src.core.csfd._get_page", side_effect=requests.RequestException("boom")
|
||||
),
|
||||
pytest.raises(CsfdError),
|
||||
):
|
||||
fetch_film("https://www.csfd.cz/film/1/")
|
||||
|
||||
|
||||
class TestIsFilmHref:
|
||||
@@ -218,7 +239,8 @@ class TestSearchFilms:
|
||||
# the Seriály-section episode link is excluded
|
||||
assert [f.csfd_id for f in films] == [2294, 248803]
|
||||
assert films[0].url == (
|
||||
"https://www.csfd.cz/film/2294-vykoupeni-z-veznice-shawshank/prehled/")
|
||||
"https://www.csfd.cz/film/2294-vykoupeni-z-veznice-shawshank/prehled/"
|
||||
)
|
||||
|
||||
def test_empty_query_returns_empty(self):
|
||||
assert search_films(" ") == []
|
||||
@@ -231,7 +253,9 @@ class TestFindCsfdUrl:
|
||||
assert find_csfd_url("shawshank 1994") == "https://www.csfd.cz/film/2294-x/"
|
||||
|
||||
def test_retries_without_trailing_year_when_first_query_misses(self):
|
||||
hit = CsfdFilm(url="https://www.csfd.cz/film/221006-vratne-lahve/", csfd_id=221006)
|
||||
hit = CsfdFilm(
|
||||
url="https://www.csfd.cz/film/221006-vratne-lahve/", csfd_id=221006
|
||||
)
|
||||
calls: list[str] = []
|
||||
|
||||
def fake_search(query, limit=1, session=None):
|
||||
|
||||
Reference in New Issue
Block a user