MCPcopy Create free account
hub / github.com/alibaba/zvec / test_embed_api_error

Method test_embed_api_error

python/tests/test_embedding.py:667–688  ·  view source on GitHub ↗

Test handling of API errors.

(self, mock_require_module)

Source from the content-addressed store, hash-verified

665
666 @patch("zvec.extension.openai_function.require_module")
667 def test_embed_api_error(self, mock_require_module):
668 """Test handling of API errors."""
669 mock_openai = Mock()
670 mock_client = Mock()
671
672 # Simulate API error
673 api_error = Mock()
674 api_error.__class__.__name__ = "APIError"
675 mock_openai.APIError = type("APIError", (Exception,), {})
676 mock_openai.APIConnectionError = type("APIConnectionError", (Exception,), {})
677
678 mock_client.embeddings.create.side_effect = mock_openai.APIError(
679 "Rate limit exceeded"
680 )
681 mock_openai.OpenAI.return_value = mock_client
682 mock_require_module.return_value = mock_openai
683
684 embedding_func = OpenAIDenseEmbedding(api_key="sk-test")
685 embedding_func.embed.cache_clear()
686
687 with pytest.raises(RuntimeError, match="Failed to call OpenAI API"):
688 embedding_func.embed("test text")
689
690 @patch("zvec.extension.openai_function.require_module")
691 def test_embed_invalid_response(self, mock_require_module):

Callers

nothing calls this directly

Calls 2

embedMethod · 0.95

Tested by

no test coverage detected