From d10084fccfe019122c0ed2776ea065ebdc403e9a Mon Sep 17 00:00:00 2001 From: Brendan Quinn Date: Thu, 19 Dec 2024 02:47:43 +0000 Subject: [PATCH] Full test coverage for s3_checkpointer.py (marked as a slow test) and more coverage for OpenSearchNeuralSearch --- .github/workflows/test-python.yml | 2 +- chat/pytest.ini | 4 +++ chat/test/persistence/test_s3_checkpointer.py | 22 +++++++++++++ .../search/test_opensearch_neural_search.py | 31 ++++++++++++++++++- 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 chat/pytest.ini diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 2b093d4..0bd476d 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -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 diff --git a/chat/pytest.ini b/chat/pytest.ini new file mode 100644 index 0000000..1ca8434 --- /dev/null +++ b/chat/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +addopts = -m "not slow" +markers = + slow: marks tests as slow (deselect with '-m "not slow"') \ No newline at end of file diff --git a/chat/test/persistence/test_s3_checkpointer.py b/chat/test/persistence/test_s3_checkpointer.py index 3fa79b3..20d1bbb 100644 --- a/chat/test/persistence/test_s3_checkpointer.py +++ b/chat/test/persistence/test_s3_checkpointer.py @@ -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) \ No newline at end of file diff --git a/chat/test/search/test_opensearch_neural_search.py b/chat/test/search/test_opensearch_neural_search.py index 6de0287..ceb7ee7 100644 --- a/chat/test/search/test_opensearch_neural_search.py +++ b/chat/test/search/test_opensearch_neural_search.py @@ -129,4 +129,33 @@ def test_client_initialization_error(self): index="test", model_id="test", client=None - ) \ No newline at end of file + ) + + 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}") \ No newline at end of file