Spaces:
Running
Running
File size: 4,316 Bytes
c262d1a |
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 |
#!/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() |