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:
Frick 2026-01-14 02:56:21 +00:00
commit 4528ece0a7
7 changed files with 325 additions and 290 deletions

View file

@ -1,73 +1,55 @@
#!/usr/bin/env python3
"""Simple test for animation callbacks - demonstrates basic usage"""
"""Simple test for animation callbacks using mcrfpy.step() for synchronous execution"""
import mcrfpy
import sys
print("Animation Callback Demo")
print("=" * 30)
# Global state to track callback
callback_count = 0
callback_demo = None # Will be set in setup_and_run
def my_callback(anim, target):
"""Simple callback that prints when animation completes"""
global callback_count
callback_count += 1
print(f"Animation completed! Callback #{callback_count}")
# For now, anim and target are None - future enhancement
def setup_and_run():
"""Set up scene and run animation with callback"""
global callback_demo
# Create scene
callback_demo = mcrfpy.Scene("callback_demo")
callback_demo.activate()
# Create scene
callback_demo = mcrfpy.Scene("callback_demo")
callback_demo.activate()
# Create a frame to animate
frame = mcrfpy.Frame((100, 100), (200, 200), fill_color=(255, 0, 0))
ui = callback_demo.children
ui.append(frame)
# Create a frame to animate
frame = mcrfpy.Frame((100, 100), (200, 200), fill_color=(255, 0, 0))
ui = callback_demo.children
ui.append(frame)
# Create animation with callback
print("Starting animation with callback...")
anim = mcrfpy.Animation("x", 400.0, 1.0, "easeInOutQuad", callback=my_callback)
anim.start(frame)
# Test 1: Animation with callback
print("Starting animation with callback (1.0s duration)...")
anim = mcrfpy.Animation("x", 400.0, 1.0, "easeInOutQuad", callback=my_callback)
anim.start(frame)
# Schedule check after animation should complete
mcrfpy.Timer("check", check_result, 1500, once=True)
# Use mcrfpy.step() to advance past animation completion
mcrfpy.step(1.5) # Advance 1.5 seconds - animation completes at 1.0s
def check_result(timer, runtime):
"""Check if callback fired correctly"""
global callback_count, callback_demo
if callback_count != 1:
print(f"FAIL: Expected 1 callback, got {callback_count}")
sys.exit(1)
print("SUCCESS: Callback fired exactly once!")
if callback_count == 1:
print("SUCCESS: Callback fired exactly once!")
# Test 2: Animation without callback
print("\nTesting animation without callback (0.5s duration)...")
anim2 = mcrfpy.Animation("y", 300.0, 0.5, "linear")
anim2.start(frame)
# Test 2: Animation without callback
print("\nTesting animation without callback...")
ui = callback_demo.children
frame = ui[0]
# Advance past second animation
mcrfpy.step(0.7)
anim2 = mcrfpy.Animation("y", 300.0, 0.5, "linear")
anim2.start(frame)
if callback_count != 1:
print(f"FAIL: Callback count changed to {callback_count}")
sys.exit(1)
mcrfpy.Timer("final", final_check, 700, once=True)
else:
print(f"FAIL: Expected 1 callback, got {callback_count}")
sys.exit(1)
def final_check(timer, runtime):
"""Final check - callback count should still be 1"""
global callback_count
if callback_count == 1:
print("SUCCESS: No unexpected callbacks fired!")
print("\nAnimation callback feature working correctly!")
sys.exit(0)
else:
print(f"FAIL: Callback count changed to {callback_count}")
sys.exit(1)
# Start the demo
print("Animation Callback Demo")
print("=" * 30)
setup_and_run()
print("SUCCESS: No unexpected callbacks fired!")
print("\nAnimation callback feature working correctly!")
sys.exit(0)