153 lines
4.0 KiB
Python
153 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script for YouTube TUI
|
|
"""
|
|
|
|
from youtube_tui.app import YouTubeTUI
|
|
|
|
|
|
def test_imports():
|
|
"""Test that all imports work correctly"""
|
|
try:
|
|
print("✓ App imported successfully")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"✗ Import failed: {e}")
|
|
return False
|
|
|
|
|
|
def test_app_creation():
|
|
"""Test that the app can be created"""
|
|
try:
|
|
app = YouTubeTUI()
|
|
print("✓ YouTubeTUI created successfully")
|
|
print(f" - App version: {app.VERSION}")
|
|
print(f" - yt-dlp version: {app.yt_dlp_version}")
|
|
print(f" - Search history loaded: {len(app.search_history)} items")
|
|
return True
|
|
except Exception as e:
|
|
print(f"✗ App creation failed: {e}")
|
|
return False
|
|
|
|
|
|
def test_video_model():
|
|
"""Test the Video model"""
|
|
try:
|
|
from youtube_tui.models.video import Video
|
|
|
|
video = Video(
|
|
video_id="dQw4w9WgXcQ",
|
|
title="Test Video",
|
|
channel="Test Channel",
|
|
channel_id="UC123",
|
|
duration="3:45",
|
|
view_count="1000000",
|
|
upload_date="20230101",
|
|
description="Test description",
|
|
)
|
|
|
|
print("✓ Video model created successfully")
|
|
print(f" - Video ID: {video.video_id}")
|
|
print(f" - Title: {video.title}")
|
|
print(f" - Display title: {video.display_title}")
|
|
print(f" - Duration: {video.duration}")
|
|
print(f" - URL: {video.url}")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"✗ Video model test failed: {e}")
|
|
return False
|
|
|
|
|
|
def test_search_history():
|
|
"""Test search history functionality"""
|
|
try:
|
|
app = YouTubeTUI()
|
|
|
|
# Test adding to history
|
|
app.add_to_search_history("test search 1")
|
|
app.add_to_search_history("test search 2")
|
|
|
|
print("✓ Search history operations successful")
|
|
print(f" - History items: {len(app.search_history)}")
|
|
|
|
# Test that duplicates are removed
|
|
app.add_to_search_history("test search 1")
|
|
print(f" - After duplicate: {len(app.search_history)} items")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"✗ Search history test failed: {e}")
|
|
return False
|
|
|
|
|
|
def test_video_from_dict():
|
|
"""Test Video model from_dict method"""
|
|
try:
|
|
from youtube_tui.models.video import Video
|
|
|
|
data = {
|
|
"video_id": "abc123",
|
|
"title": "Test Video",
|
|
"channel": "Test Channel",
|
|
"channel_id": "UC123",
|
|
"duration": "5:30",
|
|
"view_count": "500000",
|
|
"upload_date": "20230101",
|
|
"description": "Test description",
|
|
}
|
|
|
|
video = Video.from_dict(data)
|
|
|
|
print("✓ Video.from_dict() works correctly")
|
|
print(f" - Video ID: {video.video_id}")
|
|
print(f" - Title: {video.title}")
|
|
|
|
# Test to_dict
|
|
video_dict = video.to_dict()
|
|
print(f" - to_dict() keys: {list(video_dict.keys())}")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"✗ Video from_dict test failed: {e}")
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("=" * 60)
|
|
print("YouTube TUI Test Suite")
|
|
print("=" * 60)
|
|
print()
|
|
|
|
tests = [
|
|
("Imports", test_imports),
|
|
("App Creation", test_app_creation),
|
|
("Video Model", test_video_model),
|
|
("Search History", test_search_history),
|
|
("Video from Dict", test_video_from_dict),
|
|
]
|
|
|
|
results = []
|
|
for name, test_func in tests:
|
|
print(f"\nTesting: {name}")
|
|
print("-" * 40)
|
|
result = test_func()
|
|
results.append((name, result))
|
|
print()
|
|
|
|
print("=" * 60)
|
|
print("Test Results Summary")
|
|
print("=" * 60)
|
|
|
|
passed = sum(1 for _, r in results if r)
|
|
total = len(results)
|
|
|
|
for name, result in results:
|
|
status = "✓ PASS" if result else "✗ FAIL"
|
|
print(f"{status}: {name}")
|
|
|
|
print()
|
|
print(f"Total: {passed}/{total} tests passed")
|
|
print("=" * 60)
|