Skip to content

Commit e3423aa

Browse files
committed
Added basic tests of to_networkx and view. Added pytest mark called viz
1 parent dcd836d commit e3423aa

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

libs/langchain-mongodb/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ xfail_strict = true
6161
markers = [
6262
"requires: mark tests as requiring a specific library",
6363
"compile: mark placeholder test used to compile integration tests without running them",
64+
"viz: marks tests as requiring optional-dependency group `viz`",
6465
]
6566
asyncio_mode = "auto"
6667
asyncio_default_fixture_loop_scope = "function"

libs/langchain-mongodb/tests/integration_tests/test_graphrag.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from __future__ import annotations
22

33
import os
4-
from typing import Generator
4+
from typing import TYPE_CHECKING, Generator
55

66
import pytest
77
from langchain_core.documents import Document
88
from langchain_core.language_models.chat_models import BaseChatModel
9-
from langchain_core.messages import AIMessage
109
from langchain_openai import AzureChatOpenAI, ChatOpenAI
1110
from pymongo import MongoClient
1211
from pymongo.collection import Collection
@@ -17,6 +16,10 @@
1716

1817
from ..utils import CONNECTION_STRING, DB_NAME
1918

19+
if TYPE_CHECKING:
20+
pass
21+
22+
2023
COLLECTION_NAME = "langchain_test_graphrag"
2124

2225

@@ -303,3 +306,39 @@ def test_allowed_relationship_types(documents, entity_extraction_model):
303306
relationships.update(set(ent.get("relationships", {}).get("types", [])))
304307
assert relationships == {"partner"}
305308
store.close()
309+
310+
311+
@pytest.mark.viz
312+
def test_networkx(graph_store):
313+
"""Basic test that MongoDBGraphStore can be exported to NetworkX Graph.
314+
315+
See examples for self-contained Jupyter notebook example.
316+
To run: `pytest -m viz`
317+
"""
318+
try:
319+
import networkx as nx
320+
except ImportError:
321+
pytest.skip("This test requires optional-dependency `viz`")
322+
323+
nx_graph = graph_store.to_networkx()
324+
# assert nx_graph.number_of_nodes() == len(nx_graph.nodes)
325+
assert isinstance(nx_graph, nx.DiGraph)
326+
assert nx_graph.number_of_nodes() == graph_store.collection.count_documents({})
327+
assert nx_graph.number_of_edges() > 0
328+
329+
330+
@pytest.mark.viz
331+
def test_view(graph_store):
332+
"""Basic test that MongoDBGraphStore can be exported to NetworkX Graph.
333+
334+
See examples for self-contained Jupyter notebook example.
335+
To run: `pytest -m viz`
336+
"""
337+
try:
338+
import holoviews as hv
339+
except ImportError:
340+
pytest.skip("This test requires optional-dependency `viz`")
341+
342+
view = graph_store.view()
343+
assert isinstance(view, hv.Overlay)
344+
assert len(view) == 2

0 commit comments

Comments
 (0)