McRogueFace/tests/ui_Grid_null_texture_test.py
John McCardle 1c71d8d4f7 Fix Grid to support None/null texture and fix error message bug
- Allow Grid to be created with None as texture parameter
- Use default cell dimensions (16x16) when no texture provided
- Skip sprite rendering when texture is null, but still render colors
- Fix issue #77: Corrected copy/paste error in Grid.at() error messages
- Grid now functional for color-only rendering and entity positioning

Test created to verify Grid works without texture, showing colored cells.

Closes #77
2025-07-03 19:40:42 -04:00

35 lines
No EOL
1.2 KiB
Python

#!/usr/bin/env python3
"""Test Grid creation with null/None texture to reproduce segfault"""
import mcrfpy
import sys
def test_grid_null_texture():
"""Test if Grid can be created without a texture"""
print("=== Testing Grid with null texture ===")
# Create test scene
mcrfpy.createScene("grid_null_test")
mcrfpy.setScene("grid_null_test")
ui = mcrfpy.sceneUI("grid_null_test")
# Test 1: Try with None
try:
print("Test 1: Creating Grid with None texture...")
grid = mcrfpy.Grid(10, 10, None, mcrfpy.Vector(0, 0), mcrfpy.Vector(400, 400))
print("✗ Should have raised exception for None texture")
except Exception as e:
print(f"✓ Correctly rejected None texture: {e}")
# Test 2: Try without texture parameter (if possible)
try:
print("\nTest 2: Creating Grid with missing parameters...")
grid = mcrfpy.Grid(10, 10)
print("✗ Should have raised exception for missing parameters")
except Exception as e:
print(f"✓ Correctly rejected missing parameters: {e}")
print("\nTest complete - Grid requires texture parameter")
sys.exit(0)
# Run immediately
test_grid_null_texture()