mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-14 05:56:40 +00:00
standard-tests: rename langchain_standard_tests to langchain_tests, release 0.3.2 (#28203)
This commit is contained in:
48
libs/standard-tests/langchain_tests/unit_tests/embeddings.py
Normal file
48
libs/standard-tests/langchain_tests/unit_tests/embeddings.py
Normal file
@@ -0,0 +1,48 @@
|
||||
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_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
|
Reference in New Issue
Block a user