Files
gig-line/Tools/tests/test_shadow_gap.py
T
zwitschi 4d27109668 refactor(tools): group the sixty scripts by what they talk to
One directory with sixty scripts stopped being navigable, and the grouping is also the sandbox boundary:

  Tools/unreal/    commandlets and the two map builders, with ue_common.py and ue_placement.py as the
                   shared imports (they need the engine)
  Tools/blender/   builders, exporters, the FBX preset, the MPFB character pipeline, blender_screenshots
                   (they need the Blender Flatpak)
  Tools/review/    the visual loop: render_screenshots.sh, judge_screenshot.py, hero_compare.py,
                   build_comparison_md.py, e2e_asset_check.py, hero_iterate.sh, visual_loop.py,
                   visual_targets.json
  Tools/gen/       image and texture generation: the ComfyUI driver, deterministic texture writers,
                   reference fetching
  Tools/input/     OS-level input injection
  root             _common.py, check-lfs.sh, addon_compat_probe.py, sibling_asset_audit.py, tests/

Every moved script now resolves the repository root as ../.. and puts the tools root plus its siblings on
sys.path, so 'import ue_common' still works from unreal/. The test suite bootstrap does the same for the five
folders. render_screenshots.sh takes the folder as a third argument to run_cmdlet, and the e2e driver,
hero_iterate.sh and the comparison generator were repointed.

51 README rows now link to their new location, the README gains a Layout section naming each folder's
sandbox, and the architecture notes and Blender README follow the moves.

Verified: 108 tests pass, prettier is clean, judge_screenshot.py and hero_compare.py run from their new
homes, and the e2e run was aborted mid-way (it had been rebuilding an empty DemoMap for 15 minutes) and is
being rerun against the new layout.
2026-11-10 12:40:30 +01:00

66 lines
2.4 KiB
Python

"""Tests for the pure parts of Tools/shadow_gap.py."""
import os
import sys
_TOOLS = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, _TOOLS)
for _sub in ("review", "gen", "unreal", "blender", "input"):
sys.path.insert(0, os.path.join(_TOOLS, _sub))
import os
import sys
import unittest
from PIL import Image
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import shadow_gap as sg # noqa: E402
def synthetic(object_bottom, shadow_top, size=(80, 120), background=(200, 200, 196)):
"""A grey frame with a dark block (object) and a dark strip (shadow) below it."""
image = Image.new("RGB", size, background)
pixels = image.load()
for y in range(20, object_bottom):
for x in range(30, 50):
pixels[x, y] = (18, 18, 20) # object: far darker than the surface
for y in range(shadow_top, min(size[1] - 2, shadow_top + 12)):
for x in range(30, 50):
# shadow: a darkened version of the surface, as a real shadow is
pixels[x, y] = (140, 140, 138)
return image
class MeasureTests(unittest.TestCase):
def test_contact_reads_as_contact(self):
image = synthetic(object_bottom=60, shadow_top=61)
image.save("/tmp/gigline-shadow-contact.png")
result = sg.measure("/tmp/gigline-shadow-contact.png", (0.2, 0.05, 0.8, 0.95))
self.assertEqual(result["verdict"], "contact")
self.assertLessEqual(result["gap_px"], 2)
def test_a_gap_reads_as_floating(self):
image = synthetic(object_bottom=60, shadow_top=100)
image.save("/tmp/gigline-shadow-float.png")
result = sg.measure("/tmp/gigline-shadow-float.png", (0.2, 0.05, 0.8, 0.95))
self.assertEqual(result["verdict"], "floating")
self.assertGreater(result["gap_px"], result["object_height_px"] * 0.12)
def test_empty_box_reports_an_error(self):
image = Image.new("RGB", (40, 40), (200, 200, 200))
image.save("/tmp/gigline-shadow-empty.png")
result = sg.measure("/tmp/gigline-shadow-empty.png", (0.1, 0.1, 0.9, 0.9))
self.assertIn("error", result)
class BorderTests(unittest.TestCase):
def test_border_median_is_the_frame_colour(self):
image = Image.new("RGB", (40, 40), (180, 190, 200))
self.assertEqual(sg.border_median(image), (180, 190, 200))
if __name__ == "__main__":
unittest.main()