Files
wehub-resource-sync c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:02:24 +08:00

97 lines
2.4 KiB
Python

import pytest
from unittest.mock import patch, MagicMock
from cognee.eval_framework.eval_config import EvalConfig
import sys
with patch.dict(
sys.modules,
{
"deepeval": MagicMock(),
"deepeval.metrics": MagicMock(),
"deepeval.test_case": MagicMock(),
"cognee.eval_framework.evaluation.metrics.context_coverage": MagicMock(),
},
):
from cognee.eval_framework.evaluation.deep_eval_adapter import DeepEvalAdapter
@pytest.fixture
def adapter():
return DeepEvalAdapter()
@pytest.mark.asyncio
async def test_evaluate_answers_em_f1(adapter):
answers = [
{
"question": "What is 2 + 2?",
"answer": "4",
"golden_answer": "4",
"retrieval_context": "2 + 2 = 4",
}
]
evaluator_metrics = ["EM", "f1"]
results = await adapter.evaluate_answers(answers, evaluator_metrics)
assert len(results) == 1
assert "metrics" in results[0]
assert "EM" in results[0]["metrics"]
assert "f1" in results[0]["metrics"]
@pytest.mark.asyncio
async def test_unsupported_metric(adapter):
answers = [
{
"question": "What is 2 + 2?",
"answer": "4",
"golden_answer": "4",
}
]
evaluator_metrics = ["unsupported_metric"]
with pytest.raises(ValueError, match="Unsupported metric: unsupported_metric"):
await adapter.evaluate_answers(answers, evaluator_metrics)
@pytest.mark.asyncio
async def test_empty_answers_list(adapter):
results = await adapter.evaluate_answers([], ["EM", "f1"])
assert results == []
@pytest.mark.asyncio
async def test_missing_fields_in_answer(adapter):
answers = [
{
"question": "What is the capital of France?",
"answer": "Paris",
}
]
evaluator_metrics = ["EM", "f1"]
with pytest.raises(KeyError):
await adapter.evaluate_answers(answers, evaluator_metrics)
@pytest.mark.asyncio
async def test_none_values_in_answers(adapter):
answers = [
{
"question": None,
"answer": None,
"golden_answer": None,
"retrieval_context": None,
}
]
evaluator_metrics = ["EM", "f1"]
results = await adapter.evaluate_answers(answers, evaluator_metrics)
assert len(results) == 1
assert "metrics" in results[0]
assert "EM" in results[0]["metrics"]
assert "f1" in results[0]["metrics"]