Spaces:
TDN-M
/
Running on Zero

Voff / test_sports_news.py
TDN-M's picture
ffff
36d7d16
#!/usr/bin/env python3
"""
Test script cho tính năng tin thể thao
Kiểm tra việc lấy tin từ các nguồn RSS
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from sports_news import get_sports_news_content, SportsNewsAggregator
import asyncio
def test_basic_functionality():
"""Test cơ bản cho tính năng tin thể thao"""
print("🏃‍♂️ Testing Sports News Functionality...")
print("=" * 50)
try:
# Test lấy tin thể thao tiếng Việt
print("📰 Testing Vietnamese sports news...")
vi_content = get_sports_news_content('all', 'vi', 3)
print("Vietnamese Content:")
print(vi_content[:500] + "..." if len(vi_content) > 500 else vi_content)
print("\n" + "-" * 30 + "\n")
# Test lấy tin bóng đá
print("⚽ Testing football news...")
football_content = get_sports_news_content('football', 'vi', 2)
print("Football Content:")
print(football_content[:500] + "..." if len(football_content) > 500 else football_content)
print("\n" + "-" * 30 + "\n")
# Test lấy tin tiếng Anh
print("🌍 Testing English sports news...")
en_content = get_sports_news_content('all', 'en', 2)
print("English Content:")
print(en_content[:500] + "..." if len(en_content) > 500 else en_content)
print("\n" + "-" * 30 + "\n")
print("✅ All tests completed successfully!")
return True
except Exception as e:
print(f"❌ Error during testing: {str(e)}")
return False
def test_aggregator_directly():
"""Test trực tiếp SportsNewsAggregator class"""
print("🔧 Testing SportsNewsAggregator directly...")
print("=" * 50)
try:
aggregator = SportsNewsAggregator()
# Test lấy tin từ một nguồn cụ thể
print("📡 Testing individual RSS sources...")
# Test với VnExpress
vnexpress_config = {
'url': 'https://vnexpress.net/rss/the-thao.rss',
'type': 'rss',
'language': 'vi',
'name': 'vnexpress_sport'
}
news_items = aggregator.get_rss_news(vnexpress_config)
print(f"VnExpress Sports: Found {len(news_items)} articles")
if news_items:
print("Sample article:")
print(f"Title: {news_items[0]['title']}")
print(f"Summary: {news_items[0]['summary'][:200]}...")
print("\n" + "-" * 30 + "\n")
# Test format cho TTS
print("🎤 Testing TTS formatting...")
formatted = aggregator.format_news_for_tts(news_items[:2], 'vi')
print("Formatted for TTS:")
print(formatted[:300] + "..." if len(formatted) > 300 else formatted)
print("✅ Aggregator test completed successfully!")
return True
except Exception as e:
print(f"❌ Error during aggregator testing: {str(e)}")
import traceback
traceback.print_exc()
return False
def main():
"""Chạy tất cả các test"""
print("🚀 Starting Sports News Tests...")
print("=" * 60)
# Test cơ bản
basic_success = test_basic_functionality()
print("\n" + "=" * 60 + "\n")
# Test aggregator
aggregator_success = test_aggregator_directly()
print("\n" + "=" * 60)
print("📊 TEST SUMMARY:")
print(f"Basic functionality: {'✅ PASS' if basic_success else '❌ FAIL'}")
print(f"Aggregator test: {'✅ PASS' if aggregator_success else '❌ FAIL'}")
if basic_success and aggregator_success:
print("🎉 All tests passed! Sports news feature is ready to use.")
else:
print("⚠️ Some tests failed. Please check the errors above.")
if __name__ == "__main__":
main()