o
    im                  
   @   s0  d dl Z d dlZd dlZd dlmZ d dlmZ d dlZddlmZ ddlm	Z	 ddlm
Z
 zd dlm
Z d d	lmZ W n eyX Z zd dlZejd
k rRedeedZ[ww ejee dZdZdZdededefddZdedefddZdedefddZdedededefddZdedefd d!Z d"d# Z!d$d% Z"d&d' Z#d(d) Z$d*d+ Z%d,d- Z&d.d/ Z'd0d1 Z(d2d3 Z)d4d5 Z*d6d7 Z+d8d9 Z,d:d; Z-ej.j/ejd<kd=d>d?d@ Z0ej.j/ejd<kd=d>dAdB Z1dCdD Z2ej.j3dEdF Z4ej.j3dGdH Z5dIdJ Z6dKdL Z7dMdN Z8dOdP Z9dQdR Z:dSdT Z;ej.j3dUdV Z<ej.j3dWdX Z=ej.j3dYdZ Z>ej.j3d[d\ Z?ej.j3d]d^ Z@ej.j3d_d` ZAej.j3dadb ZBej.j3dcdd ZCej.j3dedf ZDej.j3dgdh ZEej.j3didj ZFdkdl ZGdmdn ZHej.j3dodp ZIej.j3dqdr ZJdsdt ZKdudv ZLej.j3dwdx ZMdS )y    N)	BaseModel)ValidationError   )pytest_helper   )errors)types)ClientSession)r   
   zKMCP Tool requires Python 3.10 or above. Please upgrade your Python version.)fileglobals_for_file)pytest_asynciogemini-2.5-flash	numeratordenominatorreturnc                 C   s   | | d S )z/Divides two integers with customized math rule.    r   r   r   r   b/home/livre-enfant/venv/lib/python3.10/site-packages/google/genai/tests/chats/test_send_message.py*divide_intergers_with_customized_math_rule4   s   r   given_integerc                 C   s   | |  S )Nr   )r   r   r   r   square_integer;   s   r   powerc                 C   s   t d| rdnd  dS )zPowers the spinning disco ball.zDisco ball is z	spinning!zstopped.Tprint)r   r   r   r   power_disco_ball?   s   r   	energeticloudbpmc                 C   s   t d| d|d| dS )a  Play some music matching the specified parameters.

    Args:
      energetic: Whether the music is energetic or not.
      loud: Whether the music is loud or not.
      bpm: The beats per minute of the music.

    Returns: The name of the song being played.
    zStarting music! energetic=z loud=z, bpm=zNever gonna give you up.r   )r   r   r   r   r   r   start_musicD   s   
r    
brightnessc                 C   s   t d| d dS )zhDim the lights.

    Args:
      brightness: The brightness of the lights, 0.0 is off, 1.0 is full.
    zLights are now set to z.0%Tr   )r!   r   r   r   
dim_lightsQ   s   r"   c                 C   s   | j jtd}|d d S Nmodeltell me a story in 100 wordschatscreate
MODEL_NAMEsend_messageclientchatr   r   r   	test_textZ   s   r/   c                 C   s&   | j jtd}|tjjdd d S Nr$   r&   textr(   r)   r*   r+   r   Part	from_textr,   r   r   r   	test_parta   s   r6   c                 C   s4   | j jtd}|tjjddtjjddg d S Nr$   ztell me a US cityr1   zthe city is in west coastr3   r,   r   r   r   
test_partsh   s   r8   c                 C   s    | j jtd}|d|g d S )Nr$   what is the image about?r'   )r-   
image_jpegr.   r   r   r   
test_imager   s   r;   c                 C   s   | j jtddddid}|d}d}|jr+|jD ]}|jjD ]	}|jr)d} nq q|s/J |d}d}|jrM|jD ]}|jjD ]	}|jrKd} nqBq<|sQJ d	S )
CTests that the thinking budget is respected and generates thoughts.thinking_configT'  include_thoughtsthinking_budgetr%   config1what is the sum of natural numbers from 1 to 100?F/can you help me to understand the logic better?N)r(   r)   r*   r+   
candidatescontentpartsthought)r-   r.   	response1has_thought1	candidatepart	response2has_thought2r   r   r   test_thinking_budget|   sD   	

rP   c                 C   s   | j jtddddid}d}|dD ]}|jr-|jD ]}|jjD ]	}|jr+d} nq"qq|s2J d}|dD ]}|jrR|jD ]}|jjD ]	}|jrPd} nqGqAq9|sWJ d	S )
r<   r=   Tr>   r?   rB   FrD   rE   N)r(   r)   r*   send_message_streamrF   rG   rH   rI   )r-   r.   rK   chunkrL   rM   rO   r   r   r   test_thinking_budget_stream   sD   	

rS   c                 C   \   | j jtd}t| tj |dtj	j
dddg W d    d S 1 s'w   Y  d S )Nr$   r9   z5gs://unified-genai-dev/imagen-inputs/google_small.png	image/pngfile_uri	mime_type)r(   r)   r*   r   exception_if_mldevr   ClientErrorr+   r   r4   from_urir,   r   r   r   test_google_cloud_storage_uri      "r\   c                 C   rT   )Nr$   r9   zChttps://generativelanguage.googleapis.com/v1beta/files/az606f58k7zjrU   rV   )r(   r)   r*   r   exception_if_vertexr   rZ   r+   r   r4   r[   r,   r   r   r   test_uploaded_file_uri   r]   r_   c                 C   s`   ddi}| j jt|d}ddi}|jd|d}|d}t|jdks%J t|jdks.J d S Ncandidate_countr   rB   r   r&   rC   )r(   r)   r*   r+   lenrF   r-   chat_configr.   request_configrequest_config_responsedefault_config_responser   r   r   test_config_override   s   ri   c                 C   sf   t jdt jjddgdt jdt jjddgdg}| jjt|d}|d t|	 d	ks1J d S 
Nuserzdefine a=5, b=10r1   )rolerH   r%   z Hello there! how can I help you?)r%   historyzwhat is a + b?r   )
r   Contentr4   r5   r(   r)   r*   r+   rc   get_historyr-   rm   r.   r   r   r   test_history   s   	
rq   c                 C   s&   | j jtd}|d |d d S Nr$   z9write a python function to check if a year is a leap yearz"write a unit test for the functionr'   r,   r   r   r   test_send_2_messages   s   
rs   c                 C   s&  | j jddtgid}|d}| }t|dksJ |d jdks%J |d jd jdks1J |d jd	ks:J |d jd j	j
d
ksGJ |d jd j	jdddksWJ |d jdks`J |d jd jj
d
ksmJ |d jd jjddiks|J |d jd	ksJ d|d jd jv sJ d S Ngemini-2.0-flash-exptoolsrB   what is the result of 100/2?   r   rk   r   r%   r   d   r   r   result3   r   51)r(   r)   r   r+   ro   rc   rl   rH   r2   function_callnameargsfunction_responseresponser-   r.   _chat_historyr   r   r   test_with_afc_history  s0   
r   c                 C   st   | j jddtgid}|d}|d}|d}| }g }|D ]	}||  q"t|tt|ks8J d S )Nru   rv   rB   helloz&could you help me with a math problem?rw   )	r(   r)   r   r+   ro   appendmodel_dump_jsonrc   set)r-   r.   r   r   content_stringsrG   r   r   r   .test_existing_chat_history_extends_afc_history%  s   


r   )r      zVobject type is dumped as <Type.OBJECT: "OBJECT"> as opposed to "OBJECT" in Python 3.13)reasonc                 C   Z  t ttg}|dddiiddid}| jjt|d}|d | }t|d	ks*J |d
 j	dks3J |d
 j
d
 jdks?J |d j	dksHJ t|d j
dksSJ |d j
D ]}|js_J qX|d j	dksiJ t|d j
dkstJ |d j
D ]}|jsJ qy|d j	dksJ t|d j
dksJ |d j
D ]}|jsJ q|d j	dksJ t|d j
dksJ |d j
D ]}|jsJ q|d j	dksJ t|d j
dksJ |d j
D ]}|jsJ q|d j	dksJ t|d j
dksJ |d j
D ]}|jsJ q|d j	dksJ t|d j
dksJ |d j
D ]	}|js)J q!d S Nfunction_calling_configmodeANYmaximum_remote_callsr   )rv   tool_configautomatic_function_callingrB   zTurn this place into a party!   r   rk   r   r%   r   rx            r   r    r"   r(   r)   r*   r+   ro   rc   rl   rH   r2   r}   r   r-   	house_fnsrC   r.   curated_historyrM   r   r   r   #test_with_afc_multiple_remote_calls6  X   
	
r   c                 C   r   r   r   r   r   r   r   )test_with_afc_multiple_remote_calls_asyncq  r   r   c                 C   s   | j jdtgddidd}|d | }t|dksJ |d jd	ks(J |d jd jdks4J |d
 jdks=J |d
 jd j	j
dksJJ |d
 jd j	jddiksYJ d S Nru   disableT)rv   r   rB   zDo the square of 3.r   r   rk   r   r%   r   r   r   )r(   r)   r   r+   ro   rc   rl   rH   r2   r}   r~   r   r-   r.   r   r   r   r   test_with_afc_disabled  s$   r   c                    s0  | j jjddtgid}|dI d H }| }t|dks!J |d jdks*J |d jd j	dks6J |d jd	ks?J |d jd j
jd
ksLJ |d jd j
jdddks\J |d jdkseJ |d jd jjd
ksrJ |d jd jjddiksJ |d jd	ksJ d|d jd j	v sJ d S rt   )aior(   r)   r   r+   ro   rc   rl   rH   r2   r}   r~   r   r   r   r   r   r   r   test_with_afc_history_async  s2   r   c                    s   | j jjdtgddidd}|dI d H  | }t|dks$J |d jd	ks-J |d jd j	dks9J |d
 jdksBJ |d
 jd j
jdksOJ |d
 jd j
jddiks^J d S r   )r   r(   r)   r   r+   ro   rc   rl   rH   r2   r}   r~   r   r   r   r   r   test_with_afc_disabled_async  s&   
r   c                 C   s:   | j jtd}d}|dD ]}|d7 }q|dksJ d S Nr$   r   r&   r   r(   r)   r*   rQ   r-   r.   chunksrR   r   r   r   test_stream_text  s   
r   c                 C   sD   | j jtd}d}|tjjddD ]}|d7 }q|dks J d S Nr$   r   r&   r1   r   r(   r)   r*   rQ   r   r4   r5   r   r   r   r   test_stream_part	  s   
r   c                 C   sR   | j jtd}d}|tjjddtjjddgD ]}|d7 }q|dks'J d S )Nr$   r   r&   r1   the story is about a carr   r   r   r   r   r   r   test_stream_parts  s   
r   c                 C   s   ddi}| j jt|d}ddi}d}|jd|dD ]}||j7 }qd}|dD ]}||j7 }q(t|s7J ttj	 t| W d    d S 1 sNw   Y  d S )Nresponse_mime_type
text/plainrB   application/json r&   rb   )
r(   r)   r*   rQ   r2   jsonloadspytestraisesJSONDecodeErrorr-   re   r.   rf   request_config_textrR   default_config_textr   r   r   test_stream_config_override"  s   
"r   c                 C   s   | j jddtgid}|dD ]}q|dD ]}q| }|d jdks(J |d jd jdks4J |d jd	ks=J |d jd jj	d
ksJJ |d jd jj
dddksZJ d S Nru   rv   rB   rw   zwhat is the result of 50/2?r   rk   r   r%   r   ry   r   r   )r(   r)   r   rQ   ro   rl   rH   r2   r}   r~   r   r-   r.   rR   r   r   r   r   test_stream_function_calling4  s.   r   c                 C   s2   | j jtd}|dD ]}q|dD ]}qd S rr   r   r-   r.   rR   r   r   r   test_stream_send_2_messagesR  s   r   c                    s&   | j jjtd}|dI d H  d S r#   )r   r(   r)   r*   r+   r,   r   r   r   test_async_text]  s   r   c                    s0   | j jjtd}|tjjddI d H  d S r0   r   r(   r)   r*   r+   r   r4   r5   r,   r   r   r   test_async_partc  s   r   c                    s>   | j jjtd}|tjjddtjjddgI d H  d S r7   r   r,   r   r   r   test_async_partsi  s   r   c                    sp   ddi}| j jjt|d}ddi}|jd|dI d H }|dI d H }t|jdks-J t|jdks6J d S r`   )r   r(   r)   r*   r+   rc   rF   rd   r   r   r   test_async_config_overridet  s   
r   c                    sp   t jdt jjddgdt jdt jjddgdg}| jjjt|d}|dI d H  t	|
 d	ks6J d S rj   )r   rn   r4   r5   r   r(   r)   r*   r+   rc   ro   rp   r   r   r   test_async_history  s   	r   c                    sN   | j jjtd}d}|dI d H 2 z
3 d H W }|d7 }q6 |dks%J d S r   r   r(   r)   r*   rQ   r   r   r   r   test_async_stream_text  s   
r   c                    sX   | j jjtd}d}|tjjddI d H 2 z
3 d H W }|d7 }q6 |dks*J d S r   r   r(   r)   r*   rQ   r   r4   r5   r   r   r   r   test_async_stream_part  s   
r   c                    sf   | j jjtd}d}|tjjddtjjddgI d H 2 z
3 d H W }|d7 }q6 |dks1J d S )Nr$   r   r&   r1   r   r   r   r   r   r   r   test_async_stream_parts  s   
r   c                    s   ddi}| j jjt|d}ddi}d}|jd|dI d H 2 z3 d H W }||j7 }q6 d}|dI d H 2 z3 d H W }||j7 }q56 t|sIJ t	| tj
 t| W d    d S 1 saw   Y  d S )	Nr   r   rB   r   r   r&   rb   z*tell me family friendly story in 100 words)r   r(   r)   r*   rQ   r2   r   r   r   rY   r   r   r   r   r   !test_async_stream_config_override  s$   "r   c                    s   | j jjddtgid}|dI d H 2 z3 d H W }q6 |dI d H 2 z3 d H W }q%6 | }|d jdks:J |d jd jdksFJ |d jd	ksOJ |d jd j	j
d
ks\J |d jd j	jdddkslJ d S r   )r   r(   r)   r   rQ   ro   rl   rH   r2   r}   r~   r   r   r   r   r   "test_async_stream_function_calling  s,   r   c                    sV   | j jjtd}|dI d H 2 z3 d H W }q6 |dI d H 2 z3 d H W }q!6 d S rr   r   r   r   r   r   !test_async_stream_send_2_messages  s   r   c              
   C   sH   | j jddtjddddddiid	d
gid}|d}|d}d S Nru   rv   get_weatherzGet the weather in a city.objectlocationtypestring)r   
properties)r~   descriptioninputSchemarB   zWhat is the weather in Boston?z%What is the weather in San Francisco?)r(   r)   	mcp_typesToolr+   r-   r.   r   r   r   r   test_mcp_tools  s   

r   c              
   C   sT   | j jddtjddddddiid	d
gid}|dD ]}q|dD ]}q%d S r   )r(   r)   r   r   rQ   r   r   r   r   test_mcp_tools_stream  s*   
r   c              
      sX   | j jjddtjddddddiid	d
gid}|dI d H  |dI d H  d S r   )r   r(   r)   r   r   r+   r,   r   r   r   test_async_mcp_tools   s   
r   c              
      sx   | j jjddtjddddddiid	d
gid}|dI d H 2 z3 d H W }q"6 |dI d H 2 z3 d H W }q26 d S r   )r   r(   r)   r   r   rQ   r   r   r   r   test_async_mcp_tools_stream3  s.   
r   c              
   C   st   t | t* | jjdddddddidd	d
gigid}|d}|d}W d    d S 1 s3w   Y  d S Nr   rv   mcp_serversweather_serverz-https://gemini-api-demos.uc.r.appspot.com/mcpAUTHORIZATIONzBearer github_pat_XXXX10s)urlheaderstimeout)r~   streamable_http_transportrB   z,What is the weather in Boston on 02/02/2026?z3What is the weather in San Francisco on 02/02/2026?)r   r^   
ValueErrorr(   r)   r+   r   r   r   r   test_server_side_mcp_toolsN  s,   
"r   c              
   C   s   t | t0 | jjdddddddidd	d
gigid}|dD ]}q#|dD ]}q+W d    d S 1 s9w   Y  d S r   )r   r^   r   r(   r)   rQ   r   r   r   r   !test_server_side_mcp_tools_streamm  s6   "r   c              
      s   t | t1 | jjjdddddddidd	d
gigid}|dI d H  |dI d H  W d    d S 1 s;w   Y  d S r   )r   r^   r   r   r(   r)   r+   r,   r   r   r    test_async_server_side_mcp_tools  s.   "r   )Nr   ossyspydanticr   r   r   r   r   r   r   mcpr   r	   McpClientSessionImportErroreversion_infosetup__file__globals
pytestmarkpytest_pluginsr*   intr   r   boolr   strr    floatr"   r/   r6   r8   r;   rP   rS   r\   r_   ri   rq   rs   r   r   markskipifr   r   r   asyncior   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s   

	

$$!
4
3
!







	






#