make falkor tests optional
This commit is contained in:
parent
885d14c9f8
commit
7a8283dbac
2 changed files with 95 additions and 50 deletions
|
|
@ -15,18 +15,27 @@ limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import unittest
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from unittest.mock import AsyncMock, MagicMock, patch
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from graphiti_core.driver.falkordb_driver import FalkorDriver, FalkorDriverSession
|
|
||||||
from graphiti_core.helpers import DEFAULT_DATABASE
|
from graphiti_core.helpers import DEFAULT_DATABASE
|
||||||
|
|
||||||
|
try:
|
||||||
|
from graphiti_core.driver.falkordb_driver import FalkorDriver, FalkorDriverSession
|
||||||
|
|
||||||
|
HAS_FALKORDB = True
|
||||||
|
except ImportError:
|
||||||
|
FalkorDriver = None
|
||||||
|
HAS_FALKORDB = False
|
||||||
|
|
||||||
|
|
||||||
class TestFalkorDriver:
|
class TestFalkorDriver:
|
||||||
"""Comprehensive test suite for FalkorDB driver."""
|
"""Comprehensive test suite for FalkorDB driver."""
|
||||||
|
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
def setup_method(self):
|
def setup_method(self):
|
||||||
"""Set up test fixtures."""
|
"""Set up test fixtures."""
|
||||||
self.mock_client = MagicMock()
|
self.mock_client = MagicMock()
|
||||||
|
|
@ -34,6 +43,7 @@ class TestFalkorDriver:
|
||||||
self.driver = FalkorDriver()
|
self.driver = FalkorDriver()
|
||||||
self.driver.client = self.mock_client
|
self.driver.client = self.mock_client
|
||||||
|
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
def test_init_with_connection_params(self):
|
def test_init_with_connection_params(self):
|
||||||
"""Test initialization with connection parameters."""
|
"""Test initialization with connection parameters."""
|
||||||
with patch('graphiti_core.driver.falkordb_driver.FalkorDB') as mock_falkor_db:
|
with patch('graphiti_core.driver.falkordb_driver.FalkorDB') as mock_falkor_db:
|
||||||
|
|
@ -51,6 +61,7 @@ class TestFalkorDriver:
|
||||||
password='test-pass'
|
password='test-pass'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
def test_init_with_falkor_db_instance(self):
|
def test_init_with_falkor_db_instance(self):
|
||||||
"""Test initialization with a FalkorDB instance."""
|
"""Test initialization with a FalkorDB instance."""
|
||||||
with patch('graphiti_core.driver.falkordb_driver.FalkorDB') as mock_falkor_db_class:
|
with patch('graphiti_core.driver.falkordb_driver.FalkorDB') as mock_falkor_db_class:
|
||||||
|
|
@ -60,10 +71,12 @@ class TestFalkorDriver:
|
||||||
assert driver.client is mock_falkor_db
|
assert driver.client is mock_falkor_db
|
||||||
mock_falkor_db_class.assert_not_called()
|
mock_falkor_db_class.assert_not_called()
|
||||||
|
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
def test_provider(self):
|
def test_provider(self):
|
||||||
"""Test driver provider identification."""
|
"""Test driver provider identification."""
|
||||||
assert self.driver.provider == 'falkordb'
|
assert self.driver.provider == 'falkordb'
|
||||||
|
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
def test_get_graph_with_name(self):
|
def test_get_graph_with_name(self):
|
||||||
"""Test _get_graph with specific graph name."""
|
"""Test _get_graph with specific graph name."""
|
||||||
mock_graph = MagicMock()
|
mock_graph = MagicMock()
|
||||||
|
|
@ -74,6 +87,7 @@ class TestFalkorDriver:
|
||||||
self.mock_client.select_graph.assert_called_once_with('test_graph')
|
self.mock_client.select_graph.assert_called_once_with('test_graph')
|
||||||
assert result is mock_graph
|
assert result is mock_graph
|
||||||
|
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
def test_get_graph_with_none_defaults_to_default_database(self):
|
def test_get_graph_with_none_defaults_to_default_database(self):
|
||||||
"""Test _get_graph with None defaults to DEFAULT_DATABASE."""
|
"""Test _get_graph with None defaults to DEFAULT_DATABASE."""
|
||||||
mock_graph = MagicMock()
|
mock_graph = MagicMock()
|
||||||
|
|
@ -85,6 +99,7 @@ class TestFalkorDriver:
|
||||||
assert result is mock_graph
|
assert result is mock_graph
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_execute_query_success(self):
|
async def test_execute_query_success(self):
|
||||||
"""Test successful query execution."""
|
"""Test successful query execution."""
|
||||||
mock_graph = MagicMock()
|
mock_graph = MagicMock()
|
||||||
|
|
@ -112,6 +127,7 @@ class TestFalkorDriver:
|
||||||
assert summary is None
|
assert summary is None
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_execute_query_handles_index_already_exists_error(self):
|
async def test_execute_query_handles_index_already_exists_error(self):
|
||||||
"""Test handling of 'already indexed' error."""
|
"""Test handling of 'already indexed' error."""
|
||||||
mock_graph = MagicMock()
|
mock_graph = MagicMock()
|
||||||
|
|
@ -125,6 +141,7 @@ class TestFalkorDriver:
|
||||||
assert result is None
|
assert result is None
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_execute_query_propagates_other_exceptions(self):
|
async def test_execute_query_propagates_other_exceptions(self):
|
||||||
"""Test that other exceptions are properly propagated."""
|
"""Test that other exceptions are properly propagated."""
|
||||||
mock_graph = MagicMock()
|
mock_graph = MagicMock()
|
||||||
|
|
@ -138,6 +155,7 @@ class TestFalkorDriver:
|
||||||
mock_logger.error.assert_called_once()
|
mock_logger.error.assert_called_once()
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_execute_query_converts_datetime_parameters(self):
|
async def test_execute_query_converts_datetime_parameters(self):
|
||||||
"""Test that datetime objects in kwargs are converted to ISO strings."""
|
"""Test that datetime objects in kwargs are converted to ISO strings."""
|
||||||
mock_graph = MagicMock()
|
mock_graph = MagicMock()
|
||||||
|
|
@ -157,6 +175,7 @@ class TestFalkorDriver:
|
||||||
call_args = mock_graph.query.call_args[0]
|
call_args = mock_graph.query.call_args[0]
|
||||||
assert call_args[1]['created_at'] == test_datetime.isoformat()
|
assert call_args[1]['created_at'] == test_datetime.isoformat()
|
||||||
|
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
def test_session_creation(self):
|
def test_session_creation(self):
|
||||||
"""Test session creation with specific database."""
|
"""Test session creation with specific database."""
|
||||||
mock_graph = MagicMock()
|
mock_graph = MagicMock()
|
||||||
|
|
@ -168,6 +187,7 @@ class TestFalkorDriver:
|
||||||
assert session.graph is mock_graph
|
assert session.graph is mock_graph
|
||||||
self.mock_client.select_graph.assert_called_once_with('test_db')
|
self.mock_client.select_graph.assert_called_once_with('test_db')
|
||||||
|
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
def test_session_creation_with_none_uses_default_database(self):
|
def test_session_creation_with_none_uses_default_database(self):
|
||||||
"""Test session creation with None uses default database."""
|
"""Test session creation with None uses default database."""
|
||||||
mock_graph = MagicMock()
|
mock_graph = MagicMock()
|
||||||
|
|
@ -179,6 +199,7 @@ class TestFalkorDriver:
|
||||||
self.mock_client.select_graph.assert_called_once_with(DEFAULT_DATABASE)
|
self.mock_client.select_graph.assert_called_once_with(DEFAULT_DATABASE)
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_close_calls_connection_close(self):
|
async def test_close_calls_connection_close(self):
|
||||||
"""Test driver close method calls connection close."""
|
"""Test driver close method calls connection close."""
|
||||||
mock_connection = MagicMock()
|
mock_connection = MagicMock()
|
||||||
|
|
@ -193,7 +214,7 @@ class TestFalkorDriver:
|
||||||
# hasattr(self.client.connection, 'aclose') returns False
|
# hasattr(self.client.connection, 'aclose') returns False
|
||||||
# hasattr(self.client.connection, 'close') returns True
|
# hasattr(self.client.connection, 'close') returns True
|
||||||
mock_hasattr.side_effect = lambda obj, attr: (
|
mock_hasattr.side_effect = lambda obj, attr: (
|
||||||
attr == 'close' and obj is mock_connection
|
attr == 'close' and obj is mock_connection
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.driver.close()
|
await self.driver.close()
|
||||||
|
|
@ -201,6 +222,7 @@ class TestFalkorDriver:
|
||||||
mock_connection.close.assert_called_once()
|
mock_connection.close.assert_called_once()
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_delete_all_indexes(self):
|
async def test_delete_all_indexes(self):
|
||||||
"""Test delete_all_indexes method."""
|
"""Test delete_all_indexes method."""
|
||||||
with patch.object(self.driver, 'execute_query', new_callable=AsyncMock) as mock_execute:
|
with patch.object(self.driver, 'execute_query', new_callable=AsyncMock) as mock_execute:
|
||||||
|
|
@ -215,25 +237,30 @@ class TestFalkorDriver:
|
||||||
class TestFalkorDriverSession:
|
class TestFalkorDriverSession:
|
||||||
"""Test FalkorDB driver session functionality."""
|
"""Test FalkorDB driver session functionality."""
|
||||||
|
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
def setup_method(self):
|
def setup_method(self):
|
||||||
"""Set up test fixtures."""
|
"""Set up test fixtures."""
|
||||||
self.mock_graph = MagicMock()
|
self.mock_graph = MagicMock()
|
||||||
self.session = FalkorDriverSession(self.mock_graph)
|
self.session = FalkorDriverSession(self.mock_graph)
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_session_async_context_manager(self):
|
async def test_session_async_context_manager(self):
|
||||||
"""Test session can be used as async context manager."""
|
"""Test session can be used as async context manager."""
|
||||||
async with self.session as s:
|
async with self.session as s:
|
||||||
assert s is self.session
|
assert s is self.session
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_close_method(self):
|
async def test_close_method(self):
|
||||||
"""Test session close method doesn't raise exceptions."""
|
"""Test session close method doesn't raise exceptions."""
|
||||||
await self.session.close() # Should not raise
|
await self.session.close() # Should not raise
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_execute_write_passes_session_and_args(self):
|
async def test_execute_write_passes_session_and_args(self):
|
||||||
"""Test execute_write method passes session and arguments correctly."""
|
"""Test execute_write method passes session and arguments correctly."""
|
||||||
|
|
||||||
async def test_func(session, *args, **kwargs):
|
async def test_func(session, *args, **kwargs):
|
||||||
assert session is self.session
|
assert session is self.session
|
||||||
assert args == ('arg1', 'arg2')
|
assert args == ('arg1', 'arg2')
|
||||||
|
|
@ -246,6 +273,7 @@ class TestFalkorDriverSession:
|
||||||
assert result == 'result'
|
assert result == 'result'
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_run_single_query_with_parameters(self):
|
async def test_run_single_query_with_parameters(self):
|
||||||
"""Test running a single query with parameters."""
|
"""Test running a single query with parameters."""
|
||||||
self.mock_graph.query = AsyncMock()
|
self.mock_graph.query = AsyncMock()
|
||||||
|
|
@ -262,6 +290,7 @@ class TestFalkorDriverSession:
|
||||||
)
|
)
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_run_multiple_queries_as_list(self):
|
async def test_run_multiple_queries_as_list(self):
|
||||||
"""Test running multiple queries passed as list."""
|
"""Test running multiple queries passed as list."""
|
||||||
self.mock_graph.query = AsyncMock()
|
self.mock_graph.query = AsyncMock()
|
||||||
|
|
@ -279,6 +308,7 @@ class TestFalkorDriverSession:
|
||||||
assert calls[1][0] == ('CREATE (n:Node)', {'param2': 'value2'})
|
assert calls[1][0] == ('CREATE (n:Node)', {'param2': 'value2'})
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_run_converts_datetime_objects_to_iso_strings(self):
|
async def test_run_converts_datetime_objects_to_iso_strings(self):
|
||||||
"""Test that datetime objects are converted to ISO strings."""
|
"""Test that datetime objects are converted to ISO strings."""
|
||||||
self.mock_graph.query = AsyncMock()
|
self.mock_graph.query = AsyncMock()
|
||||||
|
|
@ -297,6 +327,7 @@ class TestFalkorDriverSession:
|
||||||
class TestDatetimeConversion:
|
class TestDatetimeConversion:
|
||||||
"""Test datetime conversion utility function."""
|
"""Test datetime conversion utility function."""
|
||||||
|
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
def test_convert_datetime_dict(self):
|
def test_convert_datetime_dict(self):
|
||||||
"""Test datetime conversion in nested dictionary."""
|
"""Test datetime conversion in nested dictionary."""
|
||||||
from graphiti_core.driver.falkordb_driver import convert_datetimes_to_strings
|
from graphiti_core.driver.falkordb_driver import convert_datetimes_to_strings
|
||||||
|
|
@ -318,6 +349,7 @@ class TestDatetimeConversion:
|
||||||
assert result['nested_dict']['nested_datetime'] == test_datetime.isoformat()
|
assert result['nested_dict']['nested_datetime'] == test_datetime.isoformat()
|
||||||
assert result['nested_dict']['nested_string'] == 'nested_test'
|
assert result['nested_dict']['nested_string'] == 'nested_test'
|
||||||
|
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
def test_convert_datetime_list_and_tuple(self):
|
def test_convert_datetime_list_and_tuple(self):
|
||||||
"""Test datetime conversion in lists and tuples."""
|
"""Test datetime conversion in lists and tuples."""
|
||||||
from graphiti_core.driver.falkordb_driver import convert_datetimes_to_strings
|
from graphiti_core.driver.falkordb_driver import convert_datetimes_to_strings
|
||||||
|
|
@ -338,6 +370,7 @@ class TestDatetimeConversion:
|
||||||
assert result_tuple[0] == 'test'
|
assert result_tuple[0] == 'test'
|
||||||
assert result_tuple[1] == test_datetime.isoformat()
|
assert result_tuple[1] == test_datetime.isoformat()
|
||||||
|
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
def test_convert_single_datetime(self):
|
def test_convert_single_datetime(self):
|
||||||
"""Test datetime conversion for single datetime object."""
|
"""Test datetime conversion for single datetime object."""
|
||||||
from graphiti_core.driver.falkordb_driver import convert_datetimes_to_strings
|
from graphiti_core.driver.falkordb_driver import convert_datetimes_to_strings
|
||||||
|
|
@ -346,6 +379,7 @@ class TestDatetimeConversion:
|
||||||
result = convert_datetimes_to_strings(test_datetime)
|
result = convert_datetimes_to_strings(test_datetime)
|
||||||
assert result == test_datetime.isoformat()
|
assert result == test_datetime.isoformat()
|
||||||
|
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
def test_convert_other_types_unchanged(self):
|
def test_convert_other_types_unchanged(self):
|
||||||
"""Test that non-datetime types are returned unchanged."""
|
"""Test that non-datetime types are returned unchanged."""
|
||||||
from graphiti_core.driver.falkordb_driver import convert_datetimes_to_strings
|
from graphiti_core.driver.falkordb_driver import convert_datetimes_to_strings
|
||||||
|
|
@ -362,6 +396,7 @@ class TestFalkorDriverIntegration:
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_basic_integration_with_real_falkordb(self):
|
async def test_basic_integration_with_real_falkordb(self):
|
||||||
"""Basic integration test with real FalkorDB instance."""
|
"""Basic integration test with real FalkorDB instance."""
|
||||||
pytest.importorskip('falkordb')
|
pytest.importorskip('falkordb')
|
||||||
|
|
|
||||||
|
|
@ -17,18 +17,26 @@ limitations under the License.
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import unittest
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
from graphiti_core.driver.falkordb_driver import FalkorDriver
|
|
||||||
from graphiti_core.edges import EntityEdge, EpisodicEdge
|
from graphiti_core.edges import EntityEdge, EpisodicEdge
|
||||||
from graphiti_core.graphiti import Graphiti
|
from graphiti_core.graphiti import Graphiti
|
||||||
from graphiti_core.helpers import semaphore_gather
|
from graphiti_core.helpers import semaphore_gather
|
||||||
from graphiti_core.nodes import EntityNode, EpisodicNode
|
from graphiti_core.nodes import EntityNode, EpisodicNode
|
||||||
from graphiti_core.search.search_helpers import search_results_to_context_string
|
from graphiti_core.search.search_helpers import search_results_to_context_string
|
||||||
|
|
||||||
|
try:
|
||||||
|
from graphiti_core.driver.falkordb_driver import FalkorDriver
|
||||||
|
|
||||||
|
HAS_FALKORDB = True
|
||||||
|
except ImportError:
|
||||||
|
FalkorDriver = None
|
||||||
|
HAS_FALKORDB = False
|
||||||
|
|
||||||
pytestmark = pytest.mark.integration
|
pytestmark = pytest.mark.integration
|
||||||
|
|
||||||
pytest_plugins = ('pytest_asyncio',)
|
pytest_plugins = ('pytest_asyncio',)
|
||||||
|
|
@ -63,6 +71,7 @@ def setup_logging():
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_graphiti_falkordb_init():
|
async def test_graphiti_falkordb_init():
|
||||||
logger = setup_logging()
|
logger = setup_logging()
|
||||||
|
|
||||||
|
|
@ -85,6 +94,7 @@ async def test_graphiti_falkordb_init():
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
@unittest.skipIf(not HAS_FALKORDB, "FalkorDB is not installed")
|
||||||
async def test_graph_falkordb_integration():
|
async def test_graph_falkordb_integration():
|
||||||
falkor_driver = FalkorDriver(
|
falkor_driver = FalkorDriver(
|
||||||
host=FALKORDB_HOST,
|
host=FALKORDB_HOST,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue