swadhin biswas Update on working process Β· 7/28/2025
f1cf876
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env python3
"""
Test script to verify the preview system NoneType error fix
"""
import asyncio
import sys
from pathlib import Path
# Add the laxyfile package to the path
sys.path.insert(0, str(Path(__file__).parent))
async def test_preview_system_error_handling():
"""Test that preview system handles file manager errors gracefully"""
print("π§ͺ Testing Preview System Error Handling...")
try:
from laxyfile.preview.preview_system import AdvancedPreviewSystem, PreviewConfig
from laxyfile.core.file_manager_service import FileManagerService
# Reset file manager service to simulate uninitialized state
FileManagerService.reset()
# Create preview system
config = PreviewConfig()
preview_system = AdvancedPreviewSystem(config)
# Initialize preview system
await preview_system.initialize()
print(" β
Preview system initialized successfully")
# Test preview generation with a file that exists
test_file = Path(__file__)
print(f" π Testing preview generation for: {test_file.name}")
# This should not crash even if file manager is not properly initialized
preview_result = await preview_system.generate_preview(test_file)
if preview_result.success:
print(f" β
Preview generated successfully: {len(preview_result.content)} characters")
else:
print(f" β οΈ Preview generation failed (expected): {preview_result.error_message}")
# Test with non-existent file
fake_file = Path("non_existent_file.txt")
print(f" π Testing preview generation for non-existent file: {fake_file.name}")
preview_result = await preview_system.generate_preview(fake_file)
if not preview_result.success:
print(f" β
Non-existent file handled gracefully: {preview_result.error_message}")
else:
print(f" β οΈ Unexpected success for non-existent file")
print(" β
Preview system error handling test completed successfully")
return True
except Exception as e:
print(f" β Preview system test failed: {e}")
import traceback
traceback.print_exc()
return False
async def test_enhanced_panels_error_handling():
"""Test that enhanced panels handle file manager errors gracefully"""
print("\nπ§ͺ Testing Enhanced Panels Error Handling...")
try:
from laxyfile.ui.enhanced_panels import EnhancedPanelRenderer
from laxyfile.ui.theme import ThemeManager
from laxyfile.core.config import Config
from rich.console import Console
# Create components
console = Console()
config = Config()
theme_manager = ThemeManager(config)
panel_renderer = EnhancedPanelRenderer(theme_manager, console)
print(" β
Enhanced panel renderer created successfully")
# Test preview panel rendering with no file
preview_panel = panel_renderer.render_preview_panel(None)
print(" β
Preview panel rendered successfully with no file")
# Test preview panel rendering with a file
test_file = Path(__file__)
preview_panel = panel_renderer.render_preview_panel(test_file, "Test content", "text")
print(" β
Preview panel rendered successfully with file")
print(" β
Enhanced panels error handling test completed successfully")
return True
except Exception as e:
print(f" β Enhanced panels test failed: {e}")
import traceback
traceback.print_exc()
return False
async def main():
"""Run all tests"""
print("π Starting LaxyFile Preview System Error Fix Tests\n")
test_results = []
# Test preview system
result1 = await test_preview_system_error_handling()
test_results.append(result1)
# Test enhanced panels
result2 = await test_enhanced_panels_error_handling()
test_results.append(result2)
# Summary
print(f"\nπ Test Results:")
print(f" β
Passed: {sum(test_results)}")
print(f" β Failed: {len(test_results) - sum(test_results)}")
if all(test_results):
print("\nπ All tests passed! Preview system error handling is working correctly.")
return 0
else:
print("\nπ₯ Some tests failed. Please check the error messages above.")
return 1
if __name__ == "__main__":
exit_code = asyncio.run(main())
sys.exit(exit_code)