File size: 3,680 Bytes
26f8b9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""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)