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,135 +1,118 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Test UIFrame clipping functionality"""
|
||||
"""Test UIFrame clipping functionality
|
||||
Refactored to use mcrfpy.step() for synchronous execution.
|
||||
"""
|
||||
|
||||
import mcrfpy
|
||||
from mcrfpy import Color, Frame, Caption
|
||||
from mcrfpy import Color, Frame, Caption, automation
|
||||
import sys
|
||||
|
||||
# Module-level state to avoid closures
|
||||
_test_state = {}
|
||||
|
||||
def take_second_screenshot(timer, runtime):
|
||||
"""Take final screenshot and exit"""
|
||||
timer.stop()
|
||||
from mcrfpy import automation
|
||||
automation.screenshot("frame_clipping_animated.png")
|
||||
print("\nTest completed successfully!")
|
||||
print("Screenshots saved:")
|
||||
print(" - frame_clipping_test.png (initial state)")
|
||||
print(" - frame_clipping_animated.png (with animation)")
|
||||
sys.exit(0)
|
||||
|
||||
def animate_frames(timer, runtime):
|
||||
"""Animate frames to demonstrate clipping"""
|
||||
timer.stop()
|
||||
scene = test.children
|
||||
# Move child frames
|
||||
parent1 = scene[0]
|
||||
parent2 = scene[1]
|
||||
parent1.children[1].x = 50
|
||||
parent2.children[1].x = 50
|
||||
global screenshot2_timer
|
||||
screenshot2_timer = mcrfpy.Timer("screenshot2", take_second_screenshot, 500, once=True)
|
||||
|
||||
def test_clipping(timer, runtime):
|
||||
"""Test that clip_children property works correctly"""
|
||||
timer.stop()
|
||||
|
||||
print("Testing UIFrame clipping functionality...")
|
||||
|
||||
scene = test.children
|
||||
|
||||
# Create parent frame with clipping disabled (default)
|
||||
parent1 = Frame(pos=(50, 50), size=(200, 150),
|
||||
fill_color=Color(100, 100, 200),
|
||||
outline_color=Color(255, 255, 255),
|
||||
outline=2)
|
||||
parent1.name = "parent1"
|
||||
scene.append(parent1)
|
||||
|
||||
# Create parent frame with clipping enabled
|
||||
parent2 = Frame(pos=(300, 50), size=(200, 150),
|
||||
fill_color=Color(200, 100, 100),
|
||||
outline_color=Color(255, 255, 255),
|
||||
outline=2)
|
||||
parent2.name = "parent2"
|
||||
parent2.clip_children = True
|
||||
scene.append(parent2)
|
||||
|
||||
# Add captions to both frames
|
||||
caption1 = Caption(text="This text should overflow the frame bounds", pos=(10, 10))
|
||||
caption1.font_size = 16
|
||||
caption1.fill_color = Color(255, 255, 255)
|
||||
parent1.children.append(caption1)
|
||||
|
||||
caption2 = Caption(text="This text should be clipped to frame bounds", pos=(10, 10))
|
||||
caption2.font_size = 16
|
||||
caption2.fill_color = Color(255, 255, 255)
|
||||
parent2.children.append(caption2)
|
||||
|
||||
# Add child frames that extend beyond parent bounds
|
||||
child1 = Frame(pos=(150, 100), size=(100, 100),
|
||||
fill_color=Color(50, 255, 50),
|
||||
outline_color=Color(0, 0, 0),
|
||||
outline=1)
|
||||
parent1.children.append(child1)
|
||||
|
||||
child2 = Frame(pos=(150, 100), size=(100, 100),
|
||||
fill_color=Color(50, 255, 50),
|
||||
outline_color=Color(0, 0, 0),
|
||||
outline=1)
|
||||
parent2.children.append(child2)
|
||||
|
||||
# Add caption to show clip state
|
||||
status = Caption(text=f"Left frame: clip_children={parent1.clip_children}\n"
|
||||
f"Right frame: clip_children={parent2.clip_children}",
|
||||
pos=(50, 250))
|
||||
status.font_size = 14
|
||||
status.fill_color = Color(255, 255, 255)
|
||||
scene.append(status)
|
||||
|
||||
# Add instructions
|
||||
instructions = Caption(text="Left: Children should overflow (no clipping)\n"
|
||||
"Right: Children should be clipped to frame bounds\n"
|
||||
"Press 'c' to toggle clipping on left frame",
|
||||
pos=(50, 300))
|
||||
instructions.font_size = 12
|
||||
instructions.fill_color = Color(200, 200, 200)
|
||||
scene.append(instructions)
|
||||
|
||||
# Take screenshot
|
||||
from mcrfpy import automation
|
||||
automation.screenshot("frame_clipping_test.png")
|
||||
|
||||
print(f"Parent1 clip_children: {parent1.clip_children}")
|
||||
print(f"Parent2 clip_children: {parent2.clip_children}")
|
||||
|
||||
# Test toggling clip_children
|
||||
parent1.clip_children = True
|
||||
print(f"After toggle - Parent1 clip_children: {parent1.clip_children}")
|
||||
|
||||
# Verify the property setter works
|
||||
try:
|
||||
parent1.clip_children = "not a bool"
|
||||
print("ERROR: clip_children accepted non-boolean value")
|
||||
except TypeError as e:
|
||||
print(f"PASS: clip_children correctly rejected non-boolean: {e}")
|
||||
|
||||
# Start animation after a short delay
|
||||
global animate_timer
|
||||
animate_timer = mcrfpy.Timer("animate", animate_frames, 100, once=True)
|
||||
|
||||
def handle_keypress(key, modifiers):
|
||||
if key == "c":
|
||||
scene = test.children
|
||||
parent1 = scene[0]
|
||||
parent1.clip_children = not parent1.clip_children
|
||||
print(f"Toggled parent1 clip_children to: {parent1.clip_children}")
|
||||
|
||||
# Main execution
|
||||
print("Creating test scene...")
|
||||
test = mcrfpy.Scene("test")
|
||||
test.activate()
|
||||
test.on_key = handle_keypress
|
||||
test_clipping_timer = mcrfpy.Timer("test_clipping", test_clipping, 100, once=True)
|
||||
print("Test scheduled, running...")
|
||||
mcrfpy.step(0.01) # Initialize
|
||||
|
||||
print("Testing UIFrame clipping functionality...")
|
||||
|
||||
scene = test.children
|
||||
|
||||
# Create parent frame with clipping disabled (default)
|
||||
parent1 = Frame(pos=(50, 50), size=(200, 150),
|
||||
fill_color=Color(100, 100, 200),
|
||||
outline_color=Color(255, 255, 255),
|
||||
outline=2)
|
||||
parent1.name = "parent1"
|
||||
scene.append(parent1)
|
||||
|
||||
# Create parent frame with clipping enabled
|
||||
parent2 = Frame(pos=(300, 50), size=(200, 150),
|
||||
fill_color=Color(200, 100, 100),
|
||||
outline_color=Color(255, 255, 255),
|
||||
outline=2)
|
||||
parent2.name = "parent2"
|
||||
parent2.clip_children = True
|
||||
scene.append(parent2)
|
||||
|
||||
# Add captions to both frames
|
||||
caption1 = Caption(text="This text should overflow the frame bounds", pos=(10, 10))
|
||||
caption1.font_size = 16
|
||||
caption1.fill_color = Color(255, 255, 255)
|
||||
parent1.children.append(caption1)
|
||||
|
||||
caption2 = Caption(text="This text should be clipped to frame bounds", pos=(10, 10))
|
||||
caption2.font_size = 16
|
||||
caption2.fill_color = Color(255, 255, 255)
|
||||
parent2.children.append(caption2)
|
||||
|
||||
# Add child frames that extend beyond parent bounds
|
||||
child1 = Frame(pos=(150, 100), size=(100, 100),
|
||||
fill_color=Color(50, 255, 50),
|
||||
outline_color=Color(0, 0, 0),
|
||||
outline=1)
|
||||
parent1.children.append(child1)
|
||||
|
||||
child2 = Frame(pos=(150, 100), size=(100, 100),
|
||||
fill_color=Color(50, 255, 50),
|
||||
outline_color=Color(0, 0, 0),
|
||||
outline=1)
|
||||
parent2.children.append(child2)
|
||||
|
||||
# Add caption to show clip state
|
||||
status = Caption(text=f"Left frame: clip_children={parent1.clip_children}\n"
|
||||
f"Right frame: clip_children={parent2.clip_children}",
|
||||
pos=(50, 250))
|
||||
status.font_size = 14
|
||||
status.fill_color = Color(255, 255, 255)
|
||||
scene.append(status)
|
||||
|
||||
# Add instructions
|
||||
instructions = Caption(text="Left: Children should overflow (no clipping)\n"
|
||||
"Right: Children should be clipped to frame bounds",
|
||||
pos=(50, 300))
|
||||
instructions.font_size = 12
|
||||
instructions.fill_color = Color(200, 200, 200)
|
||||
scene.append(instructions)
|
||||
|
||||
# Step to render
|
||||
mcrfpy.step(0.1)
|
||||
|
||||
# Take screenshot
|
||||
automation.screenshot("frame_clipping_test.png")
|
||||
|
||||
print(f"Parent1 clip_children: {parent1.clip_children}")
|
||||
print(f"Parent2 clip_children: {parent2.clip_children}")
|
||||
|
||||
# Test toggling clip_children
|
||||
parent1.clip_children = True
|
||||
print(f"After toggle - Parent1 clip_children: {parent1.clip_children}")
|
||||
|
||||
# Verify the property setter works
|
||||
test_passed = True
|
||||
try:
|
||||
parent1.clip_children = "not a bool"
|
||||
print("ERROR: clip_children accepted non-boolean value")
|
||||
test_passed = False
|
||||
except TypeError as e:
|
||||
print(f"PASS: clip_children correctly rejected non-boolean: {e}")
|
||||
|
||||
# Animate frames (move children)
|
||||
parent1.children[1].x = 50
|
||||
parent2.children[1].x = 50
|
||||
|
||||
# Step to render animation
|
||||
mcrfpy.step(0.1)
|
||||
|
||||
# Take second screenshot
|
||||
automation.screenshot("frame_clipping_animated.png")
|
||||
|
||||
print("\nTest completed successfully!")
|
||||
print("Screenshots saved:")
|
||||
print(" - frame_clipping_test.png (initial state)")
|
||||
print(" - frame_clipping_animated.png (with animation)")
|
||||
|
||||
if test_passed:
|
||||
print("PASS")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("FAIL")
|
||||
sys.exit(1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue