Refactor timing tests to use mcrfpy.step() for synchronous execution
Converts tests from Timer-based async patterns to step()-based sync patterns, eliminating timeout issues in headless testing. Refactored tests: - simple_timer_screenshot_test.py - test_animation_callback_simple.py - test_animation_property_locking.py - test_animation_raii.py - test_animation_removal.py - test_timer_callback.py Also updates KNOWN_ISSUES.md with comprehensive documentation on the step()-based testing pattern including examples and best practices. 🤖 Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
f063d0af0c
commit
4528ece0a7
7 changed files with 325 additions and 290 deletions
|
|
@ -1,28 +1,23 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Simplified test to verify timer-based screenshots work"""
|
||||
"""Test to verify timer-based screenshots work using mcrfpy.step() for synchronous execution"""
|
||||
import mcrfpy
|
||||
from mcrfpy import automation
|
||||
import sys
|
||||
|
||||
# Counter to track timer calls
|
||||
call_count = 0
|
||||
|
||||
def take_screenshot_and_exit(timer, runtime):
|
||||
"""Timer callback that takes screenshot then exits"""
|
||||
def take_screenshot(timer, runtime):
|
||||
"""Timer callback that takes screenshot"""
|
||||
global call_count
|
||||
call_count += 1
|
||||
|
||||
print(f"\nTimer callback fired! (call #{call_count})")
|
||||
print(f"Timer callback fired! (call #{call_count}, runtime={runtime})")
|
||||
|
||||
# Take screenshot
|
||||
filename = f"timer_screenshot_test_{call_count}.png"
|
||||
result = automation.screenshot(filename)
|
||||
print(f"Screenshot result: {result} -> {filename}")
|
||||
|
||||
# Exit after first call
|
||||
if call_count >= 1:
|
||||
print("Exiting game...")
|
||||
mcrfpy.exit()
|
||||
|
||||
# Set up a simple scene
|
||||
print("Creating test scene...")
|
||||
test = mcrfpy.Scene("test")
|
||||
|
|
@ -35,6 +30,17 @@ frame = mcrfpy.Frame(pos=(100, 100), size=(200, 200),
|
|||
ui.append(frame)
|
||||
|
||||
print("Setting timer to fire in 100ms...")
|
||||
mcrfpy.Timer("screenshot_timer", take_screenshot_and_exit, 100, once=True)
|
||||
timer = mcrfpy.Timer("screenshot_timer", take_screenshot, 100, once=True)
|
||||
print(f"Timer created: {timer}")
|
||||
|
||||
print("Setup complete. Game loop starting...")
|
||||
# Use mcrfpy.step() to advance simulation synchronously instead of waiting
|
||||
print("Advancing simulation by 200ms using step()...")
|
||||
mcrfpy.step(0.2) # Advance 200ms - timer at 100ms should fire
|
||||
|
||||
# Verify timer fired
|
||||
if call_count >= 1:
|
||||
print("SUCCESS: Timer fired and screenshot taken!")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print(f"FAIL: Expected call_count >= 1, got {call_count}")
|
||||
sys.exit(1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue