Test suite modernization
This commit is contained in:
parent
0969f7c2f6
commit
52fdfd0347
141 changed files with 9947 additions and 4665 deletions
|
|
@ -4,87 +4,9 @@ import mcrfpy
|
|||
from mcrfpy import automation
|
||||
import sys
|
||||
|
||||
def test_grid_none_texture(timer, runtime):
|
||||
"""Test Grid functionality without texture"""
|
||||
print("\n=== Testing Grid with None texture ===")
|
||||
|
||||
# Test 1: Create Grid with None texture
|
||||
try:
|
||||
grid = mcrfpy.Grid(grid_size=(10, 10), pos=(50, 50), size=(400, 400))
|
||||
print("✓ Grid created successfully with None texture")
|
||||
except Exception as e:
|
||||
print(f"✗ Failed to create Grid with None texture: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
# Add to UI
|
||||
ui = grid_none_test.children
|
||||
ui.append(grid)
|
||||
|
||||
# Test 2: Verify grid properties
|
||||
try:
|
||||
grid_size = grid.grid_size
|
||||
print(f"✓ Grid size: {grid_size}")
|
||||
|
||||
# Check texture property
|
||||
texture = grid.texture
|
||||
if texture is None:
|
||||
print("✓ Grid texture is None as expected")
|
||||
else:
|
||||
print(f"✗ Grid texture should be None, got: {texture}")
|
||||
except Exception as e:
|
||||
print(f"✗ Property access failed: {e}")
|
||||
|
||||
# Test 3: Access grid points using ColorLayer (new API)
|
||||
# Note: GridPoint no longer has .color - must use ColorLayer system
|
||||
try:
|
||||
# Add a color layer to the grid
|
||||
color_layer = grid.add_layer("color", z_index=-1)
|
||||
# Create a checkerboard pattern with colors
|
||||
for x in range(10):
|
||||
for y in range(10):
|
||||
if (x + y) % 2 == 0:
|
||||
color_layer.set(x, y, mcrfpy.Color(255, 0, 0, 255)) # Red
|
||||
else:
|
||||
color_layer.set(x, y, mcrfpy.Color(0, 0, 255, 255)) # Blue
|
||||
print("✓ Successfully set grid colors via ColorLayer")
|
||||
except Exception as e:
|
||||
print(f"✗ Failed to set grid colors: {e}")
|
||||
|
||||
# Test 4: Add entities to the grid
|
||||
try:
|
||||
# Create an entity with its own texture
|
||||
entity_texture = mcrfpy.Texture("assets/kenney_tinydungeon.png", 16, 16)
|
||||
entity = mcrfpy.Entity((5, 5), texture=entity_texture, sprite_index=1, grid=grid)
|
||||
grid.entities.append(entity)
|
||||
print(f"✓ Added entity to grid, total entities: {len(grid.entities)}")
|
||||
except Exception as e:
|
||||
print(f"✗ Failed to add entity: {e}")
|
||||
|
||||
# Test 5: Test grid interaction properties
|
||||
try:
|
||||
# Test zoom
|
||||
grid.zoom = 2.0
|
||||
print(f"✓ Set zoom to: {grid.zoom}")
|
||||
|
||||
# Test center (uses pixel coordinates)
|
||||
grid.center = (200, 200)
|
||||
print(f"✓ Set center to: {grid.center}")
|
||||
except Exception as e:
|
||||
print(f"✗ Grid properties failed: {e}")
|
||||
|
||||
# Take screenshot
|
||||
filename = f"grid_none_texture_test_{int(runtime)}.png"
|
||||
result = automation.screenshot(filename)
|
||||
print(f"\nScreenshot saved: {filename} - Result: {result}")
|
||||
print("The grid should show a red/blue checkerboard pattern")
|
||||
|
||||
print("\n✓ PASS - Grid works correctly without texture!")
|
||||
sys.exit(0)
|
||||
|
||||
# Set up test scene
|
||||
print("Creating test scene...")
|
||||
grid_none_test = mcrfpy.Scene("grid_none_test")
|
||||
grid_none_test.activate()
|
||||
mcrfpy.current_scene = grid_none_test
|
||||
|
||||
# Add a background frame so we can see the grid
|
||||
ui = grid_none_test.children
|
||||
|
|
@ -94,6 +16,75 @@ background = mcrfpy.Frame(pos=(0, 0), size=(800, 600),
|
|||
outline=2.0)
|
||||
ui.append(background)
|
||||
|
||||
# Schedule test
|
||||
test_timer = mcrfpy.Timer("test", test_grid_none_texture, 100, once=True)
|
||||
print("Test scheduled...")
|
||||
print("\n=== Testing Grid with None texture ===")
|
||||
|
||||
# Test 1: Create Grid with None texture
|
||||
try:
|
||||
grid = mcrfpy.Grid(grid_size=(10, 10), pos=(50, 50), size=(400, 400))
|
||||
print("PASS: Grid created successfully with None texture")
|
||||
except Exception as e:
|
||||
print(f"FAIL: Failed to create Grid with None texture: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
# Add to UI
|
||||
ui.append(grid)
|
||||
|
||||
# Test 2: Verify grid properties
|
||||
try:
|
||||
grid_size = grid.grid_size
|
||||
print(f"PASS: Grid size: {grid_size}")
|
||||
|
||||
# Check texture property
|
||||
texture = grid.texture
|
||||
if texture is None:
|
||||
print("PASS: Grid texture is None as expected")
|
||||
else:
|
||||
print(f"FAIL: Grid texture should be None, got: {texture}")
|
||||
except Exception as e:
|
||||
print(f"FAIL: Property access failed: {e}")
|
||||
|
||||
# Test 3: Access grid points using ColorLayer (new API)
|
||||
try:
|
||||
# Add a color layer to the grid
|
||||
color_layer = grid.add_layer("color", z_index=-1)
|
||||
# Create a checkerboard pattern with colors
|
||||
for x in range(10):
|
||||
for y in range(10):
|
||||
if (x + y) % 2 == 0:
|
||||
color_layer.set(x, y, mcrfpy.Color(255, 0, 0, 255)) # Red
|
||||
else:
|
||||
color_layer.set(x, y, mcrfpy.Color(0, 0, 255, 255)) # Blue
|
||||
print("PASS: Successfully set grid colors via ColorLayer")
|
||||
except Exception as e:
|
||||
print(f"FAIL: Failed to set grid colors: {e}")
|
||||
|
||||
# Test 4: Add entities to the grid
|
||||
try:
|
||||
# Create an entity with its own texture
|
||||
entity_texture = mcrfpy.Texture("assets/kenney_tinydungeon.png", 16, 16)
|
||||
entity = mcrfpy.Entity((5, 5), texture=entity_texture, sprite_index=1, grid=grid)
|
||||
grid.entities.append(entity)
|
||||
print(f"PASS: Added entity to grid, total entities: {len(grid.entities)}")
|
||||
except Exception as e:
|
||||
print(f"FAIL: Failed to add entity: {e}")
|
||||
|
||||
# Test 5: Test grid interaction properties
|
||||
try:
|
||||
# Test zoom
|
||||
grid.zoom = 2.0
|
||||
print(f"PASS: Set zoom to: {grid.zoom}")
|
||||
|
||||
# Test center (uses pixel coordinates)
|
||||
grid.center = (200, 200)
|
||||
print(f"PASS: Set center to: {grid.center}")
|
||||
except Exception as e:
|
||||
print(f"FAIL: Grid properties failed: {e}")
|
||||
|
||||
# Take screenshot
|
||||
mcrfpy.step(0.01)
|
||||
result = automation.screenshot("grid_none_texture_test.png")
|
||||
print(f"\nScreenshot saved: grid_none_texture_test.png - Result: {result}")
|
||||
print("The grid should show a red/blue checkerboard pattern")
|
||||
|
||||
print("\nPASS - Grid works correctly without texture!")
|
||||
sys.exit(0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue