Final_Assignment / tests /test_web_loader.py
GAIA Developer
πŸ§ͺ Add comprehensive test infrastructure and async testing system
c262d1a
#!/usr/bin/env python3
"""
Test script for GAIAQuestionLoaderWeb
"""
from gaia_web_loader import GAIAQuestionLoaderWeb
def test_web_loader():
"""Test the GAIA web question loader functionality"""
print("🌐 Testing GAIAQuestionLoaderWeb")
print("=" * 50)
# Initialize web loader
loader = GAIAQuestionLoaderWeb()
# Test API connection first
print("\nπŸ”Œ Testing API Connection:")
if loader.test_api_connection():
print(" βœ… API connection successful")
else:
print(" ❌ API connection failed")
print(" Note: This might be expected if the API is not available")
# Test basic functionality
print("\nπŸ“Š Web Loader Summary:")
summary = loader.summary()
for key, value in summary.items():
print(f" {key}: {value}")
if not loader.questions:
print("\n⚠️ No questions loaded from web API")
print(" This might be expected if:")
print(" - API is not available")
print(" - Network connection issues")
print(" - API endpoint has changed")
return
# Test random question
print("\n🎲 Random Question from Web:")
random_q = loader.get_random_question()
if random_q:
print(f" Task ID: {random_q.get('task_id', 'N/A')}")
print(f" Question: {random_q.get('question', 'N/A')[:100]}...")
print(f" Has file: {'Yes' if random_q.get('file_name') else 'No'}")
print(f" Level: {random_q.get('Level', 'Unknown')}")
# Test questions with files
print("\nπŸ“Ž Questions with Files:")
with_files = loader.get_questions_with_files()
print(f" Found {len(with_files)} questions with files")
for q in with_files[:3]: # Show first 3
print(f" - {q.get('task_id', 'N/A')}: {q.get('file_name', 'N/A')}")
# Test questions without files
print("\nπŸ“ Questions without Files:")
without_files = loader.get_questions_without_files()
print(f" Found {len(without_files)} questions without files")
for q in without_files[:3]: # Show first 3
print(f" - {q.get('task_id', 'N/A')}: {q.get('question', 'N/A')[:50]}...")
# Test by level
print("\nπŸ“ˆ Questions by Level:")
by_level = loader.count_by_level()
for level, count in by_level.items():
print(f" Level {level}: {count} questions")
# Test specific question lookup
print("\nπŸ” Test Question Lookup:")
if loader.questions:
test_id = loader.questions[0].get('task_id', 'N/A')
found_q = loader.get_question_by_id(test_id)
if found_q:
print(f" βœ… Successfully found question by ID: {test_id}")
else:
print(f" ❌ Failed to find question by ID: {test_id}")
print("\nβœ… GAIAQuestionLoaderWeb test completed!")
def compare_loaders():
"""Compare local file loader vs web loader"""
print("\nπŸ”„ Comparing Local vs Web Loaders")
print("=" * 50)
try:
from gaia_loader import GAIAQuestionLoader
print("Loading from local file...")
local_loader = GAIAQuestionLoader()
print("Loading from web API...")
web_loader = GAIAQuestionLoaderWeb()
print(f"\nComparison:")
print(f" Local questions: {len(local_loader.questions)}")
print(f" Web questions: {len(web_loader.questions)}")
if local_loader.questions and web_loader.questions:
local_ids = {q.get('task_id') for q in local_loader.questions}
web_ids = {q.get('task_id') for q in web_loader.questions}
common = local_ids.intersection(web_ids)
only_local = local_ids - web_ids
only_web = web_ids - local_ids
print(f" Common questions: {len(common)}")
print(f" Only in local: {len(only_local)}")
print(f" Only in web: {len(only_web)}")
if only_web:
print(f" New questions from web: {list(only_web)[:3]}")
except ImportError:
print(" ❌ Local loader not available for comparison")
except Exception as e:
print(f" ❌ Comparison failed: {e}")
if __name__ == "__main__":
test_web_loader()
compare_loaders()