Spaces:
Running
Running
#!/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() |