Skip to content

Commit

Permalink
fix: avoid init vertexai during unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
svidiella committed Feb 29, 2024
1 parent e0b27af commit 2aa6361
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions libs/vertexai/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__pycache__
.mypy_cache_test
2 changes: 1 addition & 1 deletion libs/vertexai/tests/integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from _pytest.tmpdir import TempPathFactory
from vertexai.vision_models import Image
from vertexai.vision_models import Image # type: ignore


@pytest.fixture
Expand Down
6 changes: 3 additions & 3 deletions libs/vertexai/tests/integration_tests/test_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
`gcloud auth login` first).
"""
import pytest
from vertexai.language_models import TextEmbeddingModel
from vertexai.vision_models import MultiModalEmbeddingModel
from vertexai.language_models import TextEmbeddingModel # type: ignore
from vertexai.vision_models import MultiModalEmbeddingModel # type: ignore

from langchain_google_vertexai.embeddings import (
VertexAIEmbeddings,
GoogleEmbeddingModelType,
VertexAIEmbeddings,
)


Expand Down
13 changes: 11 additions & 2 deletions libs/vertexai/tests/unit_tests/test_embeddings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Any
from typing import Any, Dict
from unittest.mock import MagicMock

import pytest
from pydantic.v1 import root_validator

from langchain_google_vertexai import VertexAIEmbeddings
from langchain_google_vertexai.embeddings import GoogleEmbeddingModelType
Expand Down Expand Up @@ -39,4 +40,12 @@ class MockVertexAIEmbeddings(VertexAIEmbeddings):

def __init__(self, model_name, **kwargs: Any) -> None:
super().__init__(model_name, **kwargs)
self.client = MagicMock()

@classmethod
def _init_vertexai(cls, values: Dict) -> None:
pass

@root_validator()
def validate_environment(cls, values: Dict) -> Dict:
values["client"] = MagicMock()
return values

0 comments on commit 2aa6361

Please sign in to comment.