McRogueFace/tests/test_grid_features.py
John McCardle f9b6cdef1c Python API improvements: Vectors, bounds, window singleton, hidden types
- #177: GridPoint.grid_pos property returns (x, y) tuple
- #179: Grid.grid_size returns Vector instead of tuple
- #181: Grid.center returns Vector instead of tuple
- #182: Caption.size/w/h read-only properties for text dimensions
- #184: mcrfpy.window singleton for window access
- #185: Removed get_bounds() method, use .bounds property instead
- #188: bounds/global_bounds return (pos, size) as pair of Vectors
- #189: Hide internal types from module namespace (iterators, collections)

Also fixed critical bug: Changed static PyTypeObject to inline in headers
to ensure single instance across translation units (was causing segfaults).

Closes #177, closes #179, closes #181, closes #182, closes #184, closes #185, closes #188, closes #189

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-05 23:00:48 -05:00

58 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""Test Grid features"""
import sys
import mcrfpy
print("Testing Grid features...")
# Create a texture first
print("Loading texture...")
texture = mcrfpy.Texture("assets/kenney_ice.png", 16, 16)
print(f"Texture loaded: {texture}")
# Create grid
print("Creating grid...")
grid = mcrfpy.Grid(grid_size=(15, 20), texture=texture, pos=(50, 100), size=(240, 320))
print(f"Grid created: {grid}")
# Test grid_size returns Vector
print("Testing grid_size...")
grid_size = grid.grid_size
print(f"grid_size type: {type(grid_size)}")
print(f"grid_size value: {grid_size}")
if not hasattr(grid_size, 'x'):
print(f"FAIL: grid_size should be Vector, got {type(grid_size)}")
sys.exit(1)
print(f"grid_size.x={grid_size.x}, grid_size.y={grid_size.y}")
if grid_size.x != 15 or grid_size.y != 20:
print(f"FAIL: grid_size should be (15, 20), got ({grid_size.x}, {grid_size.y})")
sys.exit(1)
# Test center returns Vector
print("Testing center...")
center = grid.center
print(f"center type: {type(center)}")
print(f"center value: {center}")
if not hasattr(center, 'x'):
print(f"FAIL: center should be Vector, got {type(center)}")
sys.exit(1)
print(f"center.x={center.x}, center.y={center.y}")
# Test pos returns Vector
print("Testing pos...")
pos = grid.pos
print(f"pos type: {type(pos)}")
if not hasattr(pos, 'x'):
print(f"FAIL: pos should be Vector, got {type(pos)}")
sys.exit(1)
print(f"pos.x={pos.x}, pos.y={pos.y}")
print("PASS: Grid Vector properties work correctly!")
sys.exit(0)