From dede5fa6fdc5c42e6ad36826c72f8c62d91eacae Mon Sep 17 00:00:00 2001 From: Daulet Amirkhanov Date: Wed, 15 Oct 2025 17:09:13 +0100 Subject: [PATCH] add unit tests for empty graph check on search --- cognee/tests/unit/api/test_search.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 cognee/tests/unit/api/test_search.py diff --git a/cognee/tests/unit/api/test_search.py b/cognee/tests/unit/api/test_search.py new file mode 100644 index 000000000..aff9e5d38 --- /dev/null +++ b/cognee/tests/unit/api/test_search.py @@ -0,0 +1,23 @@ +import pytest +import cognee +from cognee.modules.data.exceptions import SearchOnEmptyGraphError + + +@pytest.mark.asyncio +async def test_empty_search_raises_SearchOnEmptyGraphError_on_empty_graph(): + await cognee.prune.prune_data() + await cognee.prune.prune_system(metadata=True) + await cognee.add("Sample input") + with pytest.raises(SearchOnEmptyGraphError): + await cognee.search("Sample query") + + +async def test_empty_search_doesnt_raise_SearchOnEmptyGraphError(): + await cognee.prune.prune_data() + await cognee.prune.prune_system(metadata=True) + await cognee.add("Sample input") + await cognee.cognify() + try: + await cognee.search("Sample query") + except SearchOnEmptyGraphError: + pytest.fail("Should not raise SearchOnEmptyGraphError when data was added and cognified")