From 5a0228cb13b88d91a7f94d7273e28d48a45a8dcf Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Fri, 4 Apr 2025 16:00:28 -0700 Subject: [PATCH] Add test --- libs/langgraph/tests/test_pregel.py | 14 +++++++++++--- libs/langgraph/tests/test_pregel_async.py | 21 ++++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/libs/langgraph/tests/test_pregel.py b/libs/langgraph/tests/test_pregel.py index e03ceeb72..97405e41c 100644 --- a/libs/langgraph/tests/test_pregel.py +++ b/libs/langgraph/tests/test_pregel.py @@ -1510,8 +1510,14 @@ def test_send_sequences() -> None: ] +@pytest.mark.parametrize("checkpoint_during", [True, False]) @pytest.mark.parametrize("checkpointer_name", ALL_CHECKPOINTERS_SYNC) -def test_imp_task(request: pytest.FixtureRequest, checkpointer_name: str) -> None: +def test_imp_task( + request: pytest.FixtureRequest, checkpointer_name: str, checkpoint_during: bool +) -> None: + if not checkpoint_during and "shallow" in checkpointer_name: + pytest.skip("Checkpointing during execution not supported") + checkpointer = request.getfixturevalue(f"checkpointer_{checkpointer_name}") mapper_calls = 0 @@ -1577,7 +1583,7 @@ def test_imp_task(request: pytest.FixtureRequest, checkpointer_name: str) -> Non } thread1 = {"configurable": {"thread_id": "1"}} - assert [*graph.stream([0, 1], thread1)] == [ + assert [*graph.stream([0, 1], thread1, checkpoint_during=checkpoint_during)] == [ {"mapper": "00"}, {"mapper": "11"}, { @@ -1593,7 +1599,9 @@ def test_imp_task(request: pytest.FixtureRequest, checkpointer_name: str) -> Non ] assert mapper_calls == 2 - assert graph.invoke(Command(resume="answer"), thread1) == [ + assert graph.invoke( + Command(resume="answer"), thread1, checkpoint_during=checkpoint_during + ) == [ "00answer", "11answer", ] diff --git a/libs/langgraph/tests/test_pregel_async.py b/libs/langgraph/tests/test_pregel_async.py index 9fbf042fc..467e97f53 100644 --- a/libs/langgraph/tests/test_pregel_async.py +++ b/libs/langgraph/tests/test_pregel_async.py @@ -2230,7 +2230,7 @@ async def test_pending_writes_resume( @pytest.mark.parametrize("checkpointer_name", REGULAR_CHECKPOINTERS_ASYNC) async def test_run_from_checkpoint_id_retains_previous_writes( - request: pytest.FixtureRequest, checkpointer_name: str, mocker: MockerFixture + checkpointer_name: str, ) -> None: class MyState(TypedDict): myval: Annotated[int, operator.add] @@ -2275,8 +2275,8 @@ async def test_run_from_checkpoint_id_retains_previous_writes( history = [c async for c in graph.aget_state_history(thread1)] assert len(history) == 4 - assert history[-1].values == {"myval": 0} assert history[0].values == {"myval": 4, "otherval": False} + assert history[-1].values == {"myval": 0} second_run_config = { **thread1, @@ -2453,8 +2453,12 @@ async def test_send_sequences(checkpointer_name: str) -> None: @NEEDS_CONTEXTVARS +@pytest.mark.parametrize("checkpoint_during", [True, False]) @pytest.mark.parametrize("checkpointer_name", ALL_CHECKPOINTERS_ASYNC) -async def test_imp_task(checkpointer_name: str) -> None: +async def test_imp_task(checkpointer_name: str, checkpoint_during: bool) -> None: + if not checkpoint_during and "shallow" in checkpointer_name: + pytest.skip("Checkpointing during execution not supported") + async with awith_checkpointer(checkpointer_name) as checkpointer: mapper_calls = 0 @@ -2474,7 +2478,12 @@ async def test_imp_task(checkpointer_name: str) -> None: tracer = FakeTracer() thread1 = {"configurable": {"thread_id": "1"}, "callbacks": [tracer]} - assert [c async for c in graph.astream([0, 1], thread1)] == [ + assert [ + c + async for c in graph.astream( + [0, 1], thread1, checkpoint_during=checkpoint_during + ) + ] == [ {"mapper": "00"}, {"mapper": "11"}, { @@ -2498,7 +2507,9 @@ async def test_imp_task(checkpointer_name: str) -> None: assert any(r.inputs == {"input": 0} for r in mapper_runs) assert any(r.inputs == {"input": 1} for r in mapper_runs) - assert await graph.ainvoke(Command(resume="answer"), thread1) == [ + assert await graph.ainvoke( + Command(resume="answer"), thread1, checkpoint_during=checkpoint_during + ) == [ "00answer", "11answer", ]