The suite was reporting 331/331 while at least 82 of those tests asserted
nothing at all.
They raised during setup on APIs removed long ago -- add_layer(name=...),
GridPoint.color, mcrfpy.Animation(), entity.gridstate, mcrfpy.setScene,
assets/kenney_ice.png, GridData.compute_astar -- registered no timers, hit the
engine's auto-exit-when-no-timers path, exited 0, and were scored PASS. Their
assertions had not executed in months. test_metrics.py is the sharpest example:
the existing metrics test died on line 140 with a TypeError, which is precisely
why #341 (get_metrics counters reading 0) went unnoticed.
The engine no longer permits this (#350: a headless --exec script must call
sys.exit()), and run_tests.py no longer passes a test whose output contains a
Traceback. This commit repairs the 82 they exposed, migrating each to the
current API while preserving its original intent -- not deleting assertions to
make the command exit 0. Each repair was adversarially re-verified by a second
pass asking "is this still a test, or was it gutted?"; none were.
Two tests could not be made to pass because they were right and the engine was
wrong. Rather than paper over them they were left failing and the bugs fixed
separately in 48eef0b: DijkstraMap path order (#375) and layer-setter cache
invalidation (#376). Three integration tests had encoded the reversed Dijkstra
order as expected behavior; their assertions now state the real contract
(excludes the origin, ends at the root).
Suite: 334/334, every one of them actually asserting.
Refs #341, #350, #372
78 lines
2.9 KiB
Python
78 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Test for mcrfpy.current_scene (successor to setScene()/currentScene())"""
|
|
import mcrfpy
|
|
import sys
|
|
|
|
print("Starting current_scene test...")
|
|
|
|
# Create test scenes first
|
|
scenes = ["scene_A", "scene_B", "scene_C"]
|
|
scene_objs = {}
|
|
for scene in scenes:
|
|
scene_objs[scene] = mcrfpy.Scene(scene)
|
|
print(f"Created scene: {scene}")
|
|
|
|
results = []
|
|
|
|
# Test switching between scenes by name (mcrfpy.current_scene is read/write)
|
|
for scene in scenes:
|
|
try:
|
|
mcrfpy.current_scene = scene
|
|
current = (mcrfpy.current_scene.name if mcrfpy.current_scene else None)
|
|
if current == scene:
|
|
results.append(f"[ok] current_scene set/get by name works for '{scene}'")
|
|
else:
|
|
results.append(f"[FAIL] Scene mismatch: set '{scene}', got '{current}'")
|
|
except Exception as e:
|
|
results.append(f"[FAIL] Error with scene '{scene}': {e}")
|
|
|
|
# Test switching by Scene object, and via Scene.activate()
|
|
for scene in scenes:
|
|
try:
|
|
mcrfpy.current_scene = scene_objs[scene]
|
|
current = mcrfpy.current_scene
|
|
if current.name == scene and current.active:
|
|
results.append(f"[ok] current_scene set by Scene object works for '{scene}'")
|
|
else:
|
|
results.append(f"[FAIL] Object assign mismatch: set '{scene}', got '{current.name}'")
|
|
except Exception as e:
|
|
results.append(f"[FAIL] Error assigning Scene object '{scene}': {e}")
|
|
|
|
try:
|
|
scene_objs["scene_B"].activate()
|
|
if mcrfpy.current_scene.name == "scene_B":
|
|
results.append("[ok] Scene.activate() switches the current scene")
|
|
else:
|
|
results.append(f"[FAIL] activate() left current scene at '{mcrfpy.current_scene.name}'")
|
|
except Exception as e:
|
|
results.append(f"[FAIL] Error in Scene.activate(): {e}")
|
|
|
|
# Test invalid scene - it must not change the current scene.
|
|
# Current contract: assigning an unknown scene name raises KeyError and the
|
|
# current scene is left untouched (the old setScene() silently ignored it).
|
|
current_before = (mcrfpy.current_scene.name if mcrfpy.current_scene else None)
|
|
try:
|
|
mcrfpy.current_scene = "nonexistent_scene"
|
|
results.append("[FAIL] Assigning a nonexistent scene name did not raise")
|
|
except KeyError:
|
|
results.append("[ok] Assigning a nonexistent scene name raises KeyError")
|
|
except Exception as e:
|
|
results.append(f"[FAIL] Expected KeyError for nonexistent scene, got {type(e).__name__}: {e}")
|
|
|
|
current_after = (mcrfpy.current_scene.name if mcrfpy.current_scene else None)
|
|
if current_before == current_after:
|
|
results.append(f"[ok] Failed switch leaves current scene alone (stayed on '{current_after}')")
|
|
else:
|
|
results.append(f"[FAIL] Scene changed unexpectedly from '{current_before}' to '{current_after}'")
|
|
|
|
# Print results
|
|
for result in results:
|
|
print(result)
|
|
|
|
# Determine pass/fail
|
|
if all("[ok]" in r for r in results):
|
|
print("PASS")
|
|
sys.exit(0)
|
|
else:
|
|
print("FAIL")
|
|
sys.exit(1)
|