Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add get_graph_from_model_generative_test
  • Loading branch information
0xideas committed Nov 15, 2024
commit 370b59b39a70086b7a341e63340a8cc1cb23610e
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@pytest.mark.parametrize("recursive_depth", [1, 2, 3])
def test_extracted_car_type(recursive_depth):
def test_society_nodes_and_edges(recursive_depth):
society = create_organization_recursive(
"society", "Society", PERSON_NAMES, recursive_depth
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest

from cognee.modules.graph.utils import (
get_graph_from_model,
get_model_instance_from_graph,
)
from cognee.tests.unit.interfaces.graph.util import (
PERSON_NAMES,
create_organization_recursive,
show_first_difference,
)


@pytest.mark.parametrize("recursive_depth", [1, 2, 3])
def test_society_nodes_and_edges(recursive_depth):
society = create_organization_recursive(
"society", "Society", PERSON_NAMES, recursive_depth
)
nodes, edges = get_graph_from_model(society)
parsed_society = get_model_instance_from_graph(nodes, edges, "society")

assert str(society) == (str(parsed_society)), show_first_difference(
str(society), str(parsed_society), "society", "parsed_society"
)
19 changes: 19 additions & 0 deletions cognee/tests/unit/interfaces/graph/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,22 @@ def count_society(obj):
return (1, 0)
else:
raise Exception("Not allowed")


def show_first_difference(str1, str2, str1_name, str2_name, context=30):
"""Shows where two strings first diverge, with surrounding context."""
for i, (c1, c2) in enumerate(zip(str1, str2)):
if c1 != c2:
start = max(0, i - context)
end1 = min(len(str1), i + context + 1)
end2 = min(len(str2), i + context + 1)
if i > 0:
return f"identical: '{str1[start:i-1]}' | {str1_name}: '{str1[i-1:end1]}'... != {str2_name}: '{str2[i-1:end2]}'..."
else:
return f"{str1_name} and {str2_name} have no overlap in characters"
if len(str1) > len(str2):
return f"{str2_name} is identical up to the {i}th character, missing afterwards '{str1[i:i+context]}'..."
if len(str2) > len(str1):
return f"{str1_name} is identical up to the {i}th character, missing afterwards '{str2[i:i+context]}'..."
else:
return f"{str1_name} and {str2_name} are identical."