#!/usr/bin/env python3 """ Test for Issue #74: Add missing Grid.grid_y property Verifies that Grid objects expose grid_x and grid_y properties correctly. """ def test_grid_xy_properties(timer_name): """Test that Grid has grid_x and grid_y properties""" import mcrfpy # Test was run print("Issue #74 test: Grid.grid_x and Grid.grid_y properties") # Test with texture texture = mcrfpy.Texture("assets/kenney_ice.png", 16, 16) grid = mcrfpy.Grid(20, 15, texture, (0, 0), (800, 600)) # Test grid_x property assert hasattr(grid, 'grid_x'), "Grid should have grid_x property" assert grid.grid_x == 20, f"Expected grid_x=20, got {grid.grid_x}" print(f"✓ grid.grid_x = {grid.grid_x}") # Test grid_y property assert hasattr(grid, 'grid_y'), "Grid should have grid_y property" assert grid.grid_y == 15, f"Expected grid_y=15, got {grid.grid_y}" print(f"✓ grid.grid_y = {grid.grid_y}") # Test grid_size still works assert hasattr(grid, 'grid_size'), "Grid should still have grid_size property" assert grid.grid_size == (20, 15), f"Expected grid_size=(20, 15), got {grid.grid_size}" print(f"✓ grid.grid_size = {grid.grid_size}") # Test without texture grid2 = mcrfpy.Grid(30, 25, None, (10, 10), (480, 400)) assert grid2.grid_x == 30, f"Expected grid_x=30, got {grid2.grid_x}" assert grid2.grid_y == 25, f"Expected grid_y=25, got {grid2.grid_y}" assert grid2.grid_size == (30, 25), f"Expected grid_size=(30, 25), got {grid2.grid_size}" print("✓ Grid without texture also has correct grid_x and grid_y") # Test using in error message context (original issue) try: grid.at((-1, 0)) # Should raise error except ValueError as e: error_msg = str(e) assert "Grid.grid_x" in error_msg, f"Error message should reference Grid.grid_x: {error_msg}" print(f"✓ Error message correctly references Grid.grid_x: {error_msg}") try: grid.at((0, -1)) # Should raise error except ValueError as e: error_msg = str(e) assert "Grid.grid_y" in error_msg, f"Error message should reference Grid.grid_y: {error_msg}" print(f"✓ Error message correctly references Grid.grid_y: {error_msg}") print("\n✅ Issue #74 test PASSED - Grid.grid_x and Grid.grid_y properties work correctly") # Execute the test after a short delay to ensure window is ready import mcrfpy mcrfpy.setTimer("test_timer", test_grid_xy_properties, 100)