"""Test script to verify Hunyuan3D error handling fix.""" from pathlib import Path from generators.hunyuan import HunyuanGenerator from core.config import QUALITY_PRESETS def test_result_parsing(): """Test different result format scenarios.""" generator = HunyuanGenerator() # Test 1: Empty tuple (should raise ValueError) print("\n[Test 1] Empty tuple...") try: result = () if isinstance(result, tuple): if len(result) == 0: raise ValueError("Empty result tuple from Hunyuan3D API") print("✅ Empty tuple handled correctly") except ValueError as e: print(f"✅ Caught expected error: {e}") # Test 2: Dict with 'value' key print("\n[Test 2] Dict with 'value' key...") result = ({'value': '/tmp/test.glb'},) file_data = result[0] if isinstance(file_data, dict): glb_path = file_data.get('value') print(f"✅ Extracted path: {glb_path}") # Test 3: Dict with 'path' key print("\n[Test 3] Dict with 'path' key...") result = ({'path': '/tmp/test2.glb'},) file_data = result[0] if isinstance(file_data, dict): glb_path = file_data.get('path') or file_data.get('value') print(f"✅ Extracted path: {glb_path}") # Test 4: Dict with 'name' key print("\n[Test 4] Dict with 'name' key...") result = ({'name': '/tmp/test3.glb'},) file_data = result[0] if isinstance(file_data, dict): glb_path = file_data.get('value') or file_data.get('path') or file_data.get('name') print(f"✅ Extracted path: {glb_path}") # Test 5: String result print("\n[Test 5] String result...") result = '/tmp/test4.glb' if isinstance(result, str): glb_path = result print(f"✅ Extracted path: {glb_path}") # Test 6: Unexpected dict format print("\n[Test 6] Unexpected dict format...") result = ({'unknown_key': '/tmp/test5.glb'},) file_data = result[0] if isinstance(file_data, dict): glb_path = file_data.get('value') or file_data.get('path') or file_data.get('name') or str(file_data) print(f"✅ Fallback to str(): {glb_path}") print("\n✅ All result parsing tests passed!") def test_error_messages(): """Test error message improvements.""" print("\n[Test Error Messages]") # Test 1: List index out of range print("\n[Test 1] List index out of range error...") try: raise ValueError("list index out of range") except Exception as e: if "list index out of range" in str(e): error_msg = ( f"Hunyuan3D API returned unexpected result format. " f"This usually means the generation failed on the server side. " f"Please try again with a different prompt or quality setting." ) print(f"✅ Error message: {error_msg}") # Test 2: Timeout error print("\n[Test 2] Timeout error...") try: raise TimeoutError("Request timeout") except Exception as e: if "timeout" in str(e).lower(): error_msg = ( f"Hunyuan3D generation timed out. " f"Try using a lower quality preset (Fast or Balanced)." ) print(f"✅ Error message: {error_msg}") print("\n✅ All error message tests passed!") if __name__ == "__main__": print("=" * 60) print("Testing Hunyuan3D Error Handling Fix") print("=" * 60) test_result_parsing() test_error_messages() print("\n" + "=" * 60) print("✅ All tests passed! Fix is working correctly.") print("=" * 60)