37 lines
1.6 KiB
Python
37 lines
1.6 KiB
Python
import copy
|
|
import pytest
|
|
|
|
from tools.answer_evaluation.rag_delivery import finalize_rag_answer
|
|
|
|
|
|
def test_notice_is_rendered_without_changing_facts_or_raw_answer():
|
|
original = {'answer': 'Eva má prácu z roku 2026.', 'context_issues': ['missing_incompleteness_notice'],
|
|
'citations_ok': True, 'accepted_for_delivery': False}
|
|
before = copy.deepcopy(original)
|
|
out = finalize_rag_answer(original)
|
|
assert original == before
|
|
assert out['model_answer'] == before['answer']
|
|
assert out['answer'] == 'Výpis je neúplný.\n\n' + before['answer']
|
|
assert out['accepted_for_delivery'] and out['display_notice_added']
|
|
assert not out['first_pass_accepted_for_delivery']
|
|
assert finalize_rag_answer(out) == out
|
|
|
|
|
|
@pytest.mark.parametrize('issues,citations_ok', [
|
|
(['unsupported_exhaustive_statement', 'missing_incompleteness_notice'], True),
|
|
(['missing_incompleteness_notice'], False),
|
|
([], False)])
|
|
def test_notice_never_bypasses_other_rejections(issues, citations_ok):
|
|
original = {'answer': 'Úplný zoznam.', 'context_issues': issues,
|
|
'citations_ok': citations_ok, 'accepted_for_delivery': False}
|
|
out = finalize_rag_answer(original)
|
|
assert not out['accepted_for_delivery'] and not out['display_notice_added']
|
|
assert out['answer'] == original['answer']
|
|
|
|
|
|
def test_complete_valid_answer_does_not_get_a_notice():
|
|
original = {'answer': 'Eva.', 'context_issues': [], 'citations_ok': True, 'accepted_for_delivery': True}
|
|
out = finalize_rag_answer(original)
|
|
assert out['answer'] == original['answer'] and not out['display_notice_added']
|
|
assert out['accepted_for_delivery']
|