Files
gig-line/Tools/tests/test_shadow_gap.py
T
zwitschi dbb42322ff fix(tools): make the e2e chain actually run after the move, and record what it found
The e2e asset check now completes: PASS on all six steps - empty maps 9 s, demo build 10 s, review build 9 s,
captures 80 s, judge 388 s, review file. Four breakages from the folder move had to be fixed first:

- ue_placement and ue_common are siblings of the scripts that import them, but the rewrite put only the tools
  root on sys.path, so every Unreal commandlet died with ModuleNotFoundError. Both paths are inserted now.
- render_screenshots.sh resolved the repository root one level up, so commandlet paths became Tools/Tools/...
  and the capture step failed in 0 s.
- the driver treated a result file left by an earlier run as success, which is how a ten-second 'demo build'
  passed without building. Result files are unlinked before each step and child output streams to a per-step
  log file rather than a pipe.
- two editors on one project hang instead of failing, so the driver refuses to start while one is running.

Also corrects ue_recreate_maps.py: LevelEditorSubsystem.new_level() refuses a path whose package is still in
memory and delete_asset() leaves the file on disk, measured create->delete->create returning False. The step
now loads each map, destroys every actor, saves, and reports the count it left (0), which is the property the
builders actually need.

Open question recorded in TODO.md: the rebuilt map holds 409 actors and 613 KB against 600 and 886 KB before,
and the ~190 missing ones look like the facade-kit and theatre-trim placements that run as separate steps.
2026-11-10 13:37:21 +01:00

68 lines
2.5 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
_HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.dirname(_HERE)) # tools root, for _common
sys.path.insert(0, _HERE) # siblings in this folder (ue_common, ue_placement)
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()