Skip to content

Commit 0580666

Browse files
committed
Cleanup tests 2
1 parent c935951 commit 0580666

File tree

1 file changed

+46
-70
lines changed
  • libs/langgraph-checkpoint-aws/tests/unit_tests/agentcore

1 file changed

+46
-70
lines changed

libs/langgraph-checkpoint-aws/tests/unit_tests/agentcore/test_saver.py

Lines changed: 46 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,16 @@
4444

4545
@pytest.fixture
4646
def sample_checkpoint_tuple():
47-
"""Helper to create a mock checkpoint tuple with configurable IDs."""
48-
config = {
49-
"configurable": {
50-
"thread_id": "test_thread_id",
51-
"actor_id": "test_actor",
52-
"checkpoint_id": "test_checkpoint_id",
53-
}
54-
}
55-
checkpoint = {"id": "test_checkpoint_id"}
56-
metadata = {"source": "input", "step": 0}
5747
return CheckpointTuple(
58-
config=config,
59-
checkpoint=checkpoint,
60-
metadata=metadata,
48+
config={
49+
"configurable": {
50+
"thread_id": "test_thread_id",
51+
"actor_id": "test_actor",
52+
"checkpoint_id": "test_checkpoint_id",
53+
}
54+
},
55+
checkpoint={"id": "test_checkpoint_id"},
56+
metadata={"source": "input", "step": 0},
6157
)
6258

6359

@@ -176,54 +172,54 @@ def sample_checkpoint_metadata(self):
176172
)
177173

178174
@pytest.fixture
179-
def slow_get_tuple(self, sample_checkpoint_tuple):
175+
def mock_slow_get_tuple(self, sample_checkpoint_tuple):
180176
"""Mock get_tuple with artificial delay for testing async concurrency."""
181177

182-
def _slow_get_tuple(config): # noqa: ARG001
178+
def _mock_slow_get_tuple(config): # noqa: ARG001
183179
time.sleep(MOCK_SLEEP_DURATION)
184180
return sample_checkpoint_tuple
185181

186-
return _slow_get_tuple
182+
return _mock_slow_get_tuple
187183

188184
@pytest.fixture
189-
def slow_list(self, sample_checkpoint_tuple):
185+
def mock_slow_list(self, sample_checkpoint_tuple):
190186
"""Mock list with artificial delay for testing async concurrency."""
191187

192-
def _slow_list(config, *, filter=None, before=None, limit=None): # noqa: ARG001 A002
188+
def _mock_slow_list(config, *, filter=None, before=None, limit=None): # noqa: ARG001 A002
193189
time.sleep(MOCK_SLEEP_DURATION)
194190
return [sample_checkpoint_tuple]
195191

196-
return _slow_list
192+
return _mock_slow_list
197193

198194
@pytest.fixture
199-
def slow_put(self):
195+
def mock_slow_put(self):
200196
"""Mock put with artificial delay for testing async concurrency."""
201197

202-
def _slow_put(config, checkpoint, metadata, new_versions): # noqa: ARG001
198+
def _mock_slow_put(config, checkpoint, metadata, new_versions): # noqa: ARG001
203199
time.sleep(MOCK_SLEEP_DURATION)
204200
return config
205201

206-
return _slow_put
202+
return _mock_slow_put
207203

208204
@pytest.fixture
209-
def slow_put_writes(self):
205+
def mock_slow_put_writes(self):
210206
"""Mock put_writes with artificial delay for testing async concurrency."""
211207

212-
def _slow_put_writes(config, writes, task_id, task_path=""): # noqa: ARG001
208+
def _mock_slow_put_writes(config, writes, task_id, task_path=""): # noqa: ARG001
213209
time.sleep(MOCK_SLEEP_DURATION)
214210
return
215211

216-
return _slow_put_writes
212+
return _mock_slow_put_writes
217213

218214
@pytest.fixture
219-
def slow_delete_thread(self):
215+
def mock_slow_delete_thread(self):
220216
"""Mock delete_thread with artificial delay for testing async concurrency."""
221217

222-
def _slow_delete_thread(thread_id, actor_id=""): # noqa: ARG001
218+
def _mock_slow_delete_thread(thread_id, actor_id=""): # noqa: ARG001
223219
time.sleep(MOCK_SLEEP_DURATION)
224220
return
225221

226-
return _slow_delete_thread
222+
return _mock_slow_delete_thread
227223

228224
def test_init_with_default_client(self, memory_id):
229225
with patch("boto3.client") as mock_boto3_client:
@@ -668,13 +664,11 @@ def test_get_next_version(self, saver):
668664
assert version.startswith("00000000000000000000000000000011.")
669665

670666
async def test_aget_tuple_calls_sync_method_with_correct_args(
671-
self, saver, runnable_config, slow_get_tuple
667+
self, saver, runnable_config, mock_slow_get_tuple
672668
):
673-
"""
674-
Test that aget_tuple calls the sync get_tuple method with correct arguments.
675-
"""
676-
677-
with patch.object(saver, "get_tuple", side_effect=slow_get_tuple) as mock_get:
669+
with patch.object(
670+
saver, "get_tuple", side_effect=mock_slow_get_tuple
671+
) as mock_get:
678672
result = await saver.aget_tuple(runnable_config)
679673

680674
# Verify sync method was called with correct arguments
@@ -683,15 +677,13 @@ async def test_aget_tuple_calls_sync_method_with_correct_args(
683677
assert result is not None
684678

685679
async def test_alist_calls_sync_method_with_correct_args(
686-
self, saver, runnable_config, slow_list
680+
self, saver, runnable_config, mock_slow_list
687681
):
688-
"""Test that alist calls the sync list method with correct arguments."""
689-
690682
filter_dict = {"test": "filter"}
691683
before_config = {"before": "config"}
692684
limit_value = 10
693685

694-
with patch.object(saver, "list", side_effect=slow_list) as mock_list:
686+
with patch.object(saver, "list", side_effect=mock_slow_list) as mock_list:
695687
# Collect all items from async iterator
696688
items = []
697689
async for item in saver.alist(
@@ -718,13 +710,11 @@ async def test_aput_calls_sync_method_with_correct_args(
718710
runnable_config,
719711
sample_checkpoint,
720712
sample_checkpoint_metadata,
721-
slow_put,
713+
mock_slow_put,
722714
):
723-
"""Test that aput calls the sync put method with correct arguments."""
724-
725715
new_versions = {"default": "v2"}
726716

727-
with patch.object(saver, "put", side_effect=slow_put) as mock_put:
717+
with patch.object(saver, "put", side_effect=mock_slow_put) as mock_put:
728718
result = await saver.aput(
729719
runnable_config,
730720
sample_checkpoint,
@@ -743,18 +733,14 @@ async def test_aput_calls_sync_method_with_correct_args(
743733
assert result == runnable_config
744734

745735
async def test_aput_writes_calls_sync_method_with_correct_args(
746-
self, saver, runnable_config, slow_put_writes
736+
self, saver, runnable_config, mock_slow_put_writes
747737
):
748-
"""
749-
Test that aput_writes calls the sync put_writes method with correct arguments.
750-
"""
751-
752738
writes = [("channel", "value")]
753739
task_id = "test-task"
754740
task_path = "test-path"
755741

756742
with patch.object(
757-
saver, "put_writes", side_effect=slow_put_writes
743+
saver, "put_writes", side_effect=mock_slow_put_writes
758744
) as mock_put_writes:
759745
result = await saver.aput_writes(
760746
runnable_config, writes, task_id, task_path
@@ -767,18 +753,13 @@ async def test_aput_writes_calls_sync_method_with_correct_args(
767753
assert result is None
768754

769755
async def test_adelete_thread_calls_sync_method_with_correct_args(
770-
self, saver, runnable_config, slow_delete_thread
756+
self, saver, runnable_config, mock_slow_delete_thread
771757
):
772-
"""
773-
Test that adelete_thread calls the sync delete_thread method
774-
with correct arguments
775-
"""
776-
777758
thread_id = runnable_config["configurable"]["thread_id"]
778759
actor_id = runnable_config["configurable"]["actor_id"]
779760

780761
with patch.object(
781-
saver, "delete_thread", side_effect=slow_delete_thread
762+
saver, "delete_thread", side_effect=mock_slow_delete_thread
782763
) as mock_delete:
783764
result = await saver.adelete_thread(thread_id, actor_id)
784765

@@ -787,35 +768,32 @@ async def test_adelete_thread_calls_sync_method_with_correct_args(
787768
assert result is None
788769

789770
async def test_concurrent_calls_aget_tuple(
790-
self, saver, runnable_config, slow_get_tuple
771+
self, saver, runnable_config, mock_slow_get_tuple
791772
):
792-
"""Test that concurrent calls are faster than sequential calls."""
793-
with patch.object(saver, "get_tuple", side_effect=slow_get_tuple):
773+
with patch.object(saver, "get_tuple", side_effect=mock_slow_get_tuple):
794774
await self.assert_concurrent_calls_are_faster_than_sequential(
795775
N_ASYNC_CALLS, saver.aget_tuple, runnable_config
796776
)
797777

798778
async def test_concurrent_calls_adelete_thread(
799-
self, saver, runnable_config, slow_delete_thread
779+
self, saver, runnable_config, mock_slow_delete_thread
800780
):
801-
"""Test that concurrent calls are faster than sequential calls."""
802781
thread_id = runnable_config["configurable"]["thread_id"]
803782
actor_id = runnable_config["configurable"]["actor_id"]
804783

805-
with patch.object(saver, "delete_thread", side_effect=slow_delete_thread):
784+
with patch.object(saver, "delete_thread", side_effect=mock_slow_delete_thread):
806785
await self.assert_concurrent_calls_are_faster_than_sequential(
807786
N_ASYNC_CALLS, saver.adelete_thread, thread_id, actor_id
808787
)
809788

810789
async def test_concurrent_calls_aput_writes(
811-
self, saver, runnable_config, slow_put_writes
790+
self, saver, runnable_config, mock_slow_put_writes
812791
):
813-
"""Test that concurrent calls are faster than sequential calls."""
814792
writes = [("channel", "value")]
815793
task_id = "test-task"
816794
task_path = "test-path"
817795

818-
with patch.object(saver, "put_writes", side_effect=slow_put_writes):
796+
with patch.object(saver, "put_writes", side_effect=mock_slow_put_writes):
819797
await self.assert_concurrent_calls_are_faster_than_sequential(
820798
N_ASYNC_CALLS,
821799
saver.aput_writes,
@@ -831,12 +809,11 @@ async def test_concurrent_calls_aput(
831809
runnable_config,
832810
sample_checkpoint,
833811
sample_checkpoint_metadata,
834-
slow_put,
812+
mock_slow_put,
835813
):
836-
"""Test that concurrent calls are faster than sequential calls."""
837814
new_versions = {"default": "v2"}
838815

839-
with patch.object(saver, "put", side_effect=slow_put):
816+
with patch.object(saver, "put", side_effect=mock_slow_put):
840817
await self.assert_concurrent_calls_are_faster_than_sequential(
841818
N_ASYNC_CALLS,
842819
saver.aput,
@@ -846,13 +823,12 @@ async def test_concurrent_calls_aput(
846823
new_versions,
847824
)
848825

849-
async def test_concurrent_calls_alist(self, saver, runnable_config, slow_list):
850-
"""Test that concurrent calls are faster than sequential calls."""
826+
async def test_concurrent_calls_alist(self, saver, runnable_config, mock_slow_list):
851827
filter_dict = {"test": "filter"}
852828
before_config = {"before": "config"}
853829
limit_value = 10
854830

855-
with patch.object(saver, "list", side_effect=slow_list):
831+
with patch.object(saver, "list", side_effect=mock_slow_list):
856832

857833
async def consume_alist() -> list:
858834
"""Helper coroutine to consume the async iterator."""

0 commit comments

Comments
 (0)