o
    hP                     @  sZ  U d 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 ddlm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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 ddlmZ dZded< dZded< dZ ded< G dd deZ!dsdtd d!Z"dud#d$Z#dvd&d'Z$dwd*d+Z%dxd/d0Z&dxd1d2Z'dxd3d4Z(dxd5d6Z)dyd8d9Z*dyd:d;Z+dyd<d=Z,dyd>d?Z-dzdAdBZ.	Cd{d|dIdJZ/	d}d~dNdOZ0	d}ddPdQZ1	d}ddSdTZ2	d}ddVdWZ3	d}ddYdZZ4	d}dd[d\Z5	d}dd]d^Z6	d}dd_d`Z7	d}ddadbZ8ddfdgZ9	d}ddidjZ:d~dkdlZ;d}ddodpZ<ddqdrZ=dS )z"Utilities for assertion debugging.    )annotationsN)Callable)Iterable)Mapping)Sequence)Set)Any)Literal)Protocol)	normalize)outcomes)PrettyPrinter)saferepr)saferepr_unlimited)Configz2Callable[[str, object, object], str | None] | None_reprcomparez&Callable[[int, str, str], None] | None_assertion_passzConfig | None_configc                   @  s   e Zd Zd
dddZd	S )_HighlightFuncpythonsourcestrlexerLiteral['diff', 'python']returnc                 C  s   dS )z'Apply highlighting to the given source.N )selfr   r   r   r   W/var/www/html/openai_agents/venv/lib/python3.10/site-packages/_pytest/assertion/util.py__call__*   s    z_HighlightFunc.__call__Nr   r   r   r   r   r   r   )__name__
__module____qualname__r   r   r   r   r   r   )   s    r   r   r   r   r   r   r   c                 C  s   | S )zDummy highlighter that returns the text unprocessed.

    Needed for _notin_text, as the diff gets post-processed to only show the "+" part.
    r   )r   r   r   r   r   dummy_highlighter.   s   r$   explanationc                 C  s   t | }t|}d|S )a  Format an explanation.

    Normally all embedded newlines are escaped, however there are
    three exceptions: \n{, \n} and \n~.  The first two are intended
    cover nested explanations, see function and attribute explanations
    for examples (.visit_Call(), visit_Attribute()).  The last one is
    for when one explanation needs to span multiple lines, e.g. when
    displaying diffs.
    
)_split_explanation_format_linesjoin)r%   linesresultr   r   r   format_explanation6   s   

r,   	list[str]c                 C  s^   | pd d}|d g}|dd D ]}|r"|d dv r"|| q|d  d| 7  < q|S )	zReturn a list of individual lines in the explanation.

    This will return a list of lines split on '\n{', '\n}' and '\n~'.
    Any other newlines will be escaped and appear in the line as the
    literal '\n' characters.
     r&   r      N){}~>z\n)splitappend)r%   	raw_linesr*   valuesr   r   r   r'   E   s   
r'   r*   Sequence[str]c                 C  sB  t | dd }dg}dg}| dd D ]}|drN|d r"d}nd}|t| |d  d7  < |d |dd	t|d   | |dd   q|d
rj|  |  ||d   |dd 7  < q|d dv srJ |d  d7  < |drt|nt|d }|d	| |dd   qt|dksJ |S )a  Format the individual lines.

    This will replace the '{', '}' and '~' characters of our mini formatting
    language with the proper 'where ...', 'and ...' and ' + ...' text, taking
    care of indentation along the way.

    Return a list of formatted lines.
    Nr/   r   r0   r4   zand   zwhere z +  r1   )r2   r3   r2   )list
startswithr6   lenpop)r*   r+   stackstackcntlinesindentr   r   r   r(   V   s,   	

,
r(   xr   boolc                 C  s   t | tjjot | t S N)
isinstancecollectionsabcr   r   rD   r   r   r   
issequencey      rK   c                 C  
   t | tS rF   )rG   r   rJ   r   r   r   istext}      
rN   c                 C  rM   rF   )rG   dictrJ   r   r   r   isdict   rO   rQ   c                 C  s   t | ttfS rF   )rG   set	frozensetrJ   r   r   r   isset   s   rT   objc                 C  s   t | tot| dd d uS )N_fields)rG   tuplegetattrrU   r   r   r   isnamedtuple   rL   rZ   c                 C     t | dd d uS )N__dataclass_fields__rX   rY   r   r   r   	isdatacls      r^   c                 C  r[   )N__attrs_attrs__r]   rY   r   r   r   isattrs   r_   ra   c                 C  s*   z
t |  t|  W S  ty   Y dS w )NF)iterrN   	ExceptionrY   r   r   r   
isiterable   s   rd   objectc                 C  s@   t | jdrt | jjdr| jjj}t| rd|v S |dkS dS )a  Check if an instance of an object contains the default eq

    First, we check if the object's __eq__ attribute has __code__,
    if so, we check the equally of the method code filename (__code__.co_filename)
    to the default one generated by the dataclass and attr module
    for dataclasses the default co_filename is <string>, for attrs class, the __eq__ should contain "attrs eq generated"
    __code__co_filenamezattrs generated z<string>T)hasattr__eq__rf   rg   ra   )rU   code_filenamer   r   r   has_default_eq   s   
rk   Fopleftright	use_asciilist[str] | Nonec                 C  s  |  tj}t|tot|totd|td|k}|dkr+t||d}t||d}ndt| d d }t|||d}t|||d}| d| d| }	| 	 j
}
d}z|d	krat|||
|}nr|d
krtt|rst|rst|||}n_|dkrt|rt|rdg}nO|dkrt|rt|rt|||
|}n;|dkrt|rt|rt|||
|}n'|dkrt|rt|rt|||
|}n|dkrt|rt|rt|||
|}W n! tjy     ty   tjj  }d| ddg}Y nw |sdS |d dkrdg|}|	g|S )z<Return specialised explanations for some operators/operands.NFDr/   )ro   A      )maxsizero    Nz==znot inz!=Both sets are equalz>=z<=r3   <z<(pytest_assertion plugin: representation of details failed: .z+ Probably an object has a faulty __repr__.)r   r.   )get_verbosityr   VERBOSITY_ASSERTIONSrG   r   r   r   r=   r   get_terminal_writer
_highlight_compare_eq_anyrN   _notin_textrT   _compare_gte_set_compare_lte_set_compare_gt_set_compare_lt_setr   Exitrc   _pytest_codeExceptionInfofrom_current_getreprcrash)configrl   rm   rn   ro   verbose	left_repr
right_reprrt   summaryhighlighterr%   
repr_crashr   r   r   assertrepr_compare   sr   




r   r   r   intc           	      C  s8  g }t | rt |rt| |||}|S ddlm} t| |s#t||r;t| |r*| n|}t| |r3|n| }||}nKt| t|u rWt| sOt| sOt	| rWt
| |||}n/t| rgt|rgt| |||}nt| rwt|rwt| |||}nt| rt|rt| |||}t| rt|rt| |||}|| |S )Nr   )
ApproxBase)rN   
_diff_text_pytest.python_apir   rG   _repr_comparetyper^   ra   rZ   _compare_eq_clsrK   _compare_eq_sequencerT   _compare_eq_setrQ   _compare_eq_dictrd   _compare_eq_iterableextend)	rm   rn   r   r   r%   r   approx_side
other_sideexplr   r   r   r}      s6   
r}   c                 C  sl  ddl m} g }|dk r}d}ttt| t|D ]}| | || kr% nq|dkrA|d8 }d| dg}| |d } ||d }t| t|kr}tt| D ]}| |  ||  kr] nqO|dkr}|d8 }|d| d	g7 }| d|  } |d|  }d
}|  s| rtt| } tt|}|dg7 }||d	dd ||
|| 
|D dd
  |S )zReturn the explanation for the diff between text.

    Unless --verbose is used this will skip leading and trailing
    characters which are identical to keep the diff minimal.
    r   )ndiffr/   *   
   z	Skipping z5 identical leading characters in diff, use -v to showNz6 identical trailing characters in diff, use -v to showTz;Strings contain only whitespace, escaping them using repr()r&   c                 s  s    | ]}| d V  qdS )r&   N)strip.0rA   r   r   r   	<genexpr>J  s
    
z_diff_text.<locals>.<genexpr>diffr   )difflibr   rangeminr=   isspacereprr   r   r)   
splitlines)rm   rn   r   r   r   r%   ikeependsr   r   r   r     sR   



	r   Iterable[Any]c              
   C  sv   |dkr
t  s
dgS dd l}t |  }t | }ddg}||ddd |||D dd	  |S )
Nr   zUse -v to get more diffr.   z
Full diff:r&   c                 s  s    | ]}|  V  qd S rF   )rstripr   r   r   r   r   g  s
    
z'_compare_eq_iterable.<locals>.<genexpr>r   r   )running_on_cir   r   pformatr   r   r)   r   )rm   rn   r   r   r   left_formattingright_formattingr%   r   r   r   r   T  s    

	r   Sequence[Any]c                 C  s>  t | to	t |t}g }t| }t|}tt||D ]=}| | || krX|r8| ||d  }	|||d  }
n| | }	|| }
|d| d|t|	 d|t|
   nq|r]|S || }|r|dkrpd}t| | }nd| }d}t|| }|dkr|| d|| g7 }|S || d	| d
|| g7 }|S )Nr/   z	At index z diff:  != r   LeftRightz contains one more item: z
 contains z more items, first extra item: )rG   bytesr=   r   r   r6   r   r   )rm   rn   r   r   comparing_bytesr%   len_left	len_rightr   
left_valueright_valuelen_diffdir_with_moreextrar   r   r   r   q  sN   	

r   AbstractSet[Any]c                 C  s0   g }| td| || | td|| | |S )Nrm   rn   )r   _set_one_sided_diffrm   rn   r   r   r%   r   r   r   r     s   r   c                 C     t | ||}|sdgS |S Nrv   )r   r   r   r   r   r        r   c                 C  r   r   )r   r   r   r   r   r     r   r   c                 C  s   t d|| |S )Nrn   r   rm   rn   r   r   r   r   r   r        r   c                 C  s   t d| ||S )Nrm   r   r   r   r   r   r     r   r   posnset1set2c                 C  sB   g }|| }|r| d|  d |D ]}| |t| q|S )NzExtra items in the z set:)r6   r   )r   r   r   r   r%   r   itemr   r   r   r     s   r   Mapping[Any, Any]c                   s  g }t  }t }||} fdd|D }|r+|dk r+|dt| dg7 }n|r=|dg7 }||t| 7 } fdd|D }	|	rl|d	g7 }|	D ]}
||t|
 |
 id
 |t|
|
 i g7 }qP|| }t|}|r|d| d|dkrdnd d ||t fdd|D   || }t|}|r|d| d|dkrdnd d ||tfdd|D   |S )Nc                   s&   i | ]} | | kr| | qS r   r   r   krm   rn   r   r   
<dictcomp>  s   & z$_compare_eq_dict.<locals>.<dictcomp>rs   	Omitting ! identical items, use -vv to showzCommon items:c                   s    h | ]} | | kr|qS r   r   r   r   r   r   	<setcomp>  s     z#_compare_eq_dict.<locals>.<setcomp>zDiffering items:r   zLeft contains z
 more itemr/   r.   rB   :c                      i | ]}| | qS r   r   r   )rm   r   r   r         zRight contains c                   r   r   r   r   )rn   r   r   r     r   )	rR   intersectionr=   pprintr   r   r   r6   r   )rm   rn   r   r   r%   set_left	set_rightcommonsamer   r   
extra_leftlen_extra_leftextra_rightlen_extra_rightr   r   r   r     sP   


r   c                   s  t | sg S t| rdd l}|| }dd |D }nt| r*| j}dd |D }n
t| r2| j}nJ d g }g }|D ]}	t| |	t||	krN|	|	 q<|	|	 q<g }
|sZ|r_|
dg7 }
|rq|dk rq|
	d	t
| d
 n|r|
dg7 }
|
|t| 7 }
|r|
dg7 }
|
|t| 7 }
|D ]9}	t| |	}t||	}|
dd|	 d  |	 d|t| d|t| g7 }
|
 fddt||||D 7 }
q|
S )Nr   c                 S  s   g | ]}|j r|jqS r   )comparename)r   infor   r   r   
<listcomp>)  s    z#_compare_eq_cls.<locals>.<listcomp>c                 S  s   g | ]
}t |d r|jqS )eq)rX   r   )r   fieldr   r   r   r   ,  s    Fr:   r.   rs   r   r   zMatching attributes:zDiffering attributes:z$Drill down into differing attribute r   z: r   c                   s   g | ]} | qS r   r   r   rC   r   r   r   N  s    )rk   r^   dataclassesfieldsra   r`   rZ   rV   rX   r6   r=   r   r   r   r   r}   )rm   rn   r   r   r   
all_fieldsfields_to_checkr   r   r   r%   
field_leftfield_rightr   r   r   r      sX   






&
r   termtextc           
      C  s   | | }|d | }||t|  d  }|| }t||t|}t| dd dg}|D ]$}	|	dr4q,|	dr:q,|	drK|d|	dd    q,||	 q,|S )	Nr   )rt   z is contained here:Skippingz- z+ r:   rs   )findr=   r   r$   r   r<   r6   )
r   r   r   indexheadtailcorrect_textr   newdiffrA   r   r   r   r~   W  s   



r~   c                  C  s   ddg} t dd | D S )z0Check if we're currently running on a CI system.CIBUILD_NUMBERc                 s  s    | ]}|t jv V  qd S rF   )osenviron)r   varr   r   r   r   m  s    z running_on_ci.<locals>.<genexpr>)any)env_varsr   r   r   r   j  s   r   r   r    )r%   r   r   r   )r%   r   r   r-   )r*   r9   r   r-   )rD   r   r   rE   )rU   r   r   rE   )rU   re   r   rE   )F)
rl   r   rm   r   rn   r   ro   rE   r   rp   )r   )
rm   r   rn   r   r   r   r   r   r   r-   )
rm   r   rn   r   r   r   r   r   r   r-   )
rm   r   rn   r   r   r   r   r   r   r-   )
rm   r   rn   r   r   r   r   r   r   r-   )
rm   r   rn   r   r   r   r   r   r   r-   )
r   r   r   r   r   r   r   r   r   r-   )
rm   r   rn   r   r   r   r   r   r   r-   )r   r   r   r   r   r   r   r-   )r   rE   )>__doc__
__future__r   collections.abcrH   r   r   r   r   r   AbstractSetr   r   typingr   r	   r
   unicodedatar   r   r   _pytest._code_pytest._io.pprintr   _pytest._io.safereprr   r   _pytest.configr   r   __annotations__r   r   r   r$   r,   r'   r(   rK   rN   rQ   rT   rZ   r^   ra   rd   rk   r   r}   r   r   r   r   r   r   r   r   r   r   r   r~   r   r   r   r   r   <module>   s~   



#







G&;!@
	
.7