Files
alfred/tests/domain/test_release_fixtures.py
T
francwa b7979c0f8b refactor(release): freeze ParsedRelease + enrich_from_probe returns new instance
ParsedRelease is now @dataclass(frozen=True). The enrichment passes that
used to patch fields in place now produce new instances:

- enrich_from_probe(parsed, info, kb) returns a new ParsedRelease via
  dataclasses.replace (no allocation when no field changed).
- inspect_release rebinds 'parsed' after detect_media_type (wrapped in
  MediaTypeToken — the strict isinstance check now also runs on
  replace) and after enrich_from_probe.

languages becomes a tuple[str, ...] so the VO is properly immutable.
Parser pipeline packs languages as a tuple in the assemble dict.

Callers updated: inspect_release, testing/recognize_folders_in_downloads.py.
Tests updated: 22 enrich_from_probe call sites rebound, language
assertions switched to tuple literals, test_release_fixtures normalizes
result['languages'] back to list for YAML-fixture comparison.

Suite: 1077 passed.
2026-05-21 07:51:49 +02:00

71 lines
2.8 KiB
Python

"""Real-world release fixtures — anti-regression baseline for parse_release.
Each fixture under ``tests/fixtures/releases/<bucket>/<case>/expected.yaml``
declares a release name and the ``ParsedRelease`` fields it should produce.
Fields absent from the fixture's ``parsed`` block are not checked, so adding
new attributes to ``ParsedRelease`` never breaks existing fixtures.
The fixture's ``tree`` is materialized into a temp dir to prove the layout is
self-consistent, even though no filesystem assertions are made yet. The
``routing`` block (library / torrents / seed_hardlinks) is captured ahead of
the ``organize_media`` refactor — it will become verifiable once the planner
exists.
"""
from __future__ import annotations
from dataclasses import asdict
import pytest
from alfred.domain.release.services import parse_release
from alfred.infrastructure.knowledge.release_kb import YamlReleaseKnowledge
from tests.fixtures.releases.conftest import ReleaseFixture, discover_fixtures
_KB = YamlReleaseKnowledge()
FIXTURES = discover_fixtures()
def _fixture_param(f: ReleaseFixture) -> pytest.param:
marks = []
if f.xfail_reason:
marks.append(pytest.mark.xfail(reason=f.xfail_reason, strict=False))
return pytest.param(f, id=f.name, marks=marks)
@pytest.mark.parametrize(
"fixture",
[_fixture_param(f) for f in FIXTURES],
)
def test_parse_matches_fixture(fixture: ReleaseFixture, tmp_path) -> None:
# Materialize the tree to assert it is at least well-formed YAML +
# plausible filesystem paths. Catches typos / missing leading dirs early.
fixture.materialize(tmp_path)
parsed, _report = parse_release(fixture.release_name, _KB)
result = asdict(parsed)
# ``is_season_pack`` and ``tech_string`` are @property values —
# ``asdict()`` does not include them.
result["is_season_pack"] = parsed.is_season_pack
result["tech_string"] = parsed.tech_string
# ``languages`` is a tuple on the VO; fixtures encode it as a YAML list.
# Compare list-to-list so the equality is unambiguous.
result["languages"] = list(result.get("languages", ()))
for field, expected in fixture.expected_parsed.items():
assert field in result, (
f"{fixture.name}: unknown field '{field}' in expected.parsed"
)
assert result[field] == expected, (
f"{fixture.name}: parsed.{field}"
f"expected {expected!r}, got {result[field]!r}"
)
def test_at_least_one_fixture_per_bucket() -> None:
"""Each bucket should hold at least one case once populated."""
buckets = {f.name.split("/")[0] for f in FIXTURES}
assert "easy" in buckets, "EASY bucket must have at least one fixture"
assert "shitty" in buckets, "SHITTY bucket must have at least one fixture"
assert "path_of_pain" in buckets, "PATH_OF_PAIN bucket must have at least one fixture"