
    BTh,                         d dl Z d dlmZ d dlmZ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Union)mock)BaseTool)	SecretStr)BaseStandardTestsc                       e Zd ZdZeedeee   ef   fd              Z	ede
fd       Zede
fd       Zej                  defd       Zy)
ToolsTestsz
    :private:
    Base class for testing tools. This won't show in the documentation, but
    the docstrings will be inherited by subclasses.
    returnc                      y)zE
        Returns a class or instance of a tool to be tested.
        N selfs    r/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/langchain_tests/unit_tests/tools.pytool_constructorzToolsTests.tool_constructor   s     	    c                     i S )zU
        Returns a dictionary of parameters to pass to the tool constructor.
        r   r   s    r   tool_constructor_paramsz"ToolsTests.tool_constructor_params   s	    
 	r   c                     i S )z
        Returns a dictionary representing the "args" of an example tool call.

        This should NOT be a ToolCall dict - it should not
        have {"name", "id", "args"} keys.
        r   r   s    r   tool_invoke_params_examplez%ToolsTests.tool_invoke_params_example#   s	     	r   c                     t        | j                  t              r(| j                  i k7  rd}t	        |      | j                  S  | j                  di | j                  S )z
        :private:
        zUIf tool_constructor is an instance of BaseTool, tool_constructor_params must be emptyr   )
isinstancer   r   r   
ValueError)r   msgs     r   toolzToolsTests.tool-   s`    
 d++X6++r1<  !o%((($t$$Dt'C'CDDr   N)__name__
__module____qualname____doc__propertyr   r   r   r   r   dictr   r   pytestfixturer   r   r   r   r   r      s     %X(@"A       D   ^^Eh E Er   r   c                   r    e Zd ZdZedeeeef   fd       ZddZddZ	de
ddfdZde
ddfd	Zde
ddfd
Zy)ToolsUnitTestsz*
    Base class for tools unit tests.
    r   c                     i i i fS )z_Return env vars, init args, and expected instance attrs for initializing
        from env vars.r   r   s    r   init_from_env_paramsz#ToolsUnitTests.init_from_env_paramsB   s     2rzr   Nc                     t        | j                  t              r| j                  }n | j                  di | j                  }|J y)z
        Test that the tool can be initialized with :attr:`tool_constructor` and
        :attr:`tool_constructor_params`. If this fails, check that the
        keyword args defined in :attr:`tool_constructor_params` are valid.
        Nr   )r   r   r   r   r   r   s     r   	test_initzToolsUnitTests.test_initH   sF     d++X6((D(4((H4+G+GHD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)Nr   )r)   r   patchr#   osenvironr   itemsgetattrr   r	   get_secret_value)r   
env_paramstools_paramsexpected_attrsr   kexpectedactuals           r   test_init_from_envz!ToolsUnitTests.test_init_from_envT   s    373L3L0
L.Z8 =,t,,<|<=###-335 *8 q)fi0#446F)))	*	 = =s   B--B6r   c                      |j                   sJ y)z
        Tests that the tool has a name attribute to pass to chat models.

        If this fails, add a `name` parameter to your tool.
        N)namer+   s     r   test_has_namezToolsUnitTests.test_has_name`   s     yyyr   c                 (    |j                         sJ y)aS  
        Tests that the tool has an input schema.

        If this fails, add an `args_schema` to your tool.

        See
        `this guide <https://python.langchain.com/docs/how_to/custom_tools/#subclass-basetool>`_
        and see how `CalculatorInput` is configured in the
        `CustomCalculatorTool.args_schema` attribute
        N)get_input_schemar+   s     r   test_has_input_schemaz$ToolsUnitTests.test_has_input_schemah   s     $$&&&r   c                 L    |j                         } |di | j                  sJ y)z
        Tests that the provided example params match the declared input schema.

        If this fails, update the `tool_invoke_params_example` attribute to match
        the input schema (`args_schema`) of the tool.
        Nr   )r?   r   )r   r   input_schemas      r   'test_input_schema_matches_invoke_paramsz6ToolsUnitTests.test_input_schema_matches_invoke_paramsu   s)     ,,.>d==>>>r   )r   N)r   r   r    r!   r"   r   r#   r)   r,   r:   r   r=   r@   rC   r   r   r   r'   r'   =   sq     eD$,<&=  

 
*( t '( 't '
?H 
? 
?r   r'   )r/   abcr   typingr   r   r   unittestr   r$   langchain_core.toolsr   pydanticr	   langchain_tests.baser
   r   r'   r   r   r   <module>rJ      s>    	  % %   )  2-E" -E`B?Z B?r   