Refactor 11 more tests to mcrfpy.step() pattern
Converted from Timer-based async to step()-based sync: - test_simple_callback.py - test_empty_animation_manager.py - test_frame_clipping.py - test_frame_clipping_advanced.py - test_grid_children.py - test_color_helpers.py - test_no_arg_constructors.py - test_properties_quick.py - test_simple_drawable.py - test_python_object_cache.py - WORKING_automation_test_example.py Only 4 tests remain with Timer-based patterns (2 are headless detection tests that may require special handling). 🤖 Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Frack <frack@goblincorps.dev> Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
bb86cece2b
commit
be450286f8
12 changed files with 867 additions and 866 deletions
|
|
@ -1,47 +1,11 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Example of CORRECT test pattern using timer callbacks for automation"""
|
||||
"""Example of CORRECT test pattern using mcrfpy.step() for automation
|
||||
Refactored from timer-based approach to synchronous step() pattern.
|
||||
"""
|
||||
import mcrfpy
|
||||
from mcrfpy import automation
|
||||
from datetime import datetime
|
||||
|
||||
def run_automation_tests(timer, runtime):
|
||||
"""This runs AFTER the game loop has started and rendered frames"""
|
||||
print("\n=== Automation Test Running (1 second after start) ===")
|
||||
|
||||
# NOW we can take screenshots that will show content!
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
filename = f"WORKING_screenshot_{timestamp}.png"
|
||||
|
||||
# Take screenshot - this should now show our red frame
|
||||
result = automation.screenshot(filename)
|
||||
print(f"Screenshot taken: {filename} - Result: {result}")
|
||||
|
||||
# Test clicking on the frame
|
||||
automation.click(200, 200) # Click in center of red frame
|
||||
|
||||
# Test keyboard input
|
||||
automation.typewrite("Hello from timer callback!")
|
||||
|
||||
# Take another screenshot to show any changes
|
||||
filename2 = f"WORKING_screenshot_after_click_{timestamp}.png"
|
||||
automation.screenshot(filename2)
|
||||
print(f"Second screenshot: {filename2}")
|
||||
|
||||
print("Test completed successfully!")
|
||||
print("\nThis works because:")
|
||||
print("1. The game loop has been running for 1 second")
|
||||
print("2. The scene has been rendered multiple times")
|
||||
print("3. The RenderTexture now contains actual rendered content")
|
||||
|
||||
# Cancel this timer so it doesn't repeat
|
||||
timer.stop()
|
||||
|
||||
# Optional: exit after a moment
|
||||
def exit_game(t, r):
|
||||
print("Exiting...")
|
||||
mcrfpy.exit()
|
||||
global exit_timer
|
||||
exit_timer = mcrfpy.Timer("exit", exit_game, 500, once=True)
|
||||
import sys
|
||||
|
||||
# This code runs during --exec script execution
|
||||
print("=== Setting Up Test Scene ===")
|
||||
|
|
@ -49,6 +13,8 @@ print("=== Setting Up Test Scene ===")
|
|||
# Create scene with visible content
|
||||
timer_test_scene = mcrfpy.Scene("timer_test_scene")
|
||||
timer_test_scene.activate()
|
||||
mcrfpy.step(0.01) # Initialize scene
|
||||
|
||||
ui = timer_test_scene.children
|
||||
|
||||
# Add a bright red frame that should be visible
|
||||
|
|
@ -60,23 +26,57 @@ ui.append(frame)
|
|||
|
||||
# Add text
|
||||
caption = mcrfpy.Caption(pos=(150, 150),
|
||||
text="TIMER TEST - SHOULD BE VISIBLE",
|
||||
text="STEP TEST - SHOULD BE VISIBLE",
|
||||
fill_color=mcrfpy.Color(255, 255, 255))
|
||||
caption.font_size = 24
|
||||
frame.children.append(caption)
|
||||
|
||||
# Add click handler to demonstrate interaction
|
||||
click_received = False
|
||||
def frame_clicked(x, y, button):
|
||||
global click_received
|
||||
click_received = True
|
||||
print(f"Frame clicked at ({x}, {y}) with button {button}")
|
||||
|
||||
frame.on_click = frame_clicked
|
||||
|
||||
print("Scene setup complete. Setting timer for automation tests...")
|
||||
print("Scene setup complete.")
|
||||
|
||||
# THIS IS THE KEY: Set timer to run AFTER the game loop starts
|
||||
automation_test_timer = mcrfpy.Timer("automation_test", run_automation_tests, 1000, once=True)
|
||||
# Step to render the scene
|
||||
mcrfpy.step(0.1)
|
||||
|
||||
print("Timer set. Game loop will start after this script completes.")
|
||||
print("Automation tests will run 1 second later when content is visible.")
|
||||
print("\n=== Automation Test Running ===")
|
||||
|
||||
# Script ends here - game loop starts next
|
||||
# NOW we can take screenshots that will show content!
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
filename = f"WORKING_screenshot_{timestamp}.png"
|
||||
|
||||
# Take screenshot - this should now show our red frame
|
||||
result = automation.screenshot(filename)
|
||||
print(f"Screenshot taken: {filename} - Result: {result}")
|
||||
|
||||
# Test clicking on the frame
|
||||
automation.click(200, 200) # Click in center of red frame
|
||||
|
||||
# Step to process the click
|
||||
mcrfpy.step(0.1)
|
||||
|
||||
# Test keyboard input
|
||||
automation.typewrite("Hello from step-based test!")
|
||||
|
||||
# Step to process keyboard input
|
||||
mcrfpy.step(0.1)
|
||||
|
||||
# Take another screenshot to show any changes
|
||||
filename2 = f"WORKING_screenshot_after_click_{timestamp}.png"
|
||||
automation.screenshot(filename2)
|
||||
print(f"Second screenshot: {filename2}")
|
||||
|
||||
print("Test completed successfully!")
|
||||
print("\nThis works because:")
|
||||
print("1. mcrfpy.step() advances simulation synchronously")
|
||||
print("2. The scene renders during step() calls")
|
||||
print("3. The RenderTexture contains actual rendered content")
|
||||
|
||||
print("PASS")
|
||||
sys.exit(0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue