mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-21 22:29:51 +00:00
Signed-off-by: ChengZi <chen.zhang@zilliz.com> Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com> Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> Co-authored-by: Dan O'Donovan <dan.odonovan@gmail.com> Co-authored-by: Tom Daniel Grande <tomdgrande@gmail.com> Co-authored-by: Grande <Tom.Daniel.Grande@statsbygg.no> Co-authored-by: Bagatur <baskaryan@gmail.com> Co-authored-by: ccurme <chester.curme@gmail.com> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com> Co-authored-by: Tomaz Bratanic <bratanic.tomaz@gmail.com> Co-authored-by: ZhangShenao <15201440436@163.com> Co-authored-by: Friso H. Kingma <fhkingma@gmail.com> Co-authored-by: ChengZi <chen.zhang@zilliz.com> Co-authored-by: Nuno Campos <nuno@langchain.dev> Co-authored-by: Morgante Pell <morgantep@google.com>
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import os
|
|
from abc import abstractmethod
|
|
from typing import Tuple, Type
|
|
from unittest import mock
|
|
|
|
import pytest
|
|
from langchain_core.embeddings import Embeddings
|
|
from pydantic import SecretStr
|
|
|
|
from langchain_standard_tests.base import BaseStandardTests
|
|
|
|
|
|
class EmbeddingsTests(BaseStandardTests):
|
|
@property
|
|
@abstractmethod
|
|
def embeddings_class(self) -> Type[Embeddings]:
|
|
...
|
|
|
|
@property
|
|
def embedding_model_params(self) -> dict:
|
|
return {}
|
|
|
|
@pytest.fixture
|
|
def model(self) -> Embeddings:
|
|
return self.embeddings_class(**self.embedding_model_params)
|
|
|
|
|
|
class EmbeddingsUnitTests(EmbeddingsTests):
|
|
def test_init(self) -> None:
|
|
model = self.embeddings_class(**self.embedding_model_params)
|
|
assert model is not None
|
|
|
|
@property
|
|
def init_from_env_params(self) -> Tuple[dict, dict, dict]:
|
|
"""Return env vars, init args, and expected instance attrs for initializing
|
|
from env vars."""
|
|
return {}, {}, {}
|
|
|
|
def test_init_from_env(self) -> None:
|
|
env_params, embeddings_params, expected_attrs = self.init_from_env_params
|
|
if env_params:
|
|
with mock.patch.dict(os.environ, env_params):
|
|
model = self.embeddings_class(**embeddings_params)
|
|
assert model is not None
|
|
for k, expected in expected_attrs.items():
|
|
actual = getattr(model, k)
|
|
if isinstance(actual, SecretStr):
|
|
actual = actual.get_secret_value()
|
|
assert actual == expected
|