mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-06 07:55:10 +00:00
test: delete slow, timing-based and redundant tests
This commit is contained in:
@@ -5,11 +5,8 @@ dovi_tool, hdr10plus_tool or FFmpeg."""
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import gc
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import weakref
|
||||
from collections.abc import Iterator
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
@@ -24,7 +21,6 @@ from unshackle.core import mux_step, temp
|
||||
from unshackle.core.api import download_manager, handlers, key_policy
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.mux_step import hybrid_plan, hybrid_source_tracks, hybrid_step_error, missing_hybrid_error
|
||||
from unshackle.core.run_plan import session_request
|
||||
from unshackle.core.service import Service, TrackRequest
|
||||
from unshackle.core.services import Services
|
||||
from unshackle.core.tracks import Audio, Chapter, Subtitle, Tracks, Video
|
||||
@@ -36,13 +32,11 @@ from unshackle.core.tracks.hybrid import (
|
||||
hdr10plus_shots,
|
||||
measured_shots,
|
||||
nits_to_pq,
|
||||
pq_to_nits,
|
||||
)
|
||||
from unshackle.core.tracks.selection import (
|
||||
generated_dv_ranges,
|
||||
hybrid_gate_failure,
|
||||
keep_generated_dv_bases,
|
||||
select_hybrid_bases,
|
||||
)
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
@@ -91,13 +85,6 @@ def test_pq_matches_the_st2084_reference_points() -> None:
|
||||
assert round(nits_to_pq(0)) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("active", [1.0, 0.75])
|
||||
def test_a_flat_histogram_averages_to_its_own_level(active: float) -> None:
|
||||
values = {index: 120.0 for index in INDEXES}
|
||||
mean = hdr10plus_mean_pq(values, active)
|
||||
assert mean is not None and mean == pytest.approx(nits_to_pq(120.0))
|
||||
|
||||
|
||||
def test_the_slots_outside_the_distribution_do_not_move_the_mean() -> None:
|
||||
"""Index 5 is a luminance-Y value and index 10 a pixel share, so neither is a maxRGB percentile."""
|
||||
base = hdr10plus_mean_pq(histogram({5: 50.0, 10: 50.0}))
|
||||
@@ -131,18 +118,6 @@ def test_a_scene_with_no_black_pixels_keeps_its_whole_frame() -> None:
|
||||
assert hdr10plus_mean_pq(full_frame, 0.75) == hdr10plus_mean_pq(full_frame, 1.0)
|
||||
|
||||
|
||||
def test_a_ten_slot_histogram_uses_the_same_lookup() -> None:
|
||||
nine = histogram({99: 300.0})
|
||||
ten = {**nine, 98: 250.0}
|
||||
assert hdr10plus_mean_pq(ten) == hdr10plus_mean_pq(nine)
|
||||
|
||||
|
||||
def test_a_histogram_without_a_distribution_slot_has_no_mean() -> None:
|
||||
values = histogram({})
|
||||
del values[75]
|
||||
assert hdr10plus_mean_pq(values) is None
|
||||
|
||||
|
||||
def test_each_scene_becomes_one_shot_with_its_own_cut() -> None:
|
||||
meta = metadata([(3, histogram({99: 200.0})), (5, histogram({99: 800.0}))], first_frame=1000)
|
||||
|
||||
@@ -277,61 +252,6 @@ def test_active_area_share(top: int, expected: float | None, quiet: None, monkey
|
||||
assert area[1] == pytest.approx(expected)
|
||||
|
||||
|
||||
def test_each_crop_sample_evaluates_enough_frames(quiet: None, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""cropdetect ignores its first two frames (skip=2) and only grows the picture over the rest."""
|
||||
cropdetect_calls: list[list[str]] = []
|
||||
|
||||
def fake_run(args: list[Any], **kwargs: Any) -> SimpleNamespace:
|
||||
if "format=duration" in args:
|
||||
return SimpleNamespace(returncode=0, stdout='{"format": {"duration": "100"}}', stderr="")
|
||||
if "stream=width,height" in args:
|
||||
return SimpleNamespace(returncode=0, stdout='{"streams": [{"width": 3840, "height": 2160}]}', stderr="")
|
||||
cropdetect_calls.append([str(a) for a in args])
|
||||
return SimpleNamespace(returncode=0, stdout="", stderr="crop=3840:1600:0:280")
|
||||
|
||||
monkeypatch.setattr(hybrid_mod.subprocess, "run", fake_run)
|
||||
|
||||
make_hybrid().detect_active_area(Path("base.mkv"))
|
||||
|
||||
assert cropdetect_calls
|
||||
for args in cropdetect_calls:
|
||||
filtergraph = args[args.index("-vf") + 1]
|
||||
skip_match = re.search(r"skip=(\d+)", filtergraph)
|
||||
skip = int(skip_match.group(1)) if skip_match else 2
|
||||
assert int(args[args.index("-vframes") + 1]) - skip >= 8
|
||||
|
||||
|
||||
def test_the_parsed_metadata_is_released_before_dovi_tool_runs(
|
||||
quiet: None, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
"""hdr10plus_tool writes one entry per frame, so a film's parsed JSON is hundreds of MB of objects."""
|
||||
|
||||
class Tracked(dict): # type: ignore[type-arg]
|
||||
pass
|
||||
|
||||
(tmp_path / "HDR10Plus.json").write_text(json.dumps(metadata([(2, histogram({}))])))
|
||||
hybrid = make_hybrid()
|
||||
monkeypatch.setattr(hybrid, "probe_hdr_metadata", lambda: (1000, 1, 0, 0))
|
||||
real_load = json.load
|
||||
refs: list[weakref.ReferenceType[Tracked]] = []
|
||||
|
||||
def tracked_load(fp: Any) -> Tracked:
|
||||
loaded = Tracked(real_load(fp))
|
||||
refs.append(weakref.ref(loaded))
|
||||
return loaded
|
||||
|
||||
def fake_generate(config_json: Path, output: Path, **kwargs: Any) -> bytes:
|
||||
gc.collect()
|
||||
assert refs and refs[0]() is None, "the parsed HDR10+ metadata is still alive"
|
||||
output.write_bytes(b"rpu")
|
||||
return b""
|
||||
|
||||
monkeypatch.setattr(hybrid_mod.json, "load", tracked_load)
|
||||
monkeypatch.setattr(hybrid_mod.dovi, "generate", fake_generate)
|
||||
|
||||
hybrid.convert_hdr10plus_to_dv()
|
||||
|
||||
|
||||
def test_conversion_writes_a_cm29_config_with_shots_and_cleans_up(
|
||||
quiet: None, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
@@ -525,11 +445,6 @@ def test_two_frame_rates_make_no_hybrid(base: str | None, dv: str, refused: bool
|
||||
Hybrid.check_base(*tracks)
|
||||
|
||||
|
||||
def test_a_raw_stream_has_no_frame_rate_to_compare() -> None:
|
||||
base = hybrid_track(Path("b.hevc"), Video.Range.HDR10, avg_frame_rate="25/1")
|
||||
Hybrid.check_base(base, hybrid_track(Path("d.mp4"), Video.Range.DV, avg_frame_rate="24/1"))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"probe",
|
||||
[{"transfer": "arib-std-b67"}, {"side_data_list": [{"dv_profile": 8, "dv_bl_signal_compatibility_id": 4}]}],
|
||||
@@ -540,16 +455,6 @@ def test_an_hlg_dv_track_makes_no_hybrid(probe: dict[str, Any]) -> None:
|
||||
Hybrid.check_base(base, hybrid_track(Path("d.mp4"), Video.Range.DV, **probe))
|
||||
|
||||
|
||||
def test_vivid_is_the_last_choice_of_hybrid_base_and_takes_no_generate_dv_range() -> None:
|
||||
videos = [
|
||||
video("v2160", Video.Range.VIVID),
|
||||
video("h2160", Video.Range.HDR10),
|
||||
video("v1080", Video.Range.VIVID, 1080),
|
||||
]
|
||||
assert [v.id for v in select_hybrid_bases(videos)] == ["h2160", "v1080"]
|
||||
assert generated_dv_ranges([Video.Range.VIVID], True) == ([Video.Range.VIVID], [])
|
||||
|
||||
|
||||
def test_an_hdr10plus_label_without_metadata_is_measured(
|
||||
quiet: None, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
@@ -605,11 +510,6 @@ def test_a_cut_on_the_first_frame_or_inside_a_flash_burst_opens_no_shot() -> Non
|
||||
assert [(s["start"], s["duration"]) for s in shots] == [(0, 12), (12, 12), (24, 1)]
|
||||
|
||||
|
||||
def test_pq_to_nits_is_the_inverse_of_nits_to_pq() -> None:
|
||||
for nits in (0.005, 1.0, 100.0, 1000.0, 10000.0):
|
||||
assert pq_to_nits(nits_to_pq(nits)) == pytest.approx(nits, rel=1e-6)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("stream, expected", [((0, 0), (1000, 400)), ((800, 200), (800, 200))])
|
||||
def test_measured_light_levels_fill_only_what_the_stream_does_not_state(
|
||||
stream: tuple[int, int], expected: tuple[int, int], quiet: None, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
@@ -700,19 +600,6 @@ def test_a_base_range_with_the_flag_runs_as_a_hybrid_of_that_base_alone() -> Non
|
||||
assert hybrid_gate_failure(keep_generated_dv_bases(videos, [R.HDR10]), True) is None
|
||||
|
||||
|
||||
def test_hdr10plus_is_the_base_before_hdr10_at_one_height() -> None:
|
||||
videos = [video("h", Video.Range.HDR10), video("p", Video.Range.HDR10P), video("h1080", Video.Range.HDR10, 1080)]
|
||||
assert [v.id for v in hybrid_plan(videos, True)[0]] == ["p", "h1080"]
|
||||
assert [v.id for v in select_hybrid_bases(videos[::-1])] == ["p", "h1080"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("to_dv", [False, True])
|
||||
def test_an_hdr10_base_without_dv_is_planned_only_with_the_flag(to_dv: bool) -> None:
|
||||
videos = [video("h", Video.Range.HDR10)]
|
||||
assert (hybrid_gate_failure(videos, to_dv) is None) is to_dv
|
||||
assert [v.id for v in hybrid_plan(videos, to_dv)[0]] == (["h"] if to_dv else [])
|
||||
|
||||
|
||||
def test_a_failed_resolution_removes_its_crop_edits_and_keeps_the_dv_files(
|
||||
quiet: None, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
@@ -830,13 +717,6 @@ def test_a_title_without_a_hybrid_file_fails() -> None:
|
||||
assert missing_hybrid_error(bases, 0) == ("Every hybrid failed (2160p, 1080p), so the title has no hybrid file")
|
||||
|
||||
|
||||
def test_only_hevc_tracks_are_hybrid_bases() -> None:
|
||||
av1 = SimpleNamespace(id="av1", height=2160, range=Video.Range.HDR10P, codec=Video.Codec.AV1)
|
||||
hevc = SimpleNamespace(id="hevc", height=1080, range=Video.Range.HDR10P, codec=Video.Codec.HEVC)
|
||||
|
||||
assert [v.id for v in select_hybrid_bases([av1, hevc])] == ["hevc"] # type: ignore[list-item]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"dv_available, to_dv, hdr10_gives, fetched, kept",
|
||||
[
|
||||
@@ -925,12 +805,6 @@ def test_a_rest_job_gives_the_flag_to_the_service_ctx_and_to_dl(
|
||||
assert exc.value.args == (to_dv, to_dv)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("to_dv", [False, True])
|
||||
def test_the_remote_client_forwards_the_flag_only_when_set(to_dv: bool) -> None:
|
||||
data = session_request({"generate_dv": to_dv}, {})
|
||||
assert data.get("generate_dv", False) is to_dv
|
||||
|
||||
|
||||
@pytest.mark.parametrize("to_dv", [False, True])
|
||||
def test_a_remote_session_puts_the_flag_in_the_service_ctx(monkeypatch: pytest.MonkeyPatch, to_dv: bool) -> None:
|
||||
seen: dict[str, Any] = {}
|
||||
@@ -967,12 +841,6 @@ def test_hybrid_fails_with_neither_a_base_nor_dv() -> None:
|
||||
assert hybrid_gate_failure([], True) == "HYBRID needs HDR10/HDR10+/VIVID and DV tracks, available ranges: none"
|
||||
|
||||
|
||||
def test_hybrid_fails_with_dv_only() -> None:
|
||||
assert hybrid_gate_failure([video("dv", Video.Range.DV)], True) == (
|
||||
"HYBRID needs HDR10/HDR10+/VIVID and DV tracks, available ranges: DV"
|
||||
)
|
||||
|
||||
|
||||
def test_hybrid_goes_on_without_dv_when_the_flag_has_an_hdr10plus_base() -> None:
|
||||
assert hybrid_gate_failure([video("p", Video.Range.HDR10P), video("h", Video.Range.HDR10)], True) is None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user