Files
Text-Texture-Generator-for-…/test_ui_and_compatibility.py
2025-08-11 12:48:35 +07:00

231 lines
9.5 KiB
Python

#!/usr/bin/env python3
"""
Advanced UI Integration and Backward Compatibility Test Suite
for the Text Texture Generator's enhanced positioning system.
This focuses on potential issues that the basic positioning tests might miss.
"""
import sys
import re
class UICompatibilityTestSuite:
"""Test suite focused on UI integration and compatibility issues"""
def __init__(self):
self.issues_found = []
self.warnings = []
def analyze_ui_layout_structure(self):
"""Analyze the UI layout structure from the addon code"""
print("\n=== Analyzing UI Layout Structure ===")
# Read the addon code to analyze UI structure
try:
with open('__init__.py', 'r') as f:
addon_code = f.read()
except FileNotFoundError:
self.issues_found.append("❌ Cannot read __init__.py for UI analysis")
return
# Check for Positioning & Alignment section
if "Positioning & Alignment" in addon_code:
print("'Positioning & Alignment' section found in UI")
else:
self.issues_found.append("'Positioning & Alignment' section not found in UI")
# Check for position mode toggle
if 'position_mode' in addon_code and 'PRESET' in addon_code and 'MANUAL' in addon_code:
print("✅ Position mode toggle implementation found")
else:
self.issues_found.append("❌ Position mode toggle not properly implemented")
# Check for 3x3 anchor grid implementation
anchor_grid_patterns = [
r'get_anchor_point_matrix\(\)',
r'for.*anchor.*in.*matrix',
r'grid_row.*=.*position_col\.row'
]
grid_found = all(re.search(pattern, addon_code, re.DOTALL) for pattern in anchor_grid_patterns)
if grid_found:
print("✅ 3x3 anchor grid UI implementation found")
else:
self.issues_found.append("❌ 3x3 anchor grid UI implementation incomplete")
# Check for margin controls with link functionality
if 'margins_linked' in addon_code and 'LINKED' in addon_code and 'UNLINKED' in addon_code:
print("✅ Margin link/unlink controls found")
else:
self.issues_found.append("❌ Margin link/unlink controls not properly implemented")
# Check for conditional UI visibility
if 'position_mode == ' in addon_code:
print("✅ Conditional UI visibility based on position mode found")
else:
self.warnings.append("⚠️ No conditional UI visibility found - controls might always be visible")
def test_backward_compatibility_integration(self):
"""Test how the new system integrates with existing text_align property"""
print("\n=== Testing Backward Compatibility Integration ===")
try:
with open('__init__.py', 'r') as f:
addon_code = f.read()
except FileNotFoundError:
self.issues_found.append("❌ Cannot read addon code for compatibility analysis")
return
# Find the backward compatibility section in generate_texture_image
compat_section = re.search(
r'# Apply legacy text_align.*?props\.anchor_point == \'MIDDLE_CENTER\'.*?# Apply offsets even in legacy mode',
addon_code, re.DOTALL
)
if compat_section:
print("✅ Backward compatibility section found in texture generation")
# Check if all text_align values are handled
compat_code = compat_section.group(0)
align_values = ['left', 'center', 'right']
missing_aligns = []
for align in align_values:
if f"text_align == '{align}'" not in compat_code:
missing_aligns.append(align)
if missing_aligns:
self.issues_found.append(f"❌ Missing text_align compatibility for: {missing_aligns}")
else:
print("✅ All text_align values have compatibility handling")
# Check if legacy mode only applies to MIDDLE_CENTER
if "anchor_point == 'MIDDLE_CENTER'" in compat_code:
print("✅ Legacy compatibility properly scoped to MIDDLE_CENTER anchor")
else:
self.issues_found.append("❌ Legacy compatibility scope issue - should only apply to MIDDLE_CENTER")
else:
self.issues_found.append("❌ Backward compatibility section not found in texture generation")
# Check if text_align property is still defined
if re.search(r'text_align.*EnumProperty', addon_code):
print("✅ Legacy text_align property still defined")
else:
self.issues_found.append("❌ Legacy text_align property not found - breaking change!")
def analyze_property_update_chains(self):
"""Analyze property update chains for consistency"""
print("\n=== Analyzing Property Update Chains ===")
try:
with open('__init__.py', 'r') as f:
addon_code = f.read()
except FileNotFoundError:
self.issues_found.append("❌ Cannot read addon code for update chain analysis")
return
# Find all properties with update=update_live_preview
update_properties = re.findall(r'(\w+):\s*\w+Property.*?update=update_live_preview', addon_code, re.DOTALL)
expected_positioning_props = [
'anchor_point', 'position_mode', 'margin_x', 'margin_y',
'margins_linked', 'offset_x', 'offset_y', 'manual_position_x',
'manual_position_y', 'manual_position_unit', 'constrain_to_canvas'
]
missing_updates = []
for prop in expected_positioning_props:
if prop not in update_properties:
missing_updates.append(prop)
if missing_updates:
self.issues_found.append(f"❌ Properties missing live preview updates: {missing_updates}")
else:
print("✅ All positioning properties have live preview updates")
# Check for visual feedback properties
visual_props = ['show_position_guides', 'show_text_bounds', 'show_canvas_grid']
missing_visual_updates = []
for prop in visual_props:
if prop not in update_properties:
missing_visual_updates.append(prop)
if missing_visual_updates:
self.issues_found.append(f"❌ Visual feedback properties missing updates: {missing_visual_updates}")
else:
print("✅ All visual feedback properties have live preview updates")
def run_compatibility_tests(self):
"""Run all compatibility and UI integration tests"""
print("🔍 UI INTEGRATION & COMPATIBILITY TEST SUITE")
print("=" * 55)
try:
self.analyze_ui_layout_structure()
self.test_backward_compatibility_integration()
self.analyze_property_update_chains()
except Exception as e:
print(f"❌ Critical error during compatibility testing: {e}")
import traceback
traceback.print_exc()
self.generate_compatibility_report()
def generate_compatibility_report(self):
"""Generate compatibility and UI integration report"""
print("\n" + "=" * 60)
print("📊 UI INTEGRATION & COMPATIBILITY REPORT")
print("=" * 60)
total_issues = len(self.issues_found)
total_warnings = len(self.warnings)
print(f"📈 SUMMARY:")
print(f" 🚨 Critical Issues: {total_issues}")
print(f" ⚠️ Warnings: {total_warnings}")
if self.issues_found:
print(f"\n🚨 CRITICAL ISSUES FOUND ({total_issues}):")
for issue in self.issues_found:
print(f" {issue}")
if self.warnings:
print(f"\n⚠️ WARNINGS ({total_warnings}):")
for warning in self.warnings:
print(f" {warning}")
if not self.issues_found and not self.warnings:
print("\n🎉 NO CRITICAL ISSUES OR WARNINGS FOUND!")
print(" The UI integration and compatibility appear to be well implemented.")
# Recommendations based on findings
print(f"\n🎯 RECOMMENDATIONS:")
if total_issues > 0:
print(" 1. 🚨 Address all critical issues before deployment")
print(" 2. Test UI elements thoroughly in actual Blender environment")
if total_warnings > 0:
print(" 3. ⚠️ Review and address warnings for robustness")
print(" 4. Add explicit error handling for edge cases")
print(" 5. ✅ Add automated UI tests to prevent regressions")
print(" 6. ✅ Test backward compatibility with existing presets")
print(" 7. ✅ Validate all property ranges in actual use cases")
return {
'critical_issues': total_issues,
'warnings': total_warnings,
'issues_list': self.issues_found,
'warnings_list': self.warnings
}
if __name__ == "__main__":
print("🚀 Starting UI Integration & Compatibility Test Suite...")
test_suite = UICompatibilityTestSuite()
results = test_suite.run_compatibility_tests()
print(f"\n✨ UI & Compatibility testing completed!")