prole/tests/test_resource_paths.py

83 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python3
"""Test that resource paths work correctly."""
import sys
from pathlib import Path
# Add current directory to path
sys.path.insert(0, str(Path.cwd()))
from install import get_resource_path
def test_resource_path():
"""Test get_resource_path function."""
print("Testing get_resource_path() function:")
print()
test_cases = [
("img/proleIcon.png", "App icon"),
("img/proleLogoSepia.png", "Background logo (sepia)"),
("img/proleLogo.png", "Main logo"),
("img/proleLogoBlueprint.png", "Blueprint logo"),
("img/proleIconblueprint.png", "Blueprint icon"),
]
all_passed = True
for rel_path, description in test_cases:
result = get_resource_path(rel_path)
exists = result.exists()
status = "" if exists else ""
print(f"{status} {description}")
print(f" Path: {rel_path}")
print(f" Resolved: {result}")
print(f" Exists: {exists}")
print()
if not exists:
all_passed = False
return all_passed
def test_pyinstaller_simulation():
"""Simulate PyInstaller environment."""
print("Simulating PyInstaller environment:")
print()
# Temporarily set _MEIPASS to simulate PyInstaller
test_meipass = Path.cwd()
sys._MEIPASS = str(test_meipass)
try:
result = get_resource_path("img/proleIcon.png")
print(f" sys._MEIPASS: {sys._MEIPASS}")
print(f" Resolved path: {result}")
print(f" Exists: {result.exists()}")
print()
return result.exists()
finally:
# Clean up
delattr(sys, "_MEIPASS")
if __name__ == "__main__":
print("=" * 60)
print("Resource Path Tests")
print("=" * 60)
print()
test1 = test_resource_path()
test2 = test_pyinstaller_simulation()
print("=" * 60)
if test1 and test2:
print("✓ All tests passed!")
print()
print("Images will be correctly included in PyInstaller build.")
sys.exit(0)
else:
print("✗ Some tests failed!")
sys.exit(1)