Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
test(video): twelve tests that run the binary on a synthetic cut carry the 900 s limit and pin their runs of RIFE
Soohong Kim661e13d87dc0
diff --git a/tests/conftest.py b/tests/conftest.pyindex c366162..a2885ca 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -4,7 +4,7 @@ import reimport shutilimport subprocessimport sys-from collections.abc import Generator+from collections.abc import Callable, Generatorfrom contextlib import contextmanagerfrom pathlib import Path@@ -216,6 +216,36 @@ def feet_unseen() -> Generator[None, None, None]:yield+def rife_located() -> bool:+ """Whether `rife.locate()` finds rife-ncnn-vulkan here, as the tests marked real_rife ask before they run: where it+ does, a cut's default fill (`--fill-held auto`) makes its frames between with it."""+ from sprite_gen.video import rife++ try:+ rife.locate()+ except rife.RifeUnavailable:+ return False+ return True+++def rife_runs(monkeypatch: pytest.MonkeyPatch) -> Callable[[], int]:+ """The runs of RIFE asked for while the test runs, over every `rife.Rife` located in it (`Rife.calls`: the binary's+ calls), read when called. A test that reaches the binary through a cut's default fill pins its count: each run is+ seconds on a CPU's Vulkan driver, so a change that asks for more fails as a count, not as a test out of time."""+ from sprite_gen.video import rife++ located: list[rife.Rife] = []+ init = rife.Rife.__init__++ def counted(self: rife.Rife, *args: object, **kwargs: object) -> None:+ init(self, *args, **kwargs)+ located.append(self)++ monkeypatch.setattr(rife.Rife, "__init__", counted)+ return lambda: sum(r.calls for r in located)++@pytest.fixture(autouse=True)def own_settings(tmp_path_factory: pytest.TempPathFactory, monkeypatch: pytest.MonkeyPatch) -> None:"""No test reads the saved preferences or the provider choices of the machine it runs on: what a call thatdiff --git a/tests/video/test_explicit_window.py b/tests/video/test_explicit_window.pyindex b7498d4..1a83f9d 100644--- a/tests/video/test_explicit_window.py+++ b/tests/video/test_explicit_window.py@@ -14,6 +14,7 @@ from pathlib import Pathimport pytest+from conftest import rife_locatedfrom sprite_gen.video import loopfrom tests.video import test_gait_fallback as fallback_clipsfrom tests.video import test_loop_prop_seam_held as held_clips@@ -49,27 +50,28 @@ def _hop(root: Path) -> Path:MOTION = ("--anchor", "motion-auto", "--repair", "off")-# path, clip, arguments, what the report shows the path ran, and whether the cut is made at all+# path, clip, arguments, what the report shows the path ran, whether the cut is made at all, and the runs of RIFE its+# held fill asks for where the binary is found (two a frame between)ROWS = [# A window that holds one step of a walk whose steps are seen: no cut of two steps there, and none of one.("first", _slow, ("--state", "walk", *MOTION, "--max-len", "25"),- lambda r: "gait_fallback" not in r and r["error"].startswith("no cut of two steps in --max-len 25"), False),- ("first", _slow, ("--state", "walk", *MOTION, "--min-len", "18"), lambda r: "gait_fallback" not in r, True),+ lambda r: "gait_fallback" not in r and r["error"].startswith("no cut of two steps in --max-len 25"), False, 0),+ ("first", _slow, ("--state", "walk", *MOTION, "--min-len", "18"), lambda r: "gait_fallback" not in r, True, 6),("two-step", _held, ("--state", "walk", *MOTION, "--max-len", "25"),- lambda r: r["cycle"]["seam_pop"]["held_edge"]["two_step_capped"]["max_len"] == 25, True),+ lambda r: r["cycle"]["seam_pop"]["held_edge"]["two_step_capped"]["max_len"] == 25, True, 0),("two-step", _held, ("--state", "walk", *MOTION, "--max-len", "47"), # 47 of 47-49 readlambda r: r["cycle"]["seam_pop"]["held_edge"]["two_step"]["lengths"] == [47, 47]- and r["cycle"]["seam_pop"]["held_edge"]["two_step_capped"] == {"max_len": 47, "lengths_over": [48, 49]}, True),- ("two-step", _held, ("--state", "walk", *MOTION, "--min-len", "20"), lambda r: r["cycle"]["seam_pop"]["applied"], True),+ and r["cycle"]["seam_pop"]["held_edge"]["two_step_capped"] == {"max_len": 47, "lengths_over": [48, 49]}, True, 0),+ ("two-step", _held, ("--state", "walk", *MOTION, "--min-len", "20"), lambda r: r["cycle"]["seam_pop"]["applied"], True, 0),("counted", _short, ("--state", "walk", *MOTION, "--max-len", "42", "--steps", "1"),- lambda r: r["cycle"]["steps"]["window"] == [41, 42] and r["cycle"]["steps"]["counted_window"] == [41, 43], True),- ("counted", _slow, ("--state", "walk", *MOTION, "--min-len", "18", "--steps", "1"), lambda r: r["cycle"]["steps"]["by"] == "given", True),- ("fallback", _slow_front, ("--state", "walk", *MOTION, "--max-len", "36"), lambda r: r["gait_fallback"]["window"] == [12, 36], False),- ("fallback", _slow_front, ("--state", "walk", *MOTION, "--min-len", "30"), lambda r: r["gait_fallback"]["window"][0] == 30, True),- ("one-shot", _hop, ("--state", "jump", "--max-len", "30"), lambda r: r["periodic_attempt"] is not None and r["cycle"]["kind"] == "one-shot", True),- ("one-shot", _hop, ("--state", "jump", "--min-len", "30"), lambda r: r["periodic_attempt"] is not None and r["cycle"]["kind"] == "one-shot", True),+ lambda r: r["cycle"]["steps"]["window"] == [41, 42] and r["cycle"]["steps"]["counted_window"] == [41, 43], True, 6),+ ("counted", _slow, ("--state", "walk", *MOTION, "--min-len", "18", "--steps", "1"), lambda r: r["cycle"]["steps"]["by"] == "given", True, 6),+ ("fallback", _slow_front, ("--state", "walk", *MOTION, "--max-len", "36"), lambda r: r["gait_fallback"]["window"] == [12, 36], False, 0),+ ("fallback", _slow_front, ("--state", "walk", *MOTION, "--min-len", "30"), lambda r: r["gait_fallback"]["window"][0] == 30, True, 22),+ ("one-shot", _hop, ("--state", "jump", "--max-len", "30"), lambda r: r["periodic_attempt"] is not None and r["cycle"]["kind"] == "one-shot", True, 0),+ ("one-shot", _hop, ("--state", "jump", "--min-len", "30"), lambda r: r["periodic_attempt"] is not None and r["cycle"]["kind"] == "one-shot", True, 0),("fixed", _hop, ("--state", "jump", "--cycle", "fixed", "--start", "50", "--length", "40", "--max-len", "30"),- lambda r: r["cycle"]["window_refused"] == {"min_len": None, "max_len": 30}, False),+ lambda r: r["cycle"]["window_refused"] == {"min_len": None, "max_len": 30}, False, 0),]@@ -78,8 +80,9 @@ def _bound(args: tuple[str, ...], flag: str) -> int | None:@pytest.mark.slow[email protected]("path, clip, args, ran, cut", ROWS, ids=[f"{r[0]}{''.join(r[2][-2:])}" for r in ROWS])-def test_an_explicit_window_holds_on_every_path(tmp_path, path, clip, args, ran, cut):[email protected](900) # up to 22 calls of the binary at about 280 x 200 (a row's runs): seconds on a GPU, minutes on a CPU's Vulkan driver[email protected]("path, clip, args, ran, cut, runs", ROWS, ids=[f"{r[0]}{''.join(r[2][-2:])}" for r in ROWS])+def test_an_explicit_window_holds_on_every_path(tmp_path, path, clip, args, ran, cut, runs, rife_runs):keyed = clip(tmp_path / "clip")report_path = tmp_path / "loop.json"try:@@ -88,6 +91,7 @@ def test_an_explicit_window_holds_on_every_path(tmp_path, path, clip, args, ran,code = exc.codereport = json.loads(report_path.read_text())assert ran(report), report.get("cycle")+ assert rife_runs() == (runs if rife_located() else 0)lo, hi = _bound(args, "--min-len"), _bound(args, "--max-len")if not cut:assert code != 0 and report["status"] == "failed", report.get("cycle")diff --git a/tests/video/test_gait_fallback.py b/tests/video/test_gait_fallback.pyindex 487fbb3..8c2e4c9 100644--- a/tests/video/test_gait_fallback.py+++ b/tests/video/test_gait_fallback.py@@ -6,6 +6,7 @@ import mathimport numpy as npimport pytestfrom PIL import Image, ImageDraw+from conftest import rife_locatedfrom sprite_gen.video import gait_fallback, loopfrom tests.video import test_ghost_given_way as ghost_clipsfrom tests.video import test_stop as stop_clips@@ -160,10 +161,12 @@ def test_a_clip_the_first_search_cuts_is_cut_without_the_fallback(tmp_path):@pytest.mark.slow-def test_a_cycle_longer_than_half_the_clip_is_found_by_the_fallback(tmp_path):[email protected](900) # 22 calls of the binary at 280 x 180 (the held fill's frames between): seconds on a GPU, minutes on a CPU's Vulkan driver+def test_a_cycle_longer_than_half_the_clip_is_found_by_the_fallback(tmp_path, rife_runs):frames = [walker(k, period=40) for k in range(73)]code, report, output = run(tmp_path, frames)assert code == 0+ assert rife_runs() == (22 if rife_located() else 0)assert abs(report['cycle']['length']-40) <= 1fallback = report['gait_fallback']assert 'no periodic cycle found' in fallback['reason']@@ -368,8 +371,9 @@ def wrap_and_inner(output):@pytest.mark.slow[email protected](900) # 14 calls of the binary at 280 x 180 for the 2 % walk (the held fill's frames between): seconds on a GPU, minutes on a CPU's Vulkan driver@pytest.mark.parametrize('clip', ['walking away', 'shrinking 2 %'])-def test_a_walk_cut_again_by_hand_is_held_at_its_size_and_its_feet(tmp_path, clip):+def test_a_walk_cut_again_by_hand_is_held_at_its_size_and_its_feet(tmp_path, clip, rife_runs):"""A cut the caller names (`--cycle fixed`, the recut path) of a walk that changes size: held over the whole clipbefore the cut is read, as a search's cut is, so the loop's last frame is the size of its first and stands on itsrow — at the wrap the body's height, crown and feet change no more than from one frame to the next inside, and@@ -377,6 +381,7 @@ def test_a_walk_cut_again_by_hand_is_held_at_its_size_and_its_feet(tmp_path, cli(1 inside) and was refused at 6.83, the 2 % walk 1 px (1) at 3.80."""frames = [walking_away(k) for k in range(73)] if clip == 'walking away' else [walker(k, grow=-0.02) for k in range(73)]code, report, output = run(tmp_path, frames, cut=FIXED)+ assert rife_runs() == (14 if clip == 'shrinking 2 %' and rife_located() else 0)edges = wrap_and_inner(output)# The feet first, whatever the gate said: held at its size alone, the walk away's last frame stands 6 px above its# first (1 px a frame inside) and the seam reads 10.03 — its size moved into its place.diff --git a/tests/video/test_ghost_given_way.py b/tests/video/test_ghost_given_way.pyindex 93df013..50e4df6 100644--- a/tests/video/test_ghost_given_way.py+++ b/tests/video/test_ghost_given_way.py@@ -392,11 +392,13 @@ def test_the_applications_walk_gives_a_small_filmed_ghost_way(tmp_path):@pytest.mark.slow@pytest.mark.real_rife-def test_real_rife_the_applications_walk_gives_a_small_filmed_ghost_way(tmp_path):[email protected](900) # 8 calls of the binary at 280 x 221 (the held fill's frames between and the jump repair's): seconds on a GPU, minutes on a CPU's Vulkan driver+def test_real_rife_the_applications_walk_gives_a_small_filmed_ghost_way(tmp_path, rife_runs):"""B1b through the real RIFE, located as `video-loop` locates it."""report = _app_cut(tmp_path, None)assert report["jump_repair"]["interpolator"]["kind"] == "rife-ncnn-vulkan"_app_ghost_given_way(report, tmp_path / "E")+ assert rife_runs() == 8# --- the source projection and the restoration ------------------------------------------------------diff --git a/tests/video/test_ghost_screen.py b/tests/video/test_ghost_screen.pyindex b83ab16..eefe728 100644--- a/tests/video/test_ghost_screen.py+++ b/tests/video/test_ghost_screen.py@@ -185,11 +185,14 @@ def test_jump_repair_rejects_a_proposal_that_carries_a_ghost(monkeypatch):@pytest.mark.slow@pytest.mark.real_rife[email protected](900) # 20 calls of the binary at 128 x 192: seconds on a GPU, a minute or two on a CPU's Vulkan driverdef test_real_rife_delivers_no_cell_carrying_a_filmed_ghost():"""A filmed ghost resampled 4 to 8 through the real RIFE: before the screen the ghost itself wastaken at its own time, unmeasured, and the frames made beside it carried it, judged only beyond it."""frames = [_walker(18, -18), _band(_walker(15, -15)), _walker(12, -12), _walker(9, -9)]- out, facts = align.resample(frames, 8, rife.Rife())+ interpolate = rife.Rife()+ out, facts = align.resample(frames, 8, interpolate)assert all(f is not frames[1] for f in out)assert max(rife.ghost(f) for f in out) <= GHOST_WARNassert [g["frame"] for g in facts["ghost_screen"]["ghosts"]] == [1]+ assert interpolate.calls == 20diff --git a/tests/video/test_once.py b/tests/video/test_once.pyindex 35e92fd..381c5a5 100644--- a/tests/video/test_once.py+++ b/tests/video/test_once.py@@ -6,6 +6,7 @@ from pathlib import Pathimport pytestfrom PIL import Image, ImageDraw+from conftest import rife_locatedfrom sprite_gen.video import loop, batch, canvas, clip_prompt@@ -30,9 +31,11 @@ def cut(tmp_path, **kwargs):name="death", report_path=None, cycle_mode="once", **kwargs)-def test_cut_keeps_final_pose_in_strip_and_once_previews(tmp_path):[email protected](900) # 20 calls of the binary at 128 x 96 (the held fill's frames between): seconds on a GPU, minutes on a CPU's Vulkan driver+def test_cut_keeps_final_pose_in_strip_and_once_previews(tmp_path, rife_runs):keyed(tmp_path / "keyed")report = cut(tmp_path)+ assert rife_runs() == (20 if rife_located() else 0)meta = report["strip"]assert report["cycle"]["kind"] == "once"assert meta["loop"] is False and meta["hold_last"] is Truediff --git a/tests/video/test_one_step_cut.py b/tests/video/test_one_step_cut.pyindex 0a5ab56..45e4d31 100644--- a/tests/video/test_one_step_cut.py+++ b/tests/video/test_one_step_cut.py@@ -25,7 +25,7 @@ from pathlib import Pathimport pytestfrom PIL import Image, ImageDraw-from conftest import feet_unseen+from conftest import feet_unseen, rife_locatedfrom sprite_gen.video import align, batch, loop, periodfrom tests.video.test_video_pipeline import HAS_IMG2WEBP@@ -134,8 +134,9 @@ def _same_but_the_screen(a: Path, b: Path) -> None:@pytest.mark.slow[email protected](900) # 8 calls of the binary at 270 x 220 (the held fill's frames between, both cuts): seconds on a GPU, minutes on a CPU's Vulkan driver@pytest.mark.parametrize("cycle, suspect", [(CYCLE, True)])-def test_the_step_screen_changes_nothing_but_its_own_record(tmp_path, monkeypatch, cycle, suspect):+def test_the_step_screen_changes_nothing_but_its_own_record(tmp_path, monkeypatch, cycle, suspect, rife_runs):"""A one-step cut: with the screen or without it, every image, the strip metadata and the reportare the same but for its record, and the gait observation's copy of it. The screen is computedafter the cut is chosen and only stored (`local_cycle.py`), so one cut answers for any cycle."""@@ -145,6 +146,7 @@ def test_the_step_screen_changes_nothing_but_its_own_record(tmp_path, monkeypatcmonkeypatch.setattr(period, "step_screen", lambda *a, **k: {"stubbed": True})_cut(tmp_path / "unscreened", keyed)_same_but_the_screen(tmp_path / "screened", tmp_path / "unscreened")+ assert rife_runs() == (8 if rife_located() else 0)@pytest.mark.slow@@ -156,9 +158,11 @@ def test_the_step_screen_reads_a_cycle_on_a_frame_count_that_is_not_whole(tmp_pa@pytest.mark.slow-def test_steps_1_cuts_the_walk_again_two_steps_long_where_its_arms_close(slow, tmp_path):[email protected](900) # 6 calls of the binary at 280 x 220 (the held fill's frames between): seconds on a GPU, minutes on a CPU's Vulkan driver+def test_steps_1_cuts_the_walk_again_two_steps_long_where_its_arms_close(slow, tmp_path, rife_runs):root, keyed, first = slowreport = _cut(tmp_path / "out", keyed, "--steps", "1")+ assert rife_runs() == (6 if rife_located() else 0)cycle = report["cycle"]assert cycle["length"] in (CYCLE - 1, CYCLE, CYCLE + 1)L = first["cycle"]["length"]diff --git a/tests/video/test_play.py b/tests/video/test_play.pyindex e71915a..bfba7bf 100644--- a/tests/video/test_play.py+++ b/tests/video/test_play.py@@ -14,6 +14,7 @@ from pathlib import Pathimport pytestfrom PIL import Image, ImageDraw+from conftest import rife_locatedfrom sprite_gen.video import batch, clip_prompt, effect, loop, nonloop, playfrom test_clip_prompt import PUNCH, punch_frames@@ -257,8 +258,10 @@ def test_a_once_return_that_does_not_come_back_is_refused(tmp_path) -> None:assert json.loads((tmp_path / "out" / "punch.loop.report.json").read_text())["status"] == "failed"-def test_a_once_return_cut_keeps_both_ends_and_plays_once(tmp_path) -> None:[email protected](900) # 36 calls of the binary at 96 x 96 (the held fill's frames between): seconds on a GPU, minutes on a CPU's Vulkan driver+def test_a_once_return_cut_keeps_both_ends_and_plays_once(tmp_path, rife_runs) -> None:report = cut(tmp_path, punch_frames(tmp_path / "frames", (96, 96), count=90))+ assert rife_runs() == (36 if rife_located() else 0)meta = report["strip"]assert report["cycle"]["kind"] == "once-return" and report["cycle"]["length"] == 90assert meta["loop"] is False and meta["hold_last"] is False and meta["returns"] is Truediff --git a/tests/video/test_wrap_blend.py b/tests/video/test_wrap_blend.pyindex eb485a2..eb6345e 100644--- a/tests/video/test_wrap_blend.py+++ b/tests/video/test_wrap_blend.py@@ -19,6 +19,7 @@ import numpy as npimport pytestfrom PIL import Image+from conftest import rife_locatedfrom sprite_gen.video import loop as loop_modfrom sprite_gen.video import wrap_blendfrom tests.video.test_idle_still import _still_frames@@ -419,7 +420,8 @@ def test_a_part_moved_on_a_redrawn_character_is_held_while_the_rest_is_blended(d@pytest.mark.slow-def test_the_checkpoints_part_on_a_flat_figure_is_cut_as_filmed_with_a_warning(tmp_path: Path, capsys) -> None:[email protected](900) # 16 calls of the binary at 160 x 224 (the held fill's frames between, both cuts): seconds on a GPU, minutes on a CPU's Vulkan driver+def test_the_checkpoints_part_on_a_flat_figure_is_cut_as_filmed_with_a_warning(tmp_path: Path, capsys, rife_runs) -> None:frames = []for t in range(N):f = _flat_base(t)@@ -434,6 +436,7 @@ def test_the_checkpoints_part_on_a_flat_figure_is_cut_as_filmed_with_a_warning(tassert "the wrap blend was not used" in capsys.readouterr().errcut(tmp_path, keyed(tmp_path, frames, "keyed-off"), "off", wrap_blend="off", repair="off")assert outputs(tmp_path / "auto") == outputs(tmp_path / "off")+ assert rife_runs() == (16 if rife_located() else 0)# --- 4. a 1 px line on a flat figure ---------------------------------------------------------------------------------------