
    BTh                         d dl Z d dlmZ d dlmZmZ d dlmZ d dlZd dl	m
Z
 d dlmZ d dlmZ  G d d	e      Z G d
 de      Zy)    N)abstractmethod)TupleType)mock)
Embeddings)	SecretStr)BaseStandardTestsc                   v    e Zd ZdZeedee   fd              Zede	fd       Z
ej                  defd       Zy)EmbeddingsTestsz
    :private:
    returnc                      y N selfs    w/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/langchain_tests/unit_tests/embeddings.pyembeddings_classz EmbeddingsTests.embeddings_class   s    47    c                     i S r   r   r   s    r   embedding_model_paramsz&EmbeddingsTests.embedding_model_params   s    	r   c                 :     | j                   di | j                  S )Nr   r   r   r   s    r   modelzEmbeddingsTests.model   s    $t$$Ct'B'BCCr   N)__name__
__module____qualname____doc__propertyr   r   r   r   dictr   pytestfixturer   r   r   r   r   r      sd     7$z"27  7   ^^Dz D Dr   r   c                   B    e Zd ZdZddZedeeeef   fd       ZddZ	y)EmbeddingsUnitTestsa  Base class for embeddings unit tests.

    Test subclasses must implement the ``embeddings_class`` property to specify the
    embeddings model to be tested. You can also override the
    ``embedding_model_params`` property to specify initialization parameters.

    Example:

    .. code-block:: python

        from typing import Type

        from langchain_tests.unit_tests import EmbeddingsUnitTests
        from my_package.embeddings import MyEmbeddingsModel


        class TestMyEmbeddingsModelUnit(EmbeddingsUnitTests):
            @property
            def embeddings_class(self) -> Type[MyEmbeddingsModel]:
                # Return the embeddings model class to test here
                return MyEmbeddingsModel

            @property
            def embedding_model_params(self) -> dict:
                # Return initialization parameters for the model.
                return {"model": "model-001"}

    .. note::
          API references for individual test methods include troubleshooting tips.

    Testing initialization from environment variables
        Overriding the ``init_from_env_params`` property will enable additional tests
        for initialization from environment variables. See below for details.

        .. dropdown:: init_from_env_params

            This property is used in unit tests to test initialization from
            environment variables. It should return a tuple of three dictionaries
            that specify the environment variables, additional initialization args,
            and expected instance attributes to check.

            Defaults to empty dicts. If not overridden, the test is skipped.

            Example:

            .. code-block:: python

                @property
                def init_from_env_params(self) -> Tuple[dict, dict, dict]:
                    return (
                        {
                            "MY_API_KEY": "api_key",
                        },
                        {
                            "model": "model-001",
                        },
                        {
                            "my_api_key": "api_key",
                        },
                    )
    r   Nc                 D     | j                   di | j                  }|J y)zTest model initialization.

        .. dropdown:: Troubleshooting

            If this test fails, ensure that ``embedding_model_params`` is specified
            and the model can be initialized from those params.
        Nr   r   )r   r   s     r   	test_initzEmbeddingsUnitTests.test_init^   s+     &%%D(C(CD   r   c                     i i i fS )a  This property is used in unit tests to test initialization from environment
        variables. It should return a tuple of three dictionaries that specify the
        environment variables, additional initialization args, and expected instance
        attributes to check.r   r   s    r   init_from_env_paramsz(EmbeddingsUnitTests.init_from_env_paramsi   s     2rzr   c                 r   | j                   \  }}}|rt        j                  j                  t        j
                  |      5   | j                  di |}ddd       J |j                         D ]8  \  }}t        ||      }t        |t              r|j                         }||k(  r8J  yy# 1 sw Y   ZxY w)a  Test initialization from environment variables. Relies on the
        ``init_from_env_params`` property. Test is skipped if that property is not
        set.

        .. dropdown:: Troubleshooting

            If this test fails, ensure that ``init_from_env_params`` is specified
            correctly and that model parameters are properly set from environment
            variables during initialization.
        Nr   )r'   r   patchr   osenvironr   itemsgetattr
isinstancer   get_secret_value)r   
env_paramsembeddings_paramsexpected_attrsr   kexpectedactuals           r   test_init_from_envz&EmbeddingsUnitTests.test_init_from_envq   s     9=8Q8Q5
%~Z8 C---B0ABC$$$-335 *8 *fi0#446F)))	*	 C Cs   B--B6)r   N)
r   r   r   r   r%   r   r   r   r'   r6   r   r   r   r#   r#      s9    <|	! eD$,<&=  *r   r#   )r*   abcr   typingr   r   unittestr   r    langchain_core.embeddingsr   pydanticr   langchain_tests.baser	   r   r#   r   r   r   <module>r=      s:    	     0  2D' D$f*/ f*r   