Test that embedding function is callable.
(self, mock_require_module)
| 736 | |
| 737 | @patch("zvec.extension.openai_function.require_module") |
| 738 | def test_embed_callable(self, mock_require_module): |
| 739 | """Test that embedding function is callable.""" |
| 740 | mock_openai = Mock() |
| 741 | mock_client = Mock() |
| 742 | mock_response = Mock() |
| 743 | |
| 744 | fake_embedding = [0.1] * 1536 |
| 745 | mock_embedding_obj = Mock() |
| 746 | mock_embedding_obj.embedding = fake_embedding |
| 747 | mock_response.data = [mock_embedding_obj] |
| 748 | |
| 749 | mock_client.embeddings.create.return_value = mock_response |
| 750 | mock_openai.OpenAI.return_value = mock_client |
| 751 | mock_openai.APIError = type("APIError", (Exception,), {}) |
| 752 | mock_openai.APIConnectionError = type("APIConnectionError", (Exception,), {}) |
| 753 | mock_require_module.return_value = mock_openai |
| 754 | |
| 755 | embedding_func = OpenAIDenseEmbedding(api_key="sk-test") |
| 756 | embedding_func.embed.cache_clear() |
| 757 | |
| 758 | # Test calling the function directly |
| 759 | result = embedding_func("test text") |
| 760 | assert isinstance(result, list) |
| 761 | assert len(result) == 1536 |
| 762 | |
| 763 | @patch("zvec.extension.openai_function.require_module") |
| 764 | def test_embed_with_base_url(self, mock_require_module): |
nothing calls this directly
no test coverage detected