
    ug                     ,   d dl Z d dlZd dlmZmZ d dlZd dlmZ d dlm	Z	m
Z
 ej                  j                  dg d       ed       ej                  e j                  i d	      d
ededdfd                     Z ed       ej                  e j                  i d	      deddfd              Zej                  j                  dddg       ed       ed       ej                  e j                  i d	      dedededdfd                            Zy)    N)patch	MagicMock)SqliteDB)SystemSettingsmigrations_hash_algorithm)Nmd5sha256chromadb.api.fastapi.FastAPIT)clearapi_mockreturnc                 v   |r$t         j                  j                  ddd|      }n"t         j                  j                  ddd      }t        j                  |      }| j                  sJ | j
                  \  }}|r|d   nd}|xs d}|sJ t        |j                  d	d      |k(  sJ |j                          y)
zq
    Ensure that when no hash algorithm or a valid one is provided, the client is set up
    with that value
    r   T./foo)chroma_api_implis_persistentpersist_directoryr   )r   r   r   r   Nr	   r   )	chromadbconfigr   Clientcalled	call_argsgetattrsettingsclear_system_cache)r   r   r   clientargskwargspassed_settings"expected_migrations_hash_algorithms           O/var/www/openai/venv/lib/python3.12/site-packages/chromadb/test/db/test_hash.py"test_settings_valid_hash_algorithmr"   
   s     !??++:%&?	 , 
 ??++:% , 
 __X&F ??? %%LD&!%d1g4O *C)Ke&?((*EtL-	.	.     mockc                     t        j                  t              5  t        j                  j                  ddd      }t        j                  |       ddd       | j                  rJ y# 1 sw Y   xY w)zn
    Ensure that providing an invalid hash results in a raised exception and the client
    is not called
    r   invalid_hash_algr   )r   r   r   N)pytestraises	Exceptionr   r   r   r   r   )r$   r   s     r!   $test_settings_invalid_hash_algorithmr*   8   s^     
y	!??++:&8% , 
 	! 
" {{?{ 
"	!s   8A))A2r	   r
   z0chromadb.db.migrations.verify_migration_sequencezchromadb.db.migrations.hashlibhashlib_mockverify_migration_sequence_mockc           	         t        t        t        dd|                  }t               |_        t               |_        dg|_        |j                          |j                  j                  sJ |xs d}|dk(  r1| j                  j                  sJ | j                  j                  rJ y|dk(  r1| j                  j                  rJ | j                  j                  sJ yJ )zE
    Test that only the appropriate hashlib functions are called
    applyT)
migrationsallow_resetr   unapplied_migrationr	   r
   N)r   r   r   r   apply_migrationr   return_valuestartr   r	   r
   )r+   r,   r   dbr    s        r!   test_hashlib_algr6   K   s     
" *C	

B #BBI
 4I2I"/HHJ$$$$ *C)Ke& *U2&&&&&&-----	+x	7##****"")))) 	ur#   )osr'   unittest.mockr   r   r   chromadb.db.impl.sqliter   chromadb.configr   r   markparametrizedictenvironstrr"   r*   r6    r#   r!   <module>rA      sK   	  *  , , 46MN%&BJJ$'( ( 47( 	(  ( ' O( V %&BJJ$'y T  ( '" 4uh6GH9:'(BJJ$'++$-+  #+ 
	+ ( ) ; I+r#   