Files
gig-line/Tools/tests/test_ue_common.py
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

80 lines
2.5 KiB
Python

"""Tests for Tools/ue_common.py — the shared Unreal commandlet helpers.
Pure stdlib: these helpers exist to turn two silent failures into loud ones, so
they are tested without starting Unreal.
"""
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 stat
import sys
import tempfile
import unittest
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
sys.path.insert(0, os.path.join(ROOT, "Tools"))
import ue_common # noqa: E402
class MakeWritableTest(unittest.TestCase):
def test_read_only_file_is_made_writable(self):
# Exactly how an LFS-tracked .umap checks out: 0o444.
with tempfile.NamedTemporaryFile(delete=False) as handle:
path = handle.name
try:
os.chmod(path, 0o444)
self.assertFalse(os.access(path, os.W_OK))
note = ue_common.make_writable(path)
self.assertIsNotNone(note)
self.assertIn("chmod u+w", note)
self.assertTrue(os.access(path, os.W_OK))
finally:
os.chmod(path, 0o644)
os.unlink(path)
def test_writable_file_reports_nothing(self):
with tempfile.NamedTemporaryFile(delete=False) as handle:
path = handle.name
try:
os.chmod(path, 0o644)
self.assertIsNone(ue_common.make_writable(path))
finally:
os.unlink(path)
def test_missing_file_raises(self):
# A typo must not look like a permissions problem.
with tempfile.TemporaryDirectory() as tmp:
with self.assertRaises(FileNotFoundError):
ue_common.make_writable(os.path.join(tmp, "absent.umap"))
def test_read_bits_are_preserved(self):
with tempfile.NamedTemporaryFile(delete=False) as handle:
path = handle.name
try:
os.chmod(path, 0o400)
ue_common.make_writable(path)
mode = os.stat(path).st_mode
self.assertTrue(mode & stat.S_IRUSR)
finally:
os.chmod(path, 0o644)
os.unlink(path)
class RequireSavedTest(unittest.TestCase):
def test_passes_the_save_result_through(self):
self.assertTrue(ue_common.require_saved(True, "/Game/X"))
self.assertFalse(ue_common.require_saved(False, "/Game/X"))
if __name__ == "__main__":
unittest.main()