
    BTh                     l    d 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)z
Standard tests for the BaseCache abstraction

We don't recommend implementing externally managed BaseCache abstractions at this time.

:private:
    )abstractmethodN)	BaseCache
Generation)BaseStandardTestsc                       e Zd ZdZeej                  defd              Zde	fdZ
de	fdZdefdZdeddfd	Zdeddfd
ZdeddfdZdeddfdZdeddfdZdeddfdZdeddfdZy)SyncCacheTestSuiteS  Test suite for checking the BaseCache API of a caching layer for LLMs.

    This test suite verifies the basic caching API of a caching layer for LLMs.

    The test suite is designed for synchronous caching layers.

    Implementers should subclass this test suite and provide a fixture
    that returns an empty cache for each test.
    returnc                      yzRGet the cache class to test.

        The returned cache should be EMPTY.
        N selfs    y/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/langchain_tests/integration_tests/cache.pycachezSyncCacheTestSuite.cache   s        c                      yz#Return a sample prompt for testing.zSample prompt for testing.r   r   s    r   get_sample_promptz$SyncCacheTestSuite.get_sample_prompt%       +r   c                      yz'Return a sample LLM string for testing.z Sample LLM string configuration.r   r   s    r   get_sample_llm_stringz(SyncCacheTestSuite.get_sample_llm_string)       1r   c                      t        dddi      S z.Return a sample Generation object for testing.zSample generated text.reasontest)textgeneration_infor   r   s    r   get_sample_generationz(SyncCacheTestSuite.get_sample_generation-       )Hf;M
 	
r   r   Nc                 d    |j                  | j                         | j                               J yzTest that the cache is empty.Nlookupr   r   r   r   s     r   test_cache_is_emptyz&SyncCacheTestSuite.test_cache_is_empty3   s/     LL//143M3M3OPX	
Xr   c                     | j                         }| j                         }| j                         }|j                  |||g       |j	                  ||      |gk(  sJ yzTest updating the cache.Nr   r   r"   updater'   r   r   prompt
llm_string
generations        r   test_update_cachez$SyncCacheTestSuite.test_update_cache9   Y    '')//1
//1
VZ*6||FJ/J<???r   c                 d    |j                  | j                         | j                               J yzThis test should follow a test that updates the cache.

        This just verifies that the fixture is set up properly to be empty
        after each test.
        Nr&   r(   s     r   test_cache_still_emptyz)SyncCacheTestSuite.test_cache_still_emptyA   s/     LL//143M3M3OPX	
Xr   c                     | j                         }| j                         }| j                         }|j                  |||g       |j	                          |j                  ||      J yzTest clearing the cache.N)r   r   r"   r-   clearr'   r.   s        r   test_clear_cachez#SyncCacheTestSuite.test_clear_cacheK   s^    '')//1
//1
VZ*6||FJ/777r   c                 H    |j                  d| j                               J yzTest cache miss.zNonexistent promptN)r'   r   r(   s     r   test_cache_missz"SyncCacheTestSuite.test_cache_missT   s#    ||0$2L2L2NOWWWr   c                     | j                         }| j                         }| j                         }|j                  |||g       |j	                  ||      |gk(  sJ yzTest cache hit.Nr,   r.   s        r   test_cache_hitz!SyncCacheTestSuite.test_cache_hitX   r3   r   c                     | j                         }| j                         }| j                         t        d      g}|j	                  |||       |j                  ||      |k(  sJ yz9Test updating the cache with multiple Generation objects.zAnother generated text.)r    N)r   r   r"   r   r-   r'   r   r   r/   r0   generationss        r   +test_update_cache_with_multiple_generationsz>SyncCacheTestSuite.test_update_cache_with_multiple_generations`   se    '')//1
&&(56
 	VZ5||FJ/;>>>r   __name__
__module____qualname____doc__r   pytestfixturer   r   strr   r   r   r"   r)   r2   r6   r:   r=   r@   rE   r   r   r   r	   r	      s     ^^y   ,3 ,2s 2
z 

 
t 
@y @T @
I 
$ 
8i 8D 8XY X4 X@I @$ @	? 	?t 	?r   r	   c                       e Zd ZdZeej                  defd              Zde	fdZ
de	fdZdefdZdeddfd	Zdeddfd
ZdeddfdZdeddfdZdeddfdZdeddfdZdeddfdZy)AsyncCacheTestSuiter
   r   c                    K   ywr   r   r   s    r   r   zAsyncCacheTestSuite.cachew   s     s   c                      yr   r   r   s    r   r   z%AsyncCacheTestSuite.get_sample_prompt   r   r   c                      yr   r   r   s    r   r   z)AsyncCacheTestSuite.get_sample_llm_string   r   r   c                      t        dddi      S r   r   r   s    r   r"   z)AsyncCacheTestSuite.get_sample_generation   r#   r   r   Nc                    K   |j                  | j                         | j                                d{   	 J y7 wr%   alookupr   r   r(   s     r   r)   z'AsyncCacheTestSuite.test_cache_is_empty   s@      -- 6 6 8$:T:T:VWW	
W   2?=	?c                    K   | j                         }| j                         }| j                         }|j                  |||g       d{    |j	                  ||       d{   |gk(  sJ y7 %7 wr+   r   r   r"   aupdaterV   r.   s        r   r2   z%AsyncCacheTestSuite.test_update_cache   o     '')//1
//1
mmFJ===]]6:66:,FFF 	>6$   AA4
A0A4$A2%A42A4c                    K   |j                  | j                         | j                                d{   	 J y7 wr5   rU   r(   s     r   r6   z*AsyncCacheTestSuite.test_cache_still_empty   s@      -- 6 6 8$:T:T:VWW	
WrW   c                   K   | j                         }| j                         }| j                         }|j                  |||g       d{    |j	                          d{    |j                  ||       d{   J y7 97 #7 wr8   )r   r   r"   rZ   aclearrV   r.   s        r   r:   z$AsyncCacheTestSuite.test_clear_cache   s~     '')//1
//1
mmFJ===lln]]6:66>>> 	>6s6   AB

BB
"B#B
<B=B
B
B
c                 f   K   |j                  d| j                                d{   	 J y7 wr<   )rV   r   r(   s     r   r=   z#AsyncCacheTestSuite.test_cache_miss   s8      -- 4d6P6P6RSS	
Ss   $1/	1c                    K   | j                         }| j                         }| j                         }|j                  |||g       d{    |j	                  ||       d{   |gk(  sJ y7 %7 wr?   rY   r.   s        r   r@   z"AsyncCacheTestSuite.test_cache_hit   r[   r\   c                    K   | j                         }| j                         }| j                         t        d      g}|j	                  |||       d{    |j                  ||       d{   |k(  sJ y7 $7 wrB   )r   r   r"   r   rZ   rV   rC   s        r   rE   z?AsyncCacheTestSuite.test_update_cache_with_multiple_generations   s}      '')//1
&&(56
 mmFJ<<<]]6:66+EEE 	=6s$   AA>A:A>/A<0A><A>rF   r   r   r   rO   rO   l   s     ^^Y   ,3 ,2s 2
z 

y 
T 
GY G4 G	
) 	
 	
?I ?$ ?
9 
 
G) G GFF	Fr   rO   )rJ   abcr   rK   langchain_core.cachesr   langchain_core.outputsr   langchain_tests.baser   r	   rO   r   r   r   <module>rg      s<      + - 2W?* W?t^F+ ^Fr   