McRogueFace/tests/api_timer_test.py
John McCardle 18cfe93a44 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.
2025-07-03 19:25:49 -04:00

70 lines
No EOL
2 KiB
Python

#!/usr/bin/env python3
"""Test for mcrfpy.setTimer() and delTimer() methods"""
import mcrfpy
import sys
def test_timers():
"""Test timer API methods"""
print("Testing mcrfpy timer methods...")
# Test 1: Create a simple timer
try:
call_count = [0]
def simple_callback(runtime):
call_count[0] += 1
print(f"Timer callback called, count={call_count[0]}, runtime={runtime}")
mcrfpy.setTimer("test_timer", simple_callback, 100)
print("✓ setTimer() called successfully")
except Exception as e:
print(f"✗ setTimer() failed: {e}")
print("FAIL")
return
# Test 2: Delete the timer
try:
mcrfpy.delTimer("test_timer")
print("✓ delTimer() called successfully")
except Exception as e:
print(f"✗ delTimer() failed: {e}")
print("FAIL")
return
# Test 3: Delete non-existent timer (should not crash)
try:
mcrfpy.delTimer("nonexistent_timer")
print("✓ delTimer() accepts non-existent timer names")
except Exception as e:
print(f"✗ delTimer() failed on non-existent timer: {e}")
print("FAIL")
return
# Test 4: Create multiple timers
try:
def callback1(rt): pass
def callback2(rt): pass
def callback3(rt): pass
mcrfpy.setTimer("timer1", callback1, 500)
mcrfpy.setTimer("timer2", callback2, 750)
mcrfpy.setTimer("timer3", callback3, 250)
print("✓ Multiple timers created successfully")
# Clean up
mcrfpy.delTimer("timer1")
mcrfpy.delTimer("timer2")
mcrfpy.delTimer("timer3")
print("✓ Multiple timers deleted successfully")
except Exception as e:
print(f"✗ Multiple timer test failed: {e}")
print("FAIL")
return
print("\nAll timer API tests passed")
print("PASS")
# Run the test
test_timers()
# Exit cleanly
sys.exit(0)