Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""
|
|
Test suite locking out ZeroDivisionError in RAGEvaluator.evaluate_response
|
|
when test_case contains empty expected_keywords or expected_analysis lists.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
|
|
|
|
from evaluate import RAGEvaluator
|
|
|
|
|
|
def test_evaluate_response_empty_expected_keywords():
|
|
"""
|
|
Ensure evaluate_response gracefully handles empty expected_keywords without raising ZeroDivisionError.
|
|
"""
|
|
evaluator = RAGEvaluator.__new__(RAGEvaluator)
|
|
test_case = {
|
|
"id": "tc1",
|
|
"question": "Sample query?",
|
|
"expected_keywords": []
|
|
}
|
|
result = evaluator.evaluate_response("Sample answer", test_case)
|
|
assert result["metrics"]["keyword_recall"] == 1.0
|
|
|
|
|
|
def test_evaluate_response_empty_expected_analysis():
|
|
"""
|
|
Ensure evaluate_response gracefully handles empty expected_analysis without raising ZeroDivisionError.
|
|
"""
|
|
evaluator = RAGEvaluator.__new__(RAGEvaluator)
|
|
test_case = {
|
|
"id": "tc2",
|
|
"question": "Sample query?",
|
|
"expected_analysis": []
|
|
}
|
|
result = evaluator.evaluate_response("Sample answer", test_case)
|
|
assert result["metrics"]["analysis_recall"] == 1.0
|