o
    hYF                     @   s  U d Z 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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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dlmZ dZeeeeegee f  ed< dZeeeeegdf  ed< dZee ed< dedefddZ dede
e fddZ!dee de
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#fd"d#Z&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#fd+d,Z*d&ede#fd-d.Z+d&ede#fd/d0Z,	1dOd2ed3ed4ed5e#dee
e  f
d6d7Z-dPd3ed4ed8ede
e fd9d:Z.dPd3ed4ed8ede
e fd;d<Z/de
e ddfd=d>Z0	dPd3e	e d4e	e d8ede
e fd?d@Z1	dPd3ee d4ee d8ede
e fdAdBZ2	dPd3ee d4ee d8ede
e fdCdDZ3	dPd3eeef d4eeef d8ede
e fdEdFZ4d3ed4ed8ede
e fdGdHZ5dPdIedJed8ede
e fdKdLZ6de#fdMdNZ7dS )Qz"Utilities for assertion debugging.    N)AbstractSet)Any)Callable)Iterable)List)Mapping)Optional)Sequence)	normalize)outcomes)_pformat_dispatch)saferepr)saferepr_unlimited)Config_reprcompare_assertion_pass_configexplanationreturnc                 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result r   L/var/www/html/ai/venv/lib/python3.10/site-packages/_pytest/assertion/util.pyformat_explanation$   s   

r   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   3   s   
r   r   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   r    r$   zand   zwhere z +  r!   )r"   r#   r"   )list
startswithr&   lenpop)r   r   stackstackcntlinesindentr   r   r   r   D   s,   	

,
r   xc                 C   s   t | tjjot | t S N)
isinstancecollectionsabcr	   strr3   r   r   r   
issequenceg      r:   c                 C   
   t | tS r4   )r5   r8   r9   r   r   r   istextk      
r=   c                 C   r<   r4   )r5   dictr9   r   r   r   isdicto   r>   r@   c                 C   s   t | ttfS r4   )r5   set	frozensetr9   r   r   r   issets   s   rC   objc                 C   s   t | tot| dd d uS )N_fields)r5   tuplegetattrrD   r   r   r   isnamedtuplew   r;   rI   c                 C      t | dd d uS )N__dataclass_fields__rG   rH   r   r   r   	isdatacls{      rM   c                 C   rJ   )N__attrs_attrs__rL   rH   r   r   r   isattrs   rN   rP   c                 C   s*   z
t |  t|  W S  ty   Y dS w )NF)iterr=   	TypeErrorrH   r   r   r   
isiterable   s   rS   c                 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 eqz<string>T)hasattr__eq__rT   rU   rP   )rD   code_filenamer   r   r   has_default_eq   s   
rY   Fopleftright	use_asciic                 C   s*  |  d}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| }	d	}
z|d
krZt|||}
n|dkrlt|rlt|rlt	|||}
W n t
jyv     ty   dtjj  dg}
Y nw |
sd	S |	g|
 S )z<Return specialised explanations for some operators/operands.verboseNFDr   )r]   A      )maxsizer]    Nz==znot inz?(pytest_assertion plugin: representation of details failed: {}.z+ Probably an object has a faulty __repr__.))	getoptionr5   r8   r
   r   r,   r   _compare_eq_anyr=   _notin_textr   Exit	Exceptionformat_pytest_codeExceptionInfofrom_current_getreprcrash)configrZ   r[   r\   r]   r^   	left_repr
right_reprrb   summaryr   r   r   r   assertrepr_compare   sF   


rs   r^   c                 C   s,  g }t | rt |rt| ||}|S ddlm} t| |s"t||r:t| |r)| n|}t| |r2|n| }||}nGt| t|krUt| sNt| sNt	| rUt
| ||}n,t| rdt|rdt| ||}nt| rst|rst| ||}nt| rt|rt| ||}t| rt|rt| ||}|| |S )Nr   )
ApproxBase)r=   
_diff_text_pytest.python_apirt   r5   _repr_comparetyperM   rP   rI   _compare_eq_clsr:   _compare_eq_sequencerC   _compare_eq_setr@   _compare_eq_dictrS   _compare_eq_iterableextend)r[   r\   r^   r   rt   approx_side
other_sideexplr   r   r   re      s6   
re   c                 C   sR  ddl m} g }|dk rzd}ttt| t|D ]}| | || kr% nq|dkr?|d8 }d| g}| |d } ||d }t| t|krztt| D ]}| |  ||  kr[ nqM|dkrz|d8 }|d|g7 }| d|  } |d|  }d	}|  s| rtt| } tt|}|d
g7 }|dd ||	|| 	|D 7 }|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 %s identical leading characters in diff, use -v to showNzASkipping {} identical trailing characters in diff, use -v to showTz;Strings contain only whitespace, escaping them using repr()c                 S   s   g | ]}| d qS )r   )strip.0r0   r   r   r   
<listcomp>   s    z_diff_text.<locals>.<listcomp>)
difflibr   rangeminr,   ri   isspacereprr8   
splitlines)r[   r\   r^   r   r   ikeependsr   r   r   ru      sH   
ru   c                 C   s   | d dd }|dv r!d| d dd  | d< |g|  | dd< | d dd }|dv rD| d dd d | d< | |g | dd< dS dS )	z6Move opening/closing parenthesis/bracket to own lines.r   Nr   )([r    rc   r$   ))]r!   ,r   )r   openingclosingr   r   r    _surrounding_parens_on_own_lines'  s   r   c           	      C   s   |dkr
t  s
dgS dd l}t|  }t| }t|}t|}||kr4t|  }t| }|dks<|dkrDt| t| dg}|dd |	||D  |S )Nr   zUse -v to get more diffr   z
Full diff:c                 s   s    | ]}|  V  qd S r4   )rstripr   r   r   r   	<genexpr>L  s    
z'_compare_eq_iterable.<locals>.<genexpr>)
running_on_cir   pprintpformatr   r,   r   r   r~   r   )	r[   r\   r^   r   left_formattingright_formatting
lines_leftlines_rightr   r   r   r   r}   3  s$   

r}   c                 C   s   t | to	t |t}g }t| }t|}tt||D ]5}| | || krP|r8| ||d  }|||d  }	n| | }|| }	|d| d|d|	g7 } nq|rU|S || }
|
r|
dkrhd}t| | }nd|
 }
d}t|| }|
dkr|| d| g7 }|S |d	||
|f g7 }|S )
Nr   z	At index z diff:  != r   LeftRightz contains one more item: z/%s contains %d more items, first extra item: %s)r5   bytesr,   r   r   r   )r[   r\   r^   comparing_bytesr   len_left	len_rightr   
left_valueright_valuelen_diffdir_with_moreextrar   r   r   rz   R  sB   	rz   c                 C   sd   g }| | }||  }|r| d |D ]	}| t| q|r0| d |D ]	}| t| q&|S )NzExtra items in the left set:zExtra items in the right set:)r&   r   )r[   r\   r^   r   	diff_left
diff_rightitemr   r   r   r{     s   

r{   c                    st  g }t  }t }||} fdd|D }|r)|dk r)|dt| g7 }n|r9|dg7 }|t| 7 } fdd|D }|rd|dg7 }|D ]}	|t|	 |	 id	 t|	|	 i g7 }qL|| }
t|
}|r|d
||dkrxdndf  |t fdd|
D   || }t|}|r|d||dkrdndf  |tfdd|D   |S )Nc                    s&   i | ]} | | kr| | qS r   r   r   kr[   r\   r   r   
<dictcomp>  s   & z$_compare_eq_dict.<locals>.<dictcomp>ra   ,Omitting %s 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 %d more item%s:r   r   r1   c                       i | ]}| | qS r   r   r   )r[   r   r   r         zRight contains %d more item%s:c                    r   r   r   r   )r\   r   r   r     r   )	rA   intersectionr,   r   r   r   r   r&   r~   )r[   r\   r^   r   set_left	set_rightcommonsamediffr   
extra_leftlen_extra_leftextra_rightlen_extra_rightr   r   r   r|     sL   


,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 }	|ro|dk ro|		d	t
|  n|r|	d
g7 }	|	t| 7 }	|r|	dg7 }	|	t| 7 }	|D ]*}t| |}
t||}|	dd| d ||
|f 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   r     s    z#_compare_eq_cls.<locals>.<listcomp>c                 S   s   g | ]
}t |d r|jqS )eq)rG   r   )r   fieldr   r   r   r     s    Fr)   r   ra   r   zMatching attributes:zDiffering attributes:z'Drill down into differing attribute %s:z%s%s: %r != %rc                    s   g | ]} | qS r   r   r   r2   r   r   r     s    )rY   rM   dataclassesfieldsrP   rO   rI   rE   rG   r&   r,   r   r   r   re   )r[   r\   r^   r   
all_fieldsfields_to_checkr   r   r   r   
field_leftfield_rightr   r   r   ry     sT   







ry   termtextc           
      C   s   | | }|d | }||t|  d  }|| }t|||}dt| dd g}|D ]$}	|	dr2q*|	dr8q*|	drI|d|	dd    q*||	 q*|S )	Nz%s is contained here:r   )rb   Skippingz- z+ r)   ra   )findr,   ru   r   r+   r&   )
r   r   r^   indexheadtailcorrect_textr   newdiffr0   r   r   r   rf     s   



rf   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 r4   )osenviron)r   varr   r   r   r   
  s    z running_on_ci.<locals>.<genexpr>)any)env_varsr   r   r   r     s   r   )F)r   )8__doc__collections.abcr6   r   r   typingr   r   r   r   r   r   r   r	   unicodedatar
   _pytest._coderj   r   _pytest._io.safereprr   r   r   _pytest.configr   r   r8   object__annotations__r   intr   r   r   r   boolr:   r=   r@   rC   rI   rM   rP   rS   rY   rs   re   ru   r   r}   rz   r{   r|   ry   rf   r   r   r   r   r   <module>   s    "#


 4 #0
 
6



) 3