o
    gR                     @   s\  d dl Z d dlmZ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Zd dlZd dlZejdeeddf fddZejdeeddf fd	d
Zedef Zejddgddejdeeddf fddZe dedeeddf fddZdeddfddZd
eddfddZdeddfddZdeddfddZdeddfddZdS )    N)AnyCallable	Generatorcast)patch)Settings)	ClientAPIreturnc                  c   s    t  } | V  |   d S N)chromadbEphemeralClientclear_system_cacheclient r   P/var/www/visachat/venv/lib/python3.10/site-packages/chromadb/test/test_client.pyephemeral_api   s   r   c                  c   s(    t jt d d} | V  |   d S )Nz/test_server)path)r   PersistentClienttempfile
gettempdirr   r   r   r   r   persistent_api   s   
r   .sync_clientasync_client)paramsrequestc              	   c   s   | j dkr=td) td tjV  W d    n1 sw   Y  W d    d S W d    d S 1 s6w   Y  d S td6 td dtdtdtfd	d
}tt|V  W d    n1 sbw   Y  W d    d S W d    d S 1 szw   Y  d S )Nr   z4chromadb.api.client.Client._validate_tenant_databasez,chromadb.api.client.Client.get_user_identityz?chromadb.api.async_client.AsyncClient._validate_tenant_databasez7chromadb.api.async_client.AsyncClient.get_user_identityargskwargsr	   c                  _   s   t  tj| i |}|S r
   )asyncioget_event_looprun_until_completer   AsyncHttpClient)r   r   clsr   r   r   factory+   s   z!http_api_factory.<locals>.factory)paramr   r   
HttpClientr   r   HttpAPIFactory)r   r#   r   r   r   http_api_factory   s"   



"

"r'   c                 c   s    |  }|V  |   d S r
   )r   )r'   r   r   r   r   http_api4   s   r(   c                 C      |   }|jdu sJ d S )NFget_settingsis_persistent)r   settingsr   r   r   test_ephemeral_client;      r.   c                 C   r)   )NTr*   )r   r-   r   r   r   test_persistent_client@   r/   r0   c                 C   s(   |   }|jdks|jdksJ d S d S )Nzchromadb.api.fastapi.FastAPIz'chromadb.api.async_fastapi.AsyncFastAPI)r+   chroma_api_impl)r(   r-   r   r   r   test_http_clientE   s
   
r2   c              
   C   sN   z| t ddd W d S  ty& } zt|dksJ W Y d }~d S d }~ww )Nz	127.0.0.1)chroma_server_host)r-   znChroma server host provided in settings[127.0.0.1] is different to the one provided in HttpClient: [localhost]r   
ValueErrorstrr'   er   r   r   0test_http_client_with_inconsistent_host_settingsM   s   r9   c              
   C   sP   z| dt ddd W d S  ty' } zt|dksJ W Y d }~d S d }~ww )NiB  iA  )chroma_server_http_port)portr-   ziChroma server http port provided in settings[8001] is different to the one provided in HttpClient: [8002]r4   r7   r   r   r   0test_http_client_with_inconsistent_port_settingsY   s   r<   )r   typingr   r   r   r   unittest.mockr   r   chromadb.configr   chromadb.apir   chromadb.server.fastapipytestr   fixturer   r   r&   FixtureRequestr'   r(   r.   r0   r2   r9   r<   r   r   r   r   <module>   sF    
