Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

test(video): the set's suspects and the two-step loop's alignment say what video-cycle-align run on its own does with a loop whose report holds its cut: named held and stopped, aligned as it is once the caller counts it, and as before where its report witnesses its cut or no report is beside it

Soohong Kim447c852b0689
diff --git a/tests/video/test_cycle_suspects.py b/tests/video/test_cycle_suspects.py
index 6e9ebad..8378df8 100644
--- a/tests/video/test_cycle_suspects.py
+++ b/tests/video/test_cycle_suspects.py
@@ -288,21 +288,31 @@ def _cut(root: Path, name: str, stride: int, length: int, state: str = "walk", *
def _set(tmp_path: Path) -> list[Path]:
- """S and E one stride each; NE two strides of 15 (30 frames), as a two-cycle cut leaves it."""
+ """S and E one stride each; NE two strides of 15 (30 frames), as a two-cycle cut leaves it. NE's cut report, beside
+ it as video-loop writes it, holds its cut: nothing witnesses it whole cycles."""
return [_cut(tmp_path, "S", 24, 24), _cut(tmp_path, "E", 24, 24), _cut(tmp_path, "NE", 15, 30, twos=True)]
@pytest.mark.slow
-def test_a_set_with_a_suspect_is_stopped_before_anything_is_rewritten(tmp_path):
[email protected]("kept", [True, False])
+def test_a_set_with_a_suspect_is_stopped_before_anything_is_rewritten(tmp_path, kept):
+ """NE returns at 15 of its 30 frames: it may hold two cycles. With its cut report beside it, it is also named for
+ what the report holds (`held`: nothing witnessed its cut whole cycles); without one (a loop cut by other means),
+ only for its return."""
dirs = _set(tmp_path)
+ report_beside = dirs[2] / "walk.loop.report.json"
+ if not kept:
+ report_beside.unlink()
before = [(d / "walk.strip.png").read_bytes() for d in dirs]
- with pytest.raises(align.CycleSuspects, match=r"NE: may hold 2 cycles of 15 frames \(0\.625 s\)") as stopped:
+ said = (r"NE: nothing witnessed its cut whole cycles \(cycle-unwitnessed, in [^)]*\): it may hold half a cycle, one or "
+ r"two .*; it may also hold 2 cycles of 15 frames \(0\.625 s\)" if kept else r"NE: may hold 2 cycles of 15 frames \(0\.625 s\)")
+ with pytest.raises(align.CycleSuspects, match=said) as stopped:
align.align_set(dirs, interpolate=_Blend(), report_path=tmp_path / "align.json")
message = str(stopped.value)
command = " ".join(["sprite-gen video-cycle-align", *(f"--loop-dir {d}" for d in dirs), f"--report {tmp_path / 'align.json'}",
f"--cycles {dirs[2]}=<1|2>"])
assert stopped.value.command == command and command in message and "--multi-cycle warn" in message
- assert "video-loop" not in message
+ assert ("video-loop" in message) is kept # a held cut that may be one step is cut again; a return alone is not
assert [(d / "walk.strip.png").read_bytes() for d in dirs] == before
assert all(not (d / "cycle.json").exists() and "cycle_align" not in json.loads((d / "walk.strip.json").read_text()) for d in dirs)
report = json.loads((tmp_path / "align.json").read_text())
@@ -311,6 +321,7 @@ def test_a_set_with_a_suspect_is_stopped_before_anything_is_rewritten(tmp_path):
assert entry["dir"] == str(dirs[2]) and entry["status"] == "stopped" and entry["length"] == 30
assert [(c["period"], c["cycles"]) for c in entry["candidates"]] == [(15, 2)]
assert entry["settle"] == [f"--cycles {dirs[2]}=1", f"--cycles {dirs[2]}=2"]
+ assert entry.get("held") == ({"reason": local_cycle.UNWITNESSED, "report": str(report_beside.resolve())} if kept else None)
assert stopped.value.suspects == report["suspects"]
@@ -336,7 +347,8 @@ def test_multi_cycle_warn_aligns_the_set_as_it_is_and_names_the_loop(tmp_path):
dirs = _set(tmp_path)
report = align.align_set(dirs, interpolate=_Blend(), multi_cycle="warn")
assert [r["from"] for r in report["loops"]] == [24, 24, 30]
- assert any(w.startswith(f"{dirs[2]}: may hold 2 cycles") and "--multi-cycle warn" in w for w in report["warnings"])
+ assert any(w.startswith(f"{dirs[2]}: nothing witnessed its cut whole cycles") and "it may also hold 2 cycles" in w
+ and "--multi-cycle warn" in w for w in report["warnings"])
assert report["suspects"][0]["status"] == "warned"
@@ -400,7 +412,7 @@ def test_the_command_takes_cycles(tmp_path, monkeypatch, capsys):
dirs = _set(tmp_path)
monkeypatch.setattr(align.rife_mod, "Rife", _Blend)
_Blend.describe = lambda self: {"binary": "blend"} # type: ignore[attr-defined]
- with pytest.raises(SystemExit, match="may hold 2 cycles"):
+ with pytest.raises(SystemExit, match="nothing witnessed its cut whole cycles .*; it may also hold 2 cycles"):
align.main([*sum((["--loop-dir", str(d)] for d in dirs), []), "--between", "nearest"])
assert align.main([*sum((["--loop-dir", str(d)] for d in dirs), []), "--between", "nearest", "--cycles", "NE=2"]) == 0
out = json.loads(capsys.readouterr().out)
diff --git a/tests/video/test_loop_prop_seam_held.py b/tests/video/test_loop_prop_seam_held.py
index a07daf5..b88e554 100644
--- a/tests/video/test_loop_prop_seam_held.py
+++ b/tests/video/test_loop_prop_seam_held.py
@@ -363,25 +363,45 @@ def test_shape_rank_reads_no_held_side_when_the_first_choice_does_not_pop():
# --- the set ----------------------------------------------------------------------------------
@pytest.mark.slow
-def test_cycle_align_aligns_a_two_step_loop_as_the_one_cycle_it_is(held, staffless):
- """The loop cut two steps long is one cycle: it returns half way at its second step, which is no
- suspect (status `steps`), and it is resampled to the set's length like the rest — the set's length
- the median of the loops as cut, nothing kept twice as long."""
+def test_cycle_align_aligns_a_two_step_loop_as_the_one_cycle_it_is(held, staffless, tmp_path):
+ """The loop cut two steps long is one cycle: where its report witnesses its cut whole cycles, it returns half way
+ at its second step, which is no suspect (status `steps`), and it is resampled to the set's length like the rest —
+ the set's length the median of the loops as cut, nothing kept twice as long. As cut here nothing witnesses either
+ loop whole cycles (the walker's body does not rise and fall, and its feet never pass): the aligner stops on both,
+ each named `held`, and a count of one each, the caller's word, aligns them as they are."""
root, report = held
other, plain = staffless
lengths = [report["cycle"]["length"], plain["cycle"]["length"]]
- out = align.align_set([root / "out", other / "out"], between="nearest")
- two, one = out["loops"]
target = round(float(np.median(lengths)))
+ # The same two loops, each report witnessing its cut: two steps on the screen.
+ seen = []
+ for src, name in ((root / "out", "two"), (other / "out", "one")):
+ shutil.copytree(src, tmp_path / name)
+ path = tmp_path / name / "loop.loop.report.json"
+ data = json.loads(path.read_text())
+ cycle = data["cycle"]
+ cycle["cut_witness"] = {"cut": [cycle["start"], cycle["length"]], "says": "two steps", "by": ["screen"]}
+ ((cycle.get("step_count") or {}).get("cycles") or {}).pop("unwitnessed", None)
+ path.write_text(json.dumps(data))
+ seen.append(tmp_path / name)
+ out = align.align_set(seen, between="nearest")
+ two, one = out["loops"]
assert out["applied"] is True and out["length"] == target and two["to"] == target and one["to"] == target
assert "cycles_kept" not in two and "cycles_kept" not in one
- mine = [e for e in out["suspects"] if e["dir"] == str((root / "out").resolve())]
+ mine = [e for e in out["suspects"] if e["dir"] == str(seen[0].resolve())]
assert mine and all(e["status"] == "steps" and e["steps"] == 2 and [c["cycles"] for c in e["candidates"]] == [2] for e in mine)
assert isinstance(report["cycle"]["ratio"], float) # a window two lengths long reads its wrap as a candidate does
- assert json.loads((root / "out" / "loop.strip.json").read_text())["steps"] == 2
- assert "steps" not in json.loads((other / "out" / "loop.strip.json").read_text())
+ assert json.loads((seen[0] / "loop.strip.json").read_text())["steps"] == 2
+ assert "steps" not in json.loads((seen[1] / "loop.strip.json").read_text())
+ # As cut: held, by name, until the caller counts them.
+ dirs = [root / "out", other / "out"]
+ with pytest.raises(align.CycleSuspects, match="nothing witnessed its cut whole cycles") as stopped:
+ align.align_set(dirs, between="nearest")
+ assert [e["held"]["reason"] for e in stopped.value.suspects] == [local_cycle.UNWITNESSED] * 2
+ out = align.align_set(dirs, between="nearest", cycles={str(d): 1 for d in dirs})
+ assert out["applied"] is True and out["length"] == target and all(e["status"] == "counted" for e in out["suspects"])
# A count given for it is still the last word: one half taken out of it, no longer two steps.
- out = align.align_set([root / "out", other / "out"], between="nearest", cycles={str(root / "out"): 2})
+ out = align.align_set(dirs, between="nearest", cycles={str(root / "out"): 2, str(other / "out"): 1})
assert "cycle_taken" in out["loops"][0]
assert "steps" not in json.loads((root / "out" / "loop.strip.json").read_text())
@@ -421,7 +441,8 @@ def test_cycle_align_writes_a_loop_without_a_held_part_as_before(tmp_path, staff
for name in ("a", "b"):
shutil.copytree(src / "out", tmp_path / name)
dirs.append(tmp_path / name)
- out = align.align_set(dirs, between="nearest")
+ # Nothing witnesses the cut whole cycles (its report holds it): counted one cycle each, as the caller says.
+ out = align.align_set(dirs, between="nearest", cycles={str(d): 1 for d in dirs})
assert all("cycles_kept" not in row and "steps" not in row for row in out["loops"])
for d in dirs:
meta = json.loads((d / "loop.strip.json").read_text())