o
    Yi                     @   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.)Z	addoption)parser r   U/home/kim/smarthome/.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 )NZPYTEST_CURRENT_TESTz:: r   [.vertexmldev/)osenvirongetsplitjoin)r   r   Ztest_name_endingZ	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   Z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-keyZGOOGLE_API_KEYzcredentials.jsonZGOOGLE_APPLICATION_CREDENTIALSz
project-idZGOOGLE_CLOUD_PROJECTlocationZGOOGLE_CLOUD_LOCATIONz8../../../../../google/cloud/aiplatform/sdk/genai/replaysZGOOGLE_GENAI_REPLAYS_DIRECTORYr   )mode	replay_idvertexaihttp_optionsprivateZ_get_api_client)r-   )configZ	getoption
ValueErrorfunction__name__r    pathsplitextbasename
startswithr%   r!   r$   dirname__file__abspathr   ZReplayApiClientr   patchobjectgoogle_genai_client_moduleZClientreturn_valueZ_api_clientclose)r   r   r.   requestr+   Ztest_function_nameZtest_filenamewordr,   Zreplays_root_directoryr/   Zreplay_clientZpatch_methodZ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 )NZtimestamped_unique_nameZ20240101000000_bd656)r>   )r   r;   r<   r   )Zunique_name_mockr   r   r   mock_timestamped_unique_name   s   "rB   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Z	PIL.Imager    r4   r$   r8   r9   ZImageopenZPILZ
image_pathZimgr   r   r   
image_jpeg      "rH   c                  c   rC   )Nr   rD   z
google.pngrE   rG   r   r   r   	image_png   rI   rJ   )__doc__datetimer    Zunittestr   uuidZpytest r   r   r   r=   r   Zfixturer   r   boolstrr%   rB   rH   rJ   r   r   r   r   <module>   s.   



@
	
