Skip to content

Commit d1f825e

Browse files
committed
Combined into one test
1 parent 8bed2ff commit d1f825e

File tree

1 file changed

+12
-34
lines changed

1 file changed

+12
-34
lines changed

libs/langgraph-checkpoint-mongodb/tests/integration_tests/test_highlevel_graph.py

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from collections.abc import Generator
1919
from typing import Annotated, TypedDict
2020

21-
import langchain_core
2221
import pytest
2322

2423
from langgraph.checkpoint.base import BaseCheckpointSaver
@@ -63,10 +62,12 @@ def generate(state: JokeInput):
6362
return {"jokes": [f"Joke about the year {state['subject']}"]}
6463

6564
def bump(state: JokeOutput):
66-
return {"jokes": [state["jokes"][0] + " and another"]}
65+
return {"jokes": [state["jokes"][0] + " and the year before"]}
6766

6867
def bump_loop(state: JokeOutput):
69-
return END if state["jokes"][0].endswith(" and another" * 10) else "bump"
68+
return (
69+
END if state["jokes"][0].endswith(" and the year before" * 10) else "bump"
70+
)
7071

7172
subgraph = StateGraph(JokeState, joke_subjects=JokeInput, output=JokeOutput)
7273
subgraph.add_node("edit", edit)
@@ -139,49 +140,26 @@ def disable_langsmith():
139140
os.environ["LANGCHAIN_API_KEY"] = ""
140141

141142

142-
def test_sync(
143-
joke_subjects,
144-
checkpointer_mongodb,
145-
checkpointer_memory,
143+
async def test_fanout(
144+
joke_subjects, checkpointer_mongodb, checkpointer_mongodb_async, checkpointer_memory
146145
) -> None:
147146
checkpointers = {
148147
"mongodb": checkpointer_mongodb,
149-
"in_memory": checkpointer_memory,
150-
}
151-
152-
print("\n\nBegin test_sync")
153-
for cname, checkpointer in checkpointers.items():
154-
assert isinstance(checkpointer, BaseCheckpointSaver)
155-
156-
graphc = fanout_to_subgraph().compile(checkpointer=checkpointer)
157-
assert isinstance(graphc.get_graph(), langchain_core.runnables.graph.Graph)
158-
config = {"configurable": {"thread_id": cname}}
159-
start = time.monotonic()
160-
out = [c for c in graphc.stream(joke_subjects, config=config)]
161-
assert len(out) == N_SUBJECTS
162-
assert isinstance(out[0], dict)
163-
assert out[0].keys() == {"generate_joke"}
164-
assert set(out[0]["generate_joke"].keys()) == {"jokes"}
165-
end = time.monotonic()
166-
print(f"{cname}: {end - start:.4f} seconds")
167-
168-
169-
async def test_async(
170-
joke_subjects, checkpointer_mongodb_async, checkpointer_memory
171-
) -> None:
172-
checkpointers = {
173148
"mongodb_async": checkpointer_mongodb_async,
149+
"in_memory": checkpointer_memory,
174150
"in_memory_async": checkpointer_memory,
175151
}
176152

177-
print("\n\nBegin test_async")
178153
for cname, checkpointer in checkpointers.items():
179154
assert isinstance(checkpointer, BaseCheckpointSaver)
180-
155+
print(f"\n\nBegin test of {cname}")
181156
graphc = (fanout_to_subgraph()).compile(checkpointer=checkpointer)
182157
config = {"configurable": {"thread_id": cname}}
183158
start = time.monotonic()
184-
out = [c async for c in graphc.astream(joke_subjects, config=config)]
159+
if "async" in cname:
160+
out = [c async for c in graphc.astream(joke_subjects, config=config)]
161+
else:
162+
out = [c for c in graphc.stream(joke_subjects, config=config)]
185163
assert len(out) == N_SUBJECTS
186164
assert isinstance(out[0], dict)
187165
assert out[0].keys() == {"generate_joke"}

0 commit comments

Comments
 (0)