mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-16 06:53:16 +00:00
standard-tests[patch]: test init from env vars (#25983)
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import os
|
||||
from abc import abstractmethod
|
||||
from typing import Type
|
||||
from typing import Tuple, Type
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from langchain_core.embeddings import Embeddings
|
||||
from langchain_core.pydantic_v1 import SecretStr
|
||||
|
||||
from langchain_standard_tests.base import BaseStandardTests
|
||||
|
||||
@@ -26,3 +29,21 @@ 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