o
    _i                     @   s   d Z ddlZddlZddlmZ ddlZddlZddlmZ ddlm	Z	 ddlm
Z dd	 Zejd
d Zejdd ZdededefddZejdd Z
ejdd Zejdd Zejdd ZdS )z Conftest for google.genai tests.    N)mock   )_common)_replay_api_client)clientc                 C   s(   | j ddddd | j dddd	d d S )
N--modestoreautoae  Replay mode.
  One of:
  * auto: Replay if replay files exist, otherwise record.
  * record: Always call the API and record.
  * replay: Always replay, fail if replay files do not exist.
  * api: Always call the API and do not record.
  * tap: Always replay, fail if replay files do not exist. Also sets default values for the API key and replay directory.
)actiondefaulthelp	--private
store_trueFzRun private tests.)	addoption)parser r   T/home/air/demo/back/venv/lib/python3.10/site-packages/google/genai/tests/conftest.pypytest_addoption   s   
r   c                   C      dS )NFr   r   r   r   r   
use_vertex5      r   c                   C   r   )Ntestr   r   r   r   r   replays_prefix;   r   r   returnc                 C   sL   t jddd }|dd dd d | rdnd	 }d
||gS )NPYTEST_CURRENT_TESTz:: r   [.vertexmldev/)osenvirongetsplitjoin)r   r   test_name_ending	test_namer   r   r   _get_replay_id@   s   
r)   c                 c   sp   |j d}|dvrtd| |jj}tjtj|jd }|	|r/td| ddD ]}||v r?td| d	q1t
| |}|d
kr|d}dtjd< tjtjtdtjd< dtjd< dtjd< tjtjtjtd}	|	tjd< |j d}
tj||| ||
d}tjtjd}||_tj| d}|V  |j  W d    d S 1 sw   Y  d S )Nr   )r	   recordreplayapitapzInvalid mode: r   z
      zl:
      Do not include the test filename in the test function name.
      keep the test function name short.)r    ml_devr   z	
        z:
        You should never ever include api types in the file name (mldev or vertex).
        All tests should run against all apis.
        Assert an exception if the test is not supported in an API.r-   r+   zdummy-api-keyGOOGLE_API_KEYzcredentials.jsonGOOGLE_APPLICATION_CREDENTIALSz
project-idGOOGLE_CLOUD_PROJECTlocationGOOGLE_CLOUD_LOCATIONz8../../../../../google/cloud/aiplatform/sdk/genai/replaysGOOGLE_GENAI_REPLAYS_DIRECTORYr   )mode	replay_idvertexaihttp_optionsprivate_get_api_client)r7   )config	getoption
ValueErrorfunction__name__r"   pathsplitextbasename
startswithr)   r#   r&   dirname__file__abspathr   ReplayApiClientr   patchobjectgoogle_genai_client_moduleClientreturn_value_api_clientclose)r   r   r8   requestr5   test_function_nametest_filenamewordr6   replays_root_directoryr9   replay_clientpatch_methodgoogle_genai_clientr   r   r   r   J   sd   










"r   c                  c   s@    t jjtddd} | V  W d    d S 1 sw   Y  d S )Ntimestamped_unique_name20240101000000_bd656)rL   )r   rH   rI   r   )unique_name_mockr   r   r   mock_timestamped_unique_name   s   "rZ   c                  c   Z    dd l } tjtjtdd}| j|}|V  W d    d S 1 s&w   Y  d S )Nr   dataz
google.jpg	PIL.Imager"   r@   r&   rD   rE   ImageopenPIL
image_pathimgr   r   r   
image_jpeg      "re   c                  c   r[   )Nr   r\   z
google.pngr]   ra   r   r   r   	image_png   rf   rg   )__doc__datetimer"   unittestr   uuidpytest r   r   r   rJ   r   fixturer   r   boolstrr)   rZ   re   rg   r   r   r   r   <module>   s.   



@
	
