McRogueFace/tests/unit/test_animation_removal.py
John McCardle 9f481a2e4a fix: Update test files to use current API patterns
Migrates test suite to current API:
- Frame(x, y, w, h) → Frame(pos=(x, y), size=(w, h))
- Caption("text", x, y) → Caption(pos=(x, y), text="text")
- caption.size → caption.font_size
- Entity(x, y, ...) → Entity((x, y), ...)
- Grid(w, h, ...) → Grid(grid_size=(w, h), ...)
- cell.color → ColorLayer system

Tests now serve as valid API usage examples.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-29 19:47:48 -05:00

65 lines
No EOL
1.9 KiB
Python

#!/usr/bin/env python3
"""
Test if the crash is related to removing animated objects
"""
import mcrfpy
import sys
def clear_and_recreate(runtime):
"""Clear UI and recreate - mimics demo switching"""
print(f"\nTimer called at {runtime}")
ui = mcrfpy.sceneUI("test")
# Remove all but first 2 items (like clear_demo_objects)
print(f"Scene has {len(ui)} elements before clearing")
while len(ui) > 2:
ui.remove(len(ui)-1)
print(f"Scene has {len(ui)} elements after clearing")
# Create new animated objects
print("Creating new animated objects...")
for i in range(5):
f = mcrfpy.Frame(100 + i*50, 200, 40, 40)
f.fill_color = mcrfpy.Color(100 + i*30, 50, 200)
ui.append(f)
# Start animation on the new frame
target_x = 300 + i * 50
anim = mcrfpy.Animation("x", float(target_x), 1.0, "easeInOut")
anim.start(f)
print("New objects created and animated")
# Schedule exit
mcrfpy.setTimer("exit", lambda t: sys.exit(0), 2000)
# Create initial scene
print("Creating scene...")
mcrfpy.createScene("test")
mcrfpy.setScene("test")
ui = mcrfpy.sceneUI("test")
# Add title and subtitle (to preserve during clearing)
title = mcrfpy.Caption(pos=(400, 20), text="Test Title")
subtitle = mcrfpy.Caption(pos=(400, 50), text="Test Subtitle")
ui.extend([title, subtitle])
# Create initial animated objects
print("Creating initial animated objects...")
for i in range(10):
f = mcrfpy.Frame(pos=(50 + i*30, 100), size=(25, 25))
f.fill_color = mcrfpy.Color(255, 100, 100)
ui.append(f)
# Animate them
anim = mcrfpy.Animation("y", 300.0, 2.0, "easeOutBounce")
anim.start(f)
print(f"Initial scene has {len(ui)} elements")
# Schedule the clear and recreate
mcrfpy.setTimer("switch", clear_and_recreate, 1000)
print("\nEntering game loop...")