Skip to content

Commit 9b17b34

Browse files
committed
Add unit tests for hello_world LangGraph sample
- Test basic workflow execution with query processing - Test empty query handling - Add fixture to clear global registry between tests
1 parent 58516c1 commit 9b17b34

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# LangGraph samples tests
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""Tests for the hello_world LangGraph sample."""
2+
3+
import uuid
4+
5+
import pytest
6+
from temporalio.client import Client
7+
from temporalio.contrib.langgraph import LangGraphPlugin
8+
from temporalio.contrib.langgraph._graph_registry import get_global_registry
9+
from temporalio.worker import Worker
10+
11+
from langgraph_samples.hello_world.graph import build_hello_graph
12+
from langgraph_samples.hello_world.workflow import HelloWorldWorkflow
13+
14+
15+
@pytest.fixture(autouse=True)
16+
def clear_registry() -> None:
17+
"""Clear the global graph registry before each test."""
18+
get_global_registry().clear()
19+
20+
21+
async def test_hello_world_workflow(client: Client) -> None:
22+
"""Test that the hello world workflow processes a query correctly."""
23+
task_queue = f"hello-world-test-{uuid.uuid4()}"
24+
25+
# Create plugin with the graph
26+
plugin = LangGraphPlugin(graphs={"hello_graph": build_hello_graph})
27+
28+
async with Worker(
29+
client,
30+
task_queue=task_queue,
31+
workflows=[HelloWorldWorkflow],
32+
plugins=[plugin],
33+
):
34+
result = await client.execute_workflow(
35+
HelloWorldWorkflow.run,
36+
"Hello from test",
37+
id=f"hello-world-{uuid.uuid4()}",
38+
task_queue=task_queue,
39+
)
40+
41+
assert result["result"] == "Processed: Hello from test"
42+
43+
44+
async def test_hello_world_empty_query(client: Client) -> None:
45+
"""Test hello world workflow with empty query."""
46+
task_queue = f"hello-world-test-{uuid.uuid4()}"
47+
48+
plugin = LangGraphPlugin(graphs={"hello_graph": build_hello_graph})
49+
50+
async with Worker(
51+
client,
52+
task_queue=task_queue,
53+
workflows=[HelloWorldWorkflow],
54+
plugins=[plugin],
55+
):
56+
result = await client.execute_workflow(
57+
HelloWorldWorkflow.run,
58+
"",
59+
id=f"hello-world-{uuid.uuid4()}",
60+
task_queue=task_queue,
61+
)
62+
63+
assert result["result"] == "Processed: "

0 commit comments

Comments
 (0)