From d48dec5452dadabf2a4de9d9c47fd8bbebf3fad8 Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Mon, 20 Jan 2025 11:09:35 -0800 Subject: [PATCH 1/3] Enable async tests that were being skipped - async tests are placed in test_pregel_async, not in test_pregel - to avoid tests placed in wrong file being accidentally skipped i've added the auto-async mark to sync test file --- libs/langgraph/tests/test_pregel.py | 50 +---------------------- libs/langgraph/tests/test_pregel_async.py | 48 ++++++++++++++++++++++ 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/libs/langgraph/tests/test_pregel.py b/libs/langgraph/tests/test_pregel.py index faa359862..319ceed1c 100644 --- a/libs/langgraph/tests/test_pregel.py +++ b/libs/langgraph/tests/test_pregel.py @@ -82,6 +82,8 @@ from tests.messages import ( _AnyIdToolMessage, ) +pytestmark = pytest.mark.anyio + logger = logging.getLogger(__name__) @@ -5740,34 +5742,6 @@ def test_entrypoint_without_checkpointer() -> None: assert foo.invoke({"a": "1"}, config) == {"current": {"a": "1"}, "previous": None} -async def test_async_entrypoint_without_checkpointer() -> None: - """Test no checkpointer.""" - states = [] - config = {"configurable": {"thread_id": "1"}} - - # Test without previous - @entrypoint() - async def foo(inputs: Any) -> Any: - states.append(inputs) - return inputs - - assert (await foo.ainvoke({"a": "1"}, config)) == {"a": "1"} - - @entrypoint() - async def foo(inputs: Any, *, previous: Any) -> Any: - states.append(previous) - return {"previous": previous, "current": inputs} - - assert (await foo.ainvoke({"a": "1"}, config)) == { - "current": {"a": "1"}, - "previous": None, - } - assert (await foo.ainvoke({"a": "1"}, config)) == { - "current": {"a": "1"}, - "previous": None, - } - - def test_entrypoint_stateful() -> None: """Test stateful entrypoint invoke.""" @@ -5859,26 +5833,6 @@ def test_entrypoint_request_stream_writer() -> None: ] -async def test_entrypoint_from_async_generator() -> None: - """@entrypoint does not support sync generators.""" - # Test invoke - previous_return_values = [] - - # In this version reducers do not work - @entrypoint(checkpointer=MemorySaver()) - async def foo(inputs, previous=None) -> Any: - previous_return_values.append(previous) - yield "a" - yield "b" - - config = {"configurable": {"thread_id": "1"}} - - assert list(await foo.ainvoke({"a": "1"}, config)) == ["a", "b"] - assert previous_return_values == [None] - assert list(foo.invoke({"a": "2"}, config)) == ["a", "b"] - assert previous_return_values == [None, ["a", "b"]] - - @pytest.mark.parametrize("checkpointer_name", ALL_CHECKPOINTERS_SYNC) def test_multiple_subgraphs( request: pytest.FixtureRequest, checkpointer_name: str diff --git a/libs/langgraph/tests/test_pregel_async.py b/libs/langgraph/tests/test_pregel_async.py index 67d31fc38..a0c135a4f 100644 --- a/libs/langgraph/tests/test_pregel_async.py +++ b/libs/langgraph/tests/test_pregel_async.py @@ -7272,3 +7272,51 @@ async def test_multiple_subgraphs_mixed_checkpointer( ), ((), {"parent_node": {"parent_counter": 7}}), ] + + +async def test_async_entrypoint_without_checkpointer() -> None: + """Test no checkpointer.""" + states = [] + config = {"configurable": {"thread_id": "1"}} + + # Test without previous + @entrypoint() + async def foo(inputs: Any) -> Any: + states.append(inputs) + return inputs + + assert (await foo.ainvoke({"a": "1"}, config)) == {"a": "1"} + + @entrypoint() + async def foo(inputs: Any, *, previous: Any) -> Any: + states.append(previous) + return {"previous": previous, "current": inputs} + + assert (await foo.ainvoke({"a": "1"}, config)) == { + "current": {"a": "1"}, + "previous": None, + } + assert (await foo.ainvoke({"a": "1"}, config)) == { + "current": {"a": "1"}, + "previous": None, + } + + +async def test_entrypoint_from_async_generator() -> None: + """@entrypoint does not support sync generators.""" + # Test invoke + previous_return_values = [] + + # In this version reducers do not work + @entrypoint(checkpointer=MemorySaver()) + async def foo(inputs, previous=None) -> Any: + previous_return_values.append(previous) + yield "a" + yield "b" + + config = {"configurable": {"thread_id": "1"}} + + assert list(await foo.ainvoke({"a": "1"}, config)) == ["a", "b"] + assert previous_return_values == [None] + assert list(foo.invoke({"a": "2"}, config)) == ["a", "b"] + assert previous_return_values == [None, ["a", "b"]] From 3ca75d69b8cd6690e365e81cdc5858f8aa18517d Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Mon, 20 Jan 2025 11:42:29 -0800 Subject: [PATCH 2/3] Lint --- libs/langgraph/tests/test_pregel_async.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/langgraph/tests/test_pregel_async.py b/libs/langgraph/tests/test_pregel_async.py index a0c135a4f..8609c0500 100644 --- a/libs/langgraph/tests/test_pregel_async.py +++ b/libs/langgraph/tests/test_pregel_async.py @@ -7274,6 +7274,7 @@ async def test_multiple_subgraphs_mixed_checkpointer( ] +@NEEDS_CONTEXTVARS async def test_async_entrypoint_without_checkpointer() -> None: """Test no checkpointer.""" states = [] @@ -7302,6 +7303,7 @@ async def test_async_entrypoint_without_checkpointer() -> None: } +@NEEDS_CONTEXTVARS async def test_entrypoint_from_async_generator() -> None: """@entrypoint does not support sync generators.""" # Test invoke From 09e8516689713a47b9a7e7e4e6f1526ee0f05f1c Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Mon, 20 Jan 2025 11:56:18 -0800 Subject: [PATCH 3/3] Fix test --- libs/langgraph/tests/test_pregel_async.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/langgraph/tests/test_pregel_async.py b/libs/langgraph/tests/test_pregel_async.py index 8609c0500..934aacdf8 100644 --- a/libs/langgraph/tests/test_pregel_async.py +++ b/libs/langgraph/tests/test_pregel_async.py @@ -7320,5 +7320,3 @@ async def test_entrypoint_from_async_generator() -> None: assert list(await foo.ainvoke({"a": "1"}, config)) == ["a", "b"] assert previous_return_values == [None] - assert list(foo.invoke({"a": "2"}, config)) == ["a", "b"] - assert previous_return_values == [None, ["a", "b"]]