the low-hanging fruit of pre-existing issues and standardizing the
Python interfaces
Special thanks to Claude Code, ~100k output tokens for this merge
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
commit 99f301e3a0
Author: John McCardle <mccardle.john@gmail.com>
Date: Sat Jul 5 16:25:32 2025 -0400
Add position tuple support and pos property to UI elements
closes #83, closes #84
- Issue #83: Add position tuple support to constructors
- Frame and Sprite now accept both (x, y) and ((x, y)) forms
- Also accept Vector objects as position arguments
- Caption and Entity already supported tuple/Vector forms
- Uses PyVector::from_arg for flexible position parsing
- Issue #84: Add pos property to Frame and Sprite
- Added pos getter that returns a Vector
- Added pos setter that accepts Vector or tuple
- Provides consistency with Caption and Entity which already had pos properties
- All UI elements now have a uniform way to get/set positions as Vectors
Both features improve API consistency and make it easier to work with positions.
commit 2f2b488fb5
Author: John McCardle <mccardle.john@gmail.com>
Date: Sat Jul 5 16:18:10 2025 -0400
Standardize sprite_index property and add scale_x/scale_y to UISprite
closes #81, closes #82
- Issue #81: Standardized property name to sprite_index across UISprite and UIEntity
- Added sprite_index as the primary property name
- Kept sprite_number as a deprecated alias for backward compatibility
- Updated repr() methods to use sprite_index
- Updated animation system to recognize both names
- Issue #82: Added scale_x and scale_y properties to UISprite
- Enables non-uniform scaling of sprites
- scale property still works for uniform scaling
- Both properties work with the animation system
All existing code using sprite_number continues to work due to backward compatibility.
commit 5a003a9aa5
Author: John McCardle <mccardle.john@gmail.com>
Date: Sat Jul 5 16:09:52 2025 -0400
Fix multiple low priority issues
closes #12, closes #80, closes #95, closes #96, closes #99
- Issue #12: Set tp_new to NULL for GridPoint and GridPointState to prevent instantiation from Python
- Issue #80: Renamed Caption.size to Caption.font_size for semantic clarity
- Issue #95: Fixed UICollection repr to show actual derived types instead of generic UIDrawable
- Issue #96: Added extend() method to UICollection for API consistency with UIEntityCollection
- Issue #99: Exposed read-only properties for Texture (sprite_width, sprite_height, sheet_width, sheet_height, sprite_count, source) and Font (family, source)
All issues have corresponding tests that verify the fixes work correctly.
commit e5affaf317
Author: John McCardle <mccardle.john@gmail.com>
Date: Sat Jul 5 15:50:09 2025 -0400
Fix critical issues: script loading, entity types, and color properties
- Issue #37: Fix Windows scripts subdirectory not checked
- Updated executeScript() to use executable_path() from platform.h
- Scripts now load correctly when working directory differs from executable
- Issue #76: Fix UIEntityCollection returns wrong type
- Updated UIEntityCollectionIter::next() to check for stored Python object
- Derived Entity classes now preserve their type when retrieved from collections
- Issue #9: Recreate RenderTexture when resized (already fixed)
- Confirmed RenderTexture recreation already implemented in set_size() and set_float_member()
- Uses 1.5x padding and 4096 max size limit
- Issue #79: Fix Color r, g, b, a properties return None
- Implemented get_member() and set_member() in PyColor.cpp
- Color component properties now work correctly with proper validation
- Additional fix: Grid.at() method signature
- Changed from METH_O to METH_VARARGS to accept two arguments
All fixes include comprehensive tests to verify functionality.
closes #37, closes #76, closes #9, closes #79
152 lines
No EOL
5.8 KiB
Python
152 lines
No EOL
5.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Comprehensive test for Issue #37: Windows scripts subdirectory bug
|
|
|
|
This test comprehensively tests script loading from different working directories,
|
|
particularly focusing on the Windows issue where relative paths fail.
|
|
|
|
The bug: On Windows, when mcrogueface.exe is run from a different directory,
|
|
it fails to find scripts/game.py because fopen uses relative paths.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import tempfile
|
|
import shutil
|
|
import platform
|
|
|
|
def create_test_script(content=""):
|
|
"""Create a minimal test script"""
|
|
if not content:
|
|
content = """
|
|
import mcrfpy
|
|
print("TEST_SCRIPT_LOADED_FROM_PATH")
|
|
mcrfpy.createScene("test_scene")
|
|
# Exit cleanly to avoid hanging
|
|
import sys
|
|
sys.exit(0)
|
|
"""
|
|
return content
|
|
|
|
def run_mcrogueface(exe_path, cwd, timeout=5):
|
|
"""Run mcrogueface from a specific directory and capture output"""
|
|
cmd = [exe_path, "--headless"]
|
|
|
|
try:
|
|
result = subprocess.run(
|
|
cmd,
|
|
cwd=cwd,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=timeout
|
|
)
|
|
return result.stdout, result.stderr, result.returncode
|
|
except subprocess.TimeoutExpired:
|
|
return "", "TIMEOUT", -1
|
|
except Exception as e:
|
|
return "", str(e), -1
|
|
|
|
def test_script_loading():
|
|
"""Test script loading from various directories"""
|
|
# Detect platform
|
|
is_windows = platform.system() == "Windows"
|
|
print(f"Platform: {platform.system()}")
|
|
|
|
# Get paths
|
|
repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
build_dir = os.path.join(repo_root, "build")
|
|
exe_name = "mcrogueface.exe" if is_windows else "mcrogueface"
|
|
exe_path = os.path.join(build_dir, exe_name)
|
|
|
|
if not os.path.exists(exe_path):
|
|
print(f"FAIL: Executable not found at {exe_path}")
|
|
print("Please build the project first")
|
|
return
|
|
|
|
# Backup original game.py
|
|
scripts_dir = os.path.join(build_dir, "scripts")
|
|
game_py_path = os.path.join(scripts_dir, "game.py")
|
|
game_py_backup = game_py_path + ".backup"
|
|
|
|
if os.path.exists(game_py_path):
|
|
shutil.copy(game_py_path, game_py_backup)
|
|
|
|
try:
|
|
# Create test script
|
|
os.makedirs(scripts_dir, exist_ok=True)
|
|
with open(game_py_path, "w") as f:
|
|
f.write(create_test_script())
|
|
|
|
print("\n=== Test 1: Run from build directory (baseline) ===")
|
|
stdout, stderr, code = run_mcrogueface(exe_path, build_dir)
|
|
if "TEST_SCRIPT_LOADED_FROM_PATH" in stdout:
|
|
print("✓ PASS: Script loaded when running from build directory")
|
|
else:
|
|
print("✗ FAIL: Script not loaded from build directory")
|
|
print(f" stdout: {stdout[:200]}")
|
|
print(f" stderr: {stderr[:200]}")
|
|
|
|
print("\n=== Test 2: Run from parent directory ===")
|
|
stdout, stderr, code = run_mcrogueface(exe_path, repo_root)
|
|
if "TEST_SCRIPT_LOADED_FROM_PATH" in stdout:
|
|
print("✓ PASS: Script loaded from parent directory")
|
|
else:
|
|
print("✗ FAIL: Script not loaded from parent directory")
|
|
print(" This might indicate Issue #37")
|
|
print(f" stdout: {stdout[:200]}")
|
|
print(f" stderr: {stderr[:200]}")
|
|
|
|
print("\n=== Test 3: Run from system temp directory ===")
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
stdout, stderr, code = run_mcrogueface(exe_path, tmpdir)
|
|
if "TEST_SCRIPT_LOADED_FROM_PATH" in stdout:
|
|
print("✓ PASS: Script loaded from temp directory")
|
|
else:
|
|
print("✗ FAIL: Script not loaded from temp directory")
|
|
print(" This is the core Issue #37 bug!")
|
|
print(f" Working directory: {tmpdir}")
|
|
print(f" stdout: {stdout[:200]}")
|
|
print(f" stderr: {stderr[:200]}")
|
|
|
|
print("\n=== Test 4: Run with absolute path from different directory ===")
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
# Use absolute path to executable
|
|
abs_exe = os.path.abspath(exe_path)
|
|
stdout, stderr, code = run_mcrogueface(abs_exe, tmpdir)
|
|
if "TEST_SCRIPT_LOADED_FROM_PATH" in stdout:
|
|
print("✓ PASS: Script loaded with absolute exe path")
|
|
else:
|
|
print("✗ FAIL: Script not loaded with absolute exe path")
|
|
print(f" stdout: {stdout[:200]}")
|
|
print(f" stderr: {stderr[:200]}")
|
|
|
|
# Test 5: Symlink test (Unix only)
|
|
if not is_windows:
|
|
print("\n=== Test 5: Run via symlink (Unix only) ===")
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
symlink_path = os.path.join(tmpdir, "mcrogueface_link")
|
|
os.symlink(exe_path, symlink_path)
|
|
stdout, stderr, code = run_mcrogueface(symlink_path, tmpdir)
|
|
if "TEST_SCRIPT_LOADED_FROM_PATH" in stdout:
|
|
print("✓ PASS: Script loaded via symlink")
|
|
else:
|
|
print("✗ FAIL: Script not loaded via symlink")
|
|
print(f" stdout: {stdout[:200]}")
|
|
print(f" stderr: {stderr[:200]}")
|
|
|
|
# Summary
|
|
print("\n=== SUMMARY ===")
|
|
print("Issue #37 is about script loading failing when the executable")
|
|
print("is run from a different working directory than where it's located.")
|
|
print("The fix should resolve the script path relative to the executable,")
|
|
print("not the current working directory.")
|
|
|
|
finally:
|
|
# Restore original game.py
|
|
if os.path.exists(game_py_backup):
|
|
shutil.move(game_py_backup, game_py_path)
|
|
print("\nTest cleanup complete")
|
|
|
|
if __name__ == "__main__":
|
|
test_script_loading() |