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,105 +1,95 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Advanced test for UIFrame clipping with nested frames"""
|
||||
"""Advanced test for UIFrame clipping with nested frames
|
||||
Refactored to use mcrfpy.step() for synchronous execution.
|
||||
"""
|
||||
|
||||
import mcrfpy
|
||||
from mcrfpy import Color, Frame, Caption, Vector
|
||||
from mcrfpy import Color, Frame, Caption, Vector, automation
|
||||
import sys
|
||||
|
||||
def test_nested_clipping(timer, runtime):
|
||||
"""Test nested frames with clipping"""
|
||||
timer.stop()
|
||||
|
||||
print("Testing advanced UIFrame clipping with nested frames...")
|
||||
|
||||
# Create test scene
|
||||
scene = test.children
|
||||
|
||||
# Create outer frame with clipping enabled
|
||||
outer = Frame(pos=(50, 50), size=(400, 300),
|
||||
fill_color=Color(50, 50, 150),
|
||||
outline_color=Color(255, 255, 255),
|
||||
outline=3)
|
||||
outer.name = "outer"
|
||||
outer.clip_children = True
|
||||
scene.append(outer)
|
||||
|
||||
# Create inner frame that extends beyond outer bounds
|
||||
inner = Frame(pos=(200, 150), size=(300, 200),
|
||||
fill_color=Color(150, 50, 50),
|
||||
outline_color=Color(255, 255, 0),
|
||||
outline=2)
|
||||
inner.name = "inner"
|
||||
inner.clip_children = True # Also enable clipping on inner frame
|
||||
outer.children.append(inner)
|
||||
|
||||
# Add content to inner frame that extends beyond its bounds
|
||||
for i in range(5):
|
||||
caption = Caption(text=f"Line {i+1}: This text should be double-clipped", pos=(10, 30 * i))
|
||||
caption.font_size = 14
|
||||
caption.fill_color = Color(255, 255, 255)
|
||||
inner.children.append(caption)
|
||||
|
||||
# Add a child frame to inner that extends way out
|
||||
deeply_nested = Frame(pos=(250, 100), size=(200, 150),
|
||||
fill_color=Color(50, 150, 50),
|
||||
outline_color=Color(255, 0, 255),
|
||||
outline=2)
|
||||
deeply_nested.name = "deeply_nested"
|
||||
inner.children.append(deeply_nested)
|
||||
|
||||
# Add status text
|
||||
status = Caption(text="Nested clipping test:\n"
|
||||
"- Blue outer frame clips red inner frame\n"
|
||||
"- Red inner frame clips green deeply nested frame\n"
|
||||
"- All text should be clipped to frame bounds",
|
||||
pos=(50, 380))
|
||||
status.font_size = 12
|
||||
status.fill_color = Color(200, 200, 200)
|
||||
scene.append(status)
|
||||
|
||||
# Test render texture size handling
|
||||
print(f"Outer frame size: {outer.w}x{outer.h}")
|
||||
print(f"Inner frame size: {inner.w}x{inner.h}")
|
||||
|
||||
# Dynamically resize frames to test RenderTexture recreation
|
||||
def resize_test(timer, runtime):
|
||||
timer.stop()
|
||||
print("Resizing frames to test RenderTexture recreation...")
|
||||
outer.w = 450
|
||||
outer.h = 350
|
||||
inner.w = 350
|
||||
inner.h = 250
|
||||
print(f"New outer frame size: {outer.w}x{outer.h}")
|
||||
print(f"New inner frame size: {inner.w}x{inner.h}")
|
||||
|
||||
# Take screenshot after resize
|
||||
global screenshot_resize_timer
|
||||
screenshot_resize_timer = mcrfpy.Timer("screenshot_resize", take_resize_screenshot, 500, once=True)
|
||||
|
||||
def take_resize_screenshot(timer, runtime):
|
||||
timer.stop()
|
||||
from mcrfpy import automation
|
||||
automation.screenshot("frame_clipping_resized.png")
|
||||
print("\nAdvanced test completed!")
|
||||
print("Screenshots saved:")
|
||||
print(" - frame_clipping_resized.png (after resize)")
|
||||
sys.exit(0)
|
||||
|
||||
# Take initial screenshot
|
||||
from mcrfpy import automation
|
||||
automation.screenshot("frame_clipping_nested.png")
|
||||
print("Initial screenshot saved: frame_clipping_nested.png")
|
||||
|
||||
# Schedule resize test
|
||||
global resize_test_timer
|
||||
resize_test_timer = mcrfpy.Timer("resize_test", resize_test, 1000, once=True)
|
||||
|
||||
# Main execution
|
||||
print("Creating advanced test scene...")
|
||||
test = mcrfpy.Scene("test")
|
||||
test.activate()
|
||||
mcrfpy.step(0.01)
|
||||
|
||||
# Schedule the test
|
||||
test_nested_clipping_timer = mcrfpy.Timer("test_nested_clipping", test_nested_clipping, 100, once=True)
|
||||
print("Testing advanced UIFrame clipping with nested frames...")
|
||||
|
||||
print("Advanced test scheduled, running...")
|
||||
# Create test scene
|
||||
scene = test.children
|
||||
|
||||
# Create outer frame with clipping enabled
|
||||
outer = Frame(pos=(50, 50), size=(400, 300),
|
||||
fill_color=Color(50, 50, 150),
|
||||
outline_color=Color(255, 255, 255),
|
||||
outline=3)
|
||||
outer.name = "outer"
|
||||
outer.clip_children = True
|
||||
scene.append(outer)
|
||||
|
||||
# Create inner frame that extends beyond outer bounds
|
||||
inner = Frame(pos=(200, 150), size=(300, 200),
|
||||
fill_color=Color(150, 50, 50),
|
||||
outline_color=Color(255, 255, 0),
|
||||
outline=2)
|
||||
inner.name = "inner"
|
||||
inner.clip_children = True # Also enable clipping on inner frame
|
||||
outer.children.append(inner)
|
||||
|
||||
# Add content to inner frame that extends beyond its bounds
|
||||
for i in range(5):
|
||||
caption = Caption(text=f"Line {i+1}: This text should be double-clipped", pos=(10, 30 * i))
|
||||
caption.font_size = 14
|
||||
caption.fill_color = Color(255, 255, 255)
|
||||
inner.children.append(caption)
|
||||
|
||||
# Add a child frame to inner that extends way out
|
||||
deeply_nested = Frame(pos=(250, 100), size=(200, 150),
|
||||
fill_color=Color(50, 150, 50),
|
||||
outline_color=Color(255, 0, 255),
|
||||
outline=2)
|
||||
deeply_nested.name = "deeply_nested"
|
||||
inner.children.append(deeply_nested)
|
||||
|
||||
# Add status text
|
||||
status = Caption(text="Nested clipping test:\n"
|
||||
"- Blue outer frame clips red inner frame\n"
|
||||
"- Red inner frame clips green deeply nested frame\n"
|
||||
"- All text should be clipped to frame bounds",
|
||||
pos=(50, 380))
|
||||
status.font_size = 12
|
||||
status.fill_color = Color(200, 200, 200)
|
||||
scene.append(status)
|
||||
|
||||
# Test render texture size handling
|
||||
print(f"Outer frame size: {outer.w}x{outer.h}")
|
||||
print(f"Inner frame size: {inner.w}x{inner.h}")
|
||||
|
||||
# Step to render
|
||||
mcrfpy.step(0.1)
|
||||
|
||||
# Take initial screenshot
|
||||
automation.screenshot("frame_clipping_nested.png")
|
||||
print("Initial screenshot saved: frame_clipping_nested.png")
|
||||
|
||||
# Dynamically resize frames to test RenderTexture recreation
|
||||
print("Resizing frames to test RenderTexture recreation...")
|
||||
outer.w = 450
|
||||
outer.h = 350
|
||||
inner.w = 350
|
||||
inner.h = 250
|
||||
print(f"New outer frame size: {outer.w}x{outer.h}")
|
||||
print(f"New inner frame size: {inner.w}x{inner.h}")
|
||||
|
||||
# Step to render resize
|
||||
mcrfpy.step(0.1)
|
||||
|
||||
# Take screenshot after resize
|
||||
automation.screenshot("frame_clipping_resized.png")
|
||||
|
||||
print("\nAdvanced test completed!")
|
||||
print("Screenshots saved:")
|
||||
print(" - frame_clipping_nested.png (initial)")
|
||||
print(" - frame_clipping_resized.png (after resize)")
|
||||
|
||||
print("PASS")
|
||||
sys.exit(0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue