Skip to content

Commit

Permalink
Full test coverage for s3_checkpointer.py (marked as a slow test) and…
Browse files Browse the repository at this point in the history
… more coverage for OpenSearchNeuralSearch
  • Loading branch information
bmquinn committed Dec 19, 2024
1 parent 600e30a commit d10084f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: ruff check .
- name: Run tests
run: |
coverage run --include='src/**/*' -m pytest
coverage run --include='src/**/*' -m pytest -m ""
coverage report
env:
AWS_REGION: us-east-1
4 changes: 4 additions & 0 deletions chat/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
addopts = -m "not slow"
markers =
slow: marks tests as slow (deselect with '-m "not slow"')
22 changes: 22 additions & 0 deletions chat/test/persistence/test_s3_checkpointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,25 @@ def test_invalid_checkpoint_key_format(self):
list(self.checkpointer.list(config))

self.assertIn("Invalid checkpoint key format", str(context.exception))

@pytest.mark.slow
def test_delete_checkpoints_large_batch(self):
"""Test deleting more than 1000 checkpoints to verify batch deletion logic."""
# Create 1001 objects to force batch deletion
for i in range(1001):
ckpt = Checkpoint(id=f"ckpt_del_{i}")
metadata = CheckpointMetadata()
config = self.create_config()
self.checkpointer.put(config, ckpt, metadata, {})

# Verify objects were created
config = self.create_config()
retrieved_before_delete = list(self.checkpointer.list(config))
self.assertEqual(len(retrieved_before_delete), 1001)

# Delete all checkpoints
self.checkpointer.delete_checkpoints(THREAD_ID)

# Verify all objects were deleted
retrieved_after_delete = list(self.checkpointer.list(config))
self.assertEqual(len(retrieved_after_delete), 0)
31 changes: 30 additions & 1 deletion chat/test/search/test_opensearch_neural_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,33 @@ def test_client_initialization_error(self):
index="test",
model_id="test",
client=None
)
)

def test_add_texts_does_nothing(self):
"""Test that add_texts method exists but does nothing."""
try:
# Call add_texts with some sample data
result = self.search.add_texts(
texts=["test1", "test2"],
metadatas=[{"id": "1"}, {"id": "2"}]
)
# Method should return None
self.assertIsNone(result)
except Exception as e:
self.fail(f"add_texts raised an unexpected exception: {e}")

def test_from_texts_does_nothing(self):
"""Test that from_texts classmethod exists but does nothing."""
try:
# Call from_texts with some sample data
result = OpenSearchNeuralSearch.from_texts(
texts=["test1", "test2"],
metadatas=[{"id": "1"}, {"id": "2"}],
endpoint="test",
index="test",
model_id="test"
)
# Method should return None
self.assertIsNone(result)
except Exception as e:
self.fail(f"from_texts raised an unexpected exception: {e}")

0 comments on commit d10084f

Please sign in to comment.