o
    3Ih                     @   sd  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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   s2    t jdrtd t } | V  |   d S )NCHROMA_INTEGRATION_TEST_ONLYIntegration test only)osenvirongetpytestskipchromadbEphemeralClientclear_system_cacheclient r   Y/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/chromadb/test/test_client.pyephemeral_api   s   
r   c                  c   s>    t jdrtd tjt d d} | V  | 	  d S )Nr
   r   z/test_server)path)
r   r   r   r   r   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 )N)asyncioget_event_looprun_until_completer   AsyncHttpClient)r"   r#   clsr   r   r   factory0   s   z!http_api_factory.<locals>.factory)paramr   r   
HttpClientr   r   HttpAPIFactory)r!   r)   r   r   r   http_api_factory$   s"   



"

"r-   c                 c   sF    t jdd urtt jd}| |d}n|  }|V  |  d S )NCHROMA_SERVER_HTTP_PORT)port)r   r   r   intr   )r-   r/   r   r   r   r   http_api9   s   r1   c                 C      |   }|jdu sJ d S )NFget_settingsis_persistent)r   settingsr   r   r   test_ephemeral_clientD      r7   c                 C   r2   )NTr3   )r   r6   r   r   r   test_persistent_clientI   r8   r9   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)r4   chroma_api_impl)r1   r6   r   r   r   test_http_clientN   s
   
r;   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)r6   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_settingsV   s   rB   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)r/   r6   ziChroma server http port provided in settings[8001] is different to the one provided in HttpClient: [8002]r=   r@   r   r   r   0test_http_client_with_inconsistent_port_settingsb   s   rD   )r$   typingr   r   r   r   unittest.mockr   r   chromadb.configr   chromadb.apir   chromadb.server.fastapir   r   r   fixturer   r   r,   FixtureRequestr-   r1   r7   r9   r;   rB   rD   r   r   r   r   <module>   sH    


