From 430df0db15c0220393221531b30854d659d3fbb3 Mon Sep 17 00:00:00 2001 From: hajdul88 <52442977+hajdul88@users.noreply.github.com> Date: Thu, 11 Dec 2025 12:13:51 +0100 Subject: [PATCH] feat: adds 100 cov to cot --- .../graph_completion_retriever_cot_test.py | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py b/cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py index b581f14d7..9f3147512 100644 --- a/cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py +++ b/cognee/tests/unit/modules/retrieval/graph_completion_retriever_cot_test.py @@ -2,7 +2,10 @@ import pytest from unittest.mock import AsyncMock, patch, MagicMock from uuid import UUID -from cognee.modules.retrieval.graph_completion_cot_retriever import GraphCompletionCotRetriever +from cognee.modules.retrieval.graph_completion_cot_retriever import ( + GraphCompletionCotRetriever, + _as_answer_text, +) from cognee.modules.graph.cognee_graph.CogneeGraphElements import Edge from cognee.infrastructure.llm.LLMGateway import LLMGateway @@ -639,3 +642,47 @@ async def test_get_completion_with_save_interaction_no_context(mock_edge): assert isinstance(completion, list) assert len(completion) == 1 + + +@pytest.mark.asyncio +async def test_as_answer_text_with_typeerror(): + """Test _as_answer_text handles TypeError when json.dumps fails.""" + non_serializable = {1, 2, 3} + + result = _as_answer_text(non_serializable) + + assert isinstance(result, str) + assert result == str(non_serializable) + + +@pytest.mark.asyncio +async def test_as_answer_text_with_string(): + """Test _as_answer_text with string input.""" + result = _as_answer_text("test string") + assert result == "test string" + + +@pytest.mark.asyncio +async def test_as_answer_text_with_dict(): + """Test _as_answer_text with dictionary input.""" + test_dict = {"key": "value", "number": 42} + result = _as_answer_text(test_dict) + assert isinstance(result, str) + assert "key" in result + assert "value" in result + + +@pytest.mark.asyncio +async def test_as_answer_text_with_basemodel(): + """Test _as_answer_text with Pydantic BaseModel input.""" + from pydantic import BaseModel + + class TestModel(BaseModel): + answer: str + + test_model = TestModel(answer="test answer") + result = _as_answer_text(test_model) + + assert isinstance(result, str) + assert "[Structured Response]" in result + assert "test answer" in result