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>
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""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(timer, runtime):
|
|
"""Timer callback that takes screenshot"""
|
|
global call_count
|
|
call_count += 1
|
|
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}")
|
|
|
|
# Set up a simple scene
|
|
print("Creating test scene...")
|
|
test = mcrfpy.Scene("test")
|
|
test.activate()
|
|
ui = test.children
|
|
|
|
# Add visible content - a white frame on default background
|
|
frame = mcrfpy.Frame(pos=(100, 100), size=(200, 200),
|
|
fill_color=mcrfpy.Color(255, 255, 255))
|
|
ui.append(frame)
|
|
|
|
print("Setting timer to fire in 100ms...")
|
|
timer = mcrfpy.Timer("screenshot_timer", take_screenshot, 100, once=True)
|
|
print(f"Timer created: {timer}")
|
|
|
|
# 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)
|