repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | from unittest.mock import ANY, patch |
| #2 | |
| #3 | import pytest |
| #4 | |
| #5 | from mem0.configs.embeddings.base import BaseEmbedderConfig |
| #6 | from mem0.embeddings.gemini import GoogleGenAIEmbedding |
| #7 | |
| #8 | |
| #9 | @pytest.fixture |
| #10 | def mock_genai(): |
| #11 | with patch("mem0.embeddings.gemini.genai.Client") as mock_client_class: |
| #12 | mock_client = mock_client_class.return_value |
| #13 | mock_client.models.embed_content.return_value = None |
| #14 | yield mock_client.models.embed_content |
| #15 | |
| #16 | |
| #17 | @pytest.fixture |
| #18 | def config(): |
| #19 | return BaseEmbedderConfig(api_key="dummy_api_key", model="test_model", embedding_dims=786) |
| #20 | |
| #21 | |
| #22 | def test_embed_query(mock_genai, config): |
| #23 | mock_embedding_response = type( |
| #24 | "Response", (), {"embeddings": [type("Embedding", (), {"values": [0.1, 0.2, 0.3, 0.4]})]} |
| #25 | )() |
| #26 | mock_genai.return_value = mock_embedding_response |
| #27 | |
| #28 | embedder = GoogleGenAIEmbedding(config) |
| #29 | |
| #30 | text = "Hello, world!" |
| #31 | embedding = embedder.embed(text) |
| #32 | |
| #33 | assert embedding == [0.1, 0.2, 0.3, 0.4] |
| #34 | mock_genai.assert_called_once_with(model="test_model", contents="Hello, world!", config=ANY) |
| #35 | |
| #36 | |
| #37 | def test_embed_returns_empty_list_if_none(mock_genai, config): |
| #38 | mock_genai.return_value = type("Response", (), {"embeddings": [type("Embedding", (), {"values": []})]})() |
| #39 | |
| #40 | embedder = GoogleGenAIEmbedding(config) |
| #41 | |
| #42 | result = embedder.embed("test") |
| #43 | assert result == [] |
| #44 | |
| #45 | |
| #46 | def test_embed_raises_on_error(mock_genai, config): |
| #47 | mock_genai.side_effect = RuntimeError("Embedding failed") |
| #48 | |
| #49 | embedder = GoogleGenAIEmbedding(config) |
| #50 | |
| #51 | with pytest.raises(RuntimeError, match="Embedding failed"): |
| #52 | embedder.embed("some input") |
| #53 | |
| #54 | |
| #55 | def test_config_initialization(config): |
| #56 | embedder = GoogleGenAIEmbedding(config) |
| #57 | |
| #58 | assert embedder.config.api_key == "dummy_api_key" |
| #59 | assert embedder.config.model == "test_model" |
| #60 | assert embedder.config.embedding_dims == 786 |
| #61 |