Fix --exec interactive prompt bug and create comprehensive test suite

Major fixes:
- Fixed --exec entering Python REPL instead of game loop
- Resolved screenshot transparency issue (requires timer callbacks)
- Added debug output to trace Python initialization

Test suite created:
- 13 comprehensive tests covering all Python-exposed methods
- Tests use timer callback pattern for proper game loop interaction
- Discovered multiple critical bugs and missing features

Critical bugs found:
- Grid class segfaults on instantiation (blocks all Grid functionality)
- Issue #78 confirmed: Middle mouse click sends 'C' keyboard event
- Entity property setters have argument parsing errors
- Sprite texture setter returns improper error
- keypressScene() segfaults on non-callable arguments

Documentation updates:
- Updated CLAUDE.md with testing guidelines and TDD practices
- Created test reports documenting all findings
- Updated ROADMAP.md with test results and new priorities

The Grid segfault is now the highest priority as it blocks all Grid-based functionality.
This commit is contained in:
John McCardle 2025-07-03 19:25:49 -04:00
commit 18cfe93a44
36 changed files with 2386 additions and 13 deletions

View file

@ -0,0 +1,104 @@
#!/usr/bin/env python3
"""Test for UICollection - Related to issue #69 (Sequence Protocol)"""
import mcrfpy
from datetime import datetime
def test_UICollection():
"""Test UICollection sequence protocol compliance"""
# Create test scene
mcrfpy.createScene("collection_test")
mcrfpy.setScene("collection_test")
ui = mcrfpy.sceneUI("collection_test")
# Add various UI elements
frame = mcrfpy.Frame(10, 10, 100, 100)
caption = mcrfpy.Caption(mcrfpy.Vector(120, 10), text="Test")
# Skip sprite for now since it requires a texture
ui.append(frame)
ui.append(caption)
print("Testing UICollection sequence protocol (Issue #69)...")
# Test len()
try:
length = len(ui)
print(f"✓ len() works: {length} items")
except Exception as e:
print(f"✗ len() failed: {e}")
# Test indexing
try:
item0 = ui[0]
item1 = ui[1]
print(f"✓ Indexing works: [{type(item0).__name__}, {type(item1).__name__}]")
# Test negative indexing
last_item = ui[-1]
print(f"✓ Negative indexing works: ui[-1] = {type(last_item).__name__}")
except Exception as e:
print(f"✗ Indexing failed: {e}")
# Test slicing (if implemented)
try:
slice_items = ui[0:2]
print(f"✓ Slicing works: got {len(slice_items)} items")
except Exception as e:
print(f"✗ Slicing not implemented (Issue #69): {e}")
# Test iteration
try:
types = []
for item in ui:
types.append(type(item).__name__)
print(f"✓ Iteration works: {types}")
except Exception as e:
print(f"✗ Iteration failed: {e}")
# Test contains
try:
if frame in ui:
print("'in' operator works")
else:
print("'in' operator returned False for existing item")
except Exception as e:
print(f"'in' operator not implemented (Issue #69): {e}")
# Test remove
try:
ui.remove(1) # Remove caption
print(f"✓ remove() works, now {len(ui)} items")
except Exception as e:
print(f"✗ remove() failed: {e}")
# Test type preservation (Issue #76)
try:
# Add a frame with children to test nested collections
parent_frame = mcrfpy.Frame(250, 10, 200, 200,
fill_color=mcrfpy.Color(200, 200, 200))
child_caption = mcrfpy.Caption(mcrfpy.Vector(10, 10), text="Child")
parent_frame.children.append(child_caption)
ui.append(parent_frame)
# Check if type is preserved when retrieving
retrieved = ui[-1]
if type(retrieved).__name__ == "Frame":
print("✓ Type preservation works")
else:
print(f"✗ Type not preserved (Issue #76): got {type(retrieved).__name__}")
except Exception as e:
print(f"✗ Type preservation test failed: {e}")
# Test find by name (Issue #41 - not yet implemented)
try:
found = ui.find("Test")
print(f"✓ find() method works: {type(found).__name__}")
except AttributeError:
print("✗ find() method not implemented (Issue #41)")
except Exception as e:
print(f"✗ find() method error: {e}")
print("PASS")
# Run test immediately
test_UICollection()