Files
semantica/tests/test_graph_store_methods.py
T
KaifAhmad1 58707ff721 fix(kg): resolve 'unhashable type: Entity' in GraphAnalyzer #159
- Robust ID extraction in CentralityCalculator, CommunityDetector, and ConnectivityAnalyzer
- Support for direct Entity objects and dictionaries as node identifiers
- Improved Entity hashability in utils/types.py
- Added integration test to verify fix and prevent regression
2026-01-08 17:23:31 +05:30

61 lines
2.0 KiB
Python

import unittest
from unittest.mock import MagicMock, patch
from semantica.graph_store import methods
from semantica.graph_store.registry import method_registry
class TestGraphStoreMethods(unittest.TestCase):
def setUp(self):
# Reset global store
methods._reset_store()
# Mock GraphStore
self.mock_store = MagicMock()
self.mock_store_patcher = patch('semantica.graph_store.methods.GraphStore', return_value=self.mock_store)
self.MockGraphStore = self.mock_store_patcher.start()
def tearDown(self):
self.mock_store_patcher.stop()
methods._reset_store()
# Unregister custom methods if any
method_registry.unregister("node", "custom_create")
def test_create_node_default(self):
# Setup
labels = ["Person"]
props = {"name": "Alice"}
self.mock_store.create_node.return_value = {"id": 1, "labels": labels, "properties": props}
# Execute
result = methods.create_node(labels, props)
# Verify
self.mock_store.create_node.assert_called_once_with(labels, props)
self.assertEqual(result["id"], 1)
def test_create_node_custom(self):
# Register custom method
mock_custom = MagicMock(return_value={"id": 99, "custom": True})
method_registry.register("node", "custom_create", mock_custom)
# Execute
result = methods.create_node(["Person"], {"name": "Bob"}, method="custom_create")
# Verify
mock_custom.assert_called_once()
self.mock_store.create_node.assert_not_called()
self.assertEqual(result["id"], 99)
def test_execute_query_default(self):
# Setup
query = "MATCH (n) RETURN n"
self.mock_store.execute_query.return_value = {"records": []}
# Execute
result = methods.execute_query(query)
# Verify
self.mock_store.execute_query.assert_called_once_with(query, None)
if __name__ == '__main__':
unittest.main()