Final_Assignment_Template / test_questions.py
mjschock's picture
Refactor main_v2.py to update task formatting for dual answer requests, enhancing response structure. Implement error handling for JSON parsing in agent results, ensuring robust output. Add unit tests in test_questions.py to validate succinct answer accuracy against expected values. Remove unused extract_final_answer utility from utils.py, streamlining the codebase.
2da6a11 unverified
raw
history blame
1.4 kB
import unittest
import requests
from main_v2 import main
class TestQuestions(unittest.TestCase):
def setUp(self):
self.api_url = "https://agents-course-unit4-scoring.hf.space"
self.questions_url = f"{self.api_url}/questions"
# Get questions from the API
response = requests.get(self.questions_url, timeout=15)
response.raise_for_status()
self.questions = response.json()
# Expected answers for each question
self.expected_answers = {
"How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.": "3",
# Add more expected answers as you verify them
}
def test_questions(self):
"""Test each question and verify the succinct answer matches the expected value."""
for question_data in self.questions:
question = question_data["question"]
if question in self.expected_answers:
expected_answer = self.expected_answers[question]
actual_answer = main(question)
self.assertEqual(
actual_answer,
expected_answer,
f"Question: {question}\nExpected: {expected_answer}\nGot: {actual_answer}"
)
if __name__ == "__main__":
unittest.main()