Files
Spellcast3d/code/tests/bake/test_mutations.py
Igor AherneandClaude Opus 5.5 56d85f6eeb Spellcast3D 0.1.0
A free, open-source Windows app that takes an artist from an idea to game-ready 3D props on their own PC: pictures with Qwen-Image 2.1, 3D models with Pixal3D, an optional repaint of their textures, retopology with TriFlow, LATO.2 or Instant Meshes, and a baker for the final textures. See README.md, and DEVELOPERS.md for building from source.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-25 02:38:33 +01:00

72 lines
3.3 KiB
Python

"""The gates bite: the oracle with each classic baker bug must FAIL at least one gate,
and the clean oracle must PASS on the same fixtures (design section 7, mutation tests).
Most bugs show on the split plane (a mirrored, rotated second chart); ``face_rays`` and
``transpose`` need curvature the tessellation does not follow, so they run on the
icosahedron over the displaced sphere, where the vertex normals are 63 deg apart.
The CLI's PASS/FAIL exit code is checked on the same bakes.
"""
from __future__ import annotations
from pathlib import Path
import pytest
pytest.importorskip("instant_meshes_brush.uv", reason="the low OBJs are written by instant_meshes_brush.uv")
from bakecheck import bakecheck as bc # noqa: E402
from bakecheck import cli # noqa: E402
from bakecheck import fixtures as fx # noqa: E402
#: mutation -> the fixture that exposes it
WHERE = {"flip_green": "plane_split", "ignore_w": "plane_split", "vflip": "plane_split",
"gamma_twice": "plane_split", "half_texel": "plane_split", "no_padding": "plane_split",
"face_rays": "coarse_sphere", "transpose": "coarse_sphere"}
@pytest.fixture(scope="module")
def root(request: pytest.FixtureRequest) -> Path:
return fx.cache_root(request.config)
def setup(root: Path, where: str, basis: str) -> tuple[fx.Case, fx.Recipe]:
if where == "plane_split":
return fx.plane_case(root, "split"), fx.Recipe(texture_size=512, quality=1, tangent_basis=basis)
# the icosahedron's faces sink 0.2 below the surface: a 10%-of-diagonal ray window
return fx.coarse_sphere_case(root), fx.Recipe(texture_size=512, quality=1, tangent_basis=basis,
ray_distance=10.0)
def test_every_mutation_has_a_fixture() -> None:
assert set(WHERE) == set(bc.MUTATIONS)
@pytest.mark.parametrize("where", sorted(set(WHERE.values())))
@pytest.mark.parametrize("basis", bc.TANGENT_BASES)
def test_clean_oracle_passes(root: Path, tmp_path: Path, where: str, basis: str) -> None:
case, recipe = setup(root, where, basis)
verdict, _ = bc.score(case.scene, fx.OracleBaker().bake(case, recipe, tmp_path))
assert verdict.passed, f"clean oracle on {where}:\n{verdict}"
@pytest.mark.parametrize("basis", bc.TANGENT_BASES)
@pytest.mark.parametrize("mutation", bc.MUTATIONS)
def test_mutation_fails_a_gate(root: Path, tmp_path: Path, mutation: str, basis: str) -> None:
case, recipe = setup(root, WHERE[mutation], basis)
verdict, _ = bc.score(case.scene, fx.OracleBaker(mutations=[mutation]).bake(case, recipe, tmp_path))
assert not verdict.passed, f"{mutation} slipped through every gate:\n{verdict}"
def test_cli_exit_codes(root: Path, tmp_path: Path, capsys: pytest.CaptureFixture[str]) -> None:
case, recipe = setup(root, "plane_split", "mikk")
scene_json = case.high.parent / "scene.json"
clean = fx.OracleBaker().bake(case, recipe, tmp_path / "clean")
report = tmp_path / "report.json"
assert cli.main([str(scene_json), str(clean), "--json", str(report)]) == 0
assert "RESULT: PASS" in capsys.readouterr().out
assert report.is_file()
flipped = fx.OracleBaker(mutations=["flip_green"]).bake(case, recipe, tmp_path / "flipped")
assert cli.main([str(scene_json), str(flipped)]) == 1
assert "RESULT: FAIL" in capsys.readouterr().out