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
65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Test for mcrfpy.Scene() creation and activation (formerly mcrfpy.createScene())"""
|
|
import mcrfpy
|
|
import sys
|
|
|
|
def test_createScene():
|
|
"""Test creating a new scene"""
|
|
failures = []
|
|
scenes = {}
|
|
|
|
# Test creating scenes
|
|
test_scenes = ["test_scene1", "test_scene2", "special_chars_!@#"]
|
|
|
|
for scene_name in test_scenes:
|
|
try:
|
|
scenes[scene_name] = mcrfpy.Scene(scene_name)
|
|
print(f"PASS: Created scene: {scene_name}")
|
|
except Exception as e:
|
|
print(f"FAIL: Failed to create scene {scene_name}: {e}")
|
|
failures.append(f"create {scene_name}")
|
|
continue
|
|
|
|
if scenes[scene_name].name != scene_name:
|
|
print(f"FAIL: scene.name mismatch: expected '{scene_name}', got '{scenes[scene_name].name}'")
|
|
failures.append(f"name {scene_name}")
|
|
|
|
# Activate a created scene to verify it exists and is switchable
|
|
if "test_scene1" in scenes:
|
|
try:
|
|
scenes["test_scene1"].activate()
|
|
current = (mcrfpy.current_scene.name if mcrfpy.current_scene else None)
|
|
if current == "test_scene1":
|
|
print("PASS: Scene switching works correctly")
|
|
else:
|
|
print(f"FAIL: Scene switch failed: expected 'test_scene1', got '{current}'")
|
|
failures.append("activate()")
|
|
except Exception as e:
|
|
print(f"FAIL: Scene switching error: {e}")
|
|
failures.append("activate()")
|
|
|
|
# current_scene is also writable directly
|
|
try:
|
|
mcrfpy.current_scene = scenes["test_scene2"]
|
|
current = (mcrfpy.current_scene.name if mcrfpy.current_scene else None)
|
|
if current == "test_scene2":
|
|
print("PASS: mcrfpy.current_scene assignment works correctly")
|
|
else:
|
|
print(f"FAIL: current_scene assignment failed: expected 'test_scene2', got '{current}'")
|
|
failures.append("current_scene=")
|
|
except Exception as e:
|
|
print(f"FAIL: current_scene assignment error: {e}")
|
|
failures.append("current_scene=")
|
|
|
|
return failures
|
|
|
|
# Run test immediately
|
|
print("Running createScene test...")
|
|
failures = test_createScene()
|
|
print("Test completed.")
|
|
|
|
if failures:
|
|
print("FAIL: " + ", ".join(failures))
|
|
sys.exit(1)
|
|
print("PASS")
|
|
sys.exit(0)
|