o
    tBhOh                     @  s  U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZ ddlmZmZmZmZmZ ddlmZmZ ddlZddlmZmZmZ ejeZdd	gZd
ed< G dd deZ G dd deZ!ee e!f Z"ded< dVddZ#G dd dej$Z%dWddZ&G dd dZ'dXd"d#Z(dYd&d'Z)dYd(d)Z*dZd+d,Z+d[d0d1Z,d\d3d4Z-d\d5d6Z.d]d9d:Z/d^d?d@Z0d_dGdHZ1G dIdJ dJej2Z3G dKdB dBej4Z5d`dMdNZ6dadQdRZ7dadSdTZ8G dUdD dDZ9dS )bzGUtilities for processing .test files containing test case descriptions.    )annotationsN)abstractmethod)AnyIterator
NamedTuplePatternUnion)Final	TypeAlias)PREFIXtest_data_prefixtest_temp_dirgdblldbr	   SUPPORTED_DEBUGGERSc                   @  s&   e Zd ZU ded< ded< ded< dS )
UpdateFilestrmodulecontenttarget_pathN__name__
__module____qualname____annotations__ r   r   e/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/mypy/test/data.pyr      s   
 r   c                   @  s   e Zd ZU ded< ded< dS )
DeleteFiler   r   pathNr   r   r   r   r   r   $   s   
 r   
_TypeAliasFileOperationcaseDataDrivenTestCasereturnNonec           &      C  s  t | j| j}| jj}| jjrtjj}nt	j}| jj
}d}g }g }g }i }	i }
i }i }g }i }|d  }}|dd D ]}|jdv r|jdusJJ td|j}|||j|f}|jdkre|| q;|jdkr}||d t|d  tjf q;|| q;|jd	v r|jdusJ |tj| j|j}|jd
krdnd}t|dd}||||| f W d   n1 sw   Y  q;|jdkr|jdusJ |tj| j|j}t|dd}|||d| f W d   n1 sw   Y  q;td|jr<|jdkrdn
t|jtdd }|dks#J |jdu r,t n
dd |jdD }|||< q;td|jrw|jdkrLdn
t|jtdd }|dks^J |jdu rgt n
dd |jdD }|||< q;td|jr|jdkrdn
t|jtdd }|dksJ |jdu rg n
dd |jdD }|||< q;|jdkr|jdusJ td|j}|sJ d|j t|d }|d ksJ d!| |||d}|
|t | q;td"|jr|jdu rg }n|jd}d}|D ]}|d#krd$}|d%r|d&d' } | d(vr6t d)!| j|j"|d'd }!zt#d*d+ |!d,D }"W n t y]   t d-!| j|j"|!w | d.krjt$j%|"k}q| d/krdt|"  k r}d0k sn t d1!| j|j"|!t$j%dt|" |"k}q|rd2d |jD }#tjj&d3kr|rd4d |#D }#|jd5ks|jd6kr|#}nt|jtd5d }|dksJ |#|	|< d$}q;|jd7kr|jdu r|j}q;t d8|j d9| j d:|j" |r	t | j d;|j" d<|' D ]-}||vr|| ||< ||v r9||v r9|| (|| s9t d=!|| j|j"q|j}$t)|$|d> |D ]\}%}t)|d||% qF|$| _*|| _+|	| _,| j"|j" t|j d  | _-|| _.|| _/|| _0|| _1|
| _2|pg | _3|| _4|| _5dS )?zParse and prepare a single case from suite with test case descriptions.

    This method is part of the setup phase, just before the test case is run.
    Tr      N>   fileoutfile
outfile-re
r&   r(   )builtinsbuiltins_py2r*   zbuiltins.pyiz__builtin__.pyiutf8encodingtypingz
typing.pyizstale[0-9]*$stalec                 S     h | ]}|  qS r   strip.0tr   r   r   	<setcomp>d       z"parse_test_case.<locals>.<setcomp>,zrechecked[0-9]*$	recheckedc                 S  r1   r   r2   r4   r   r   r   r7   i   r8   ztargets[0-9]*$targetsc                 S  s   g | ]}|  qS r   r2   r4   r   r   r   
<listcomp>n   r8   z#parse_test_case.<locals>.<listcomp>deletez(.*)\.([0-9]+)$zInvalid delete section:    zCan't delete during step z
out[0-9]*$zskip-path-normalizationFversion   	   >   ==>=zB{}, line {}: Only >= and == version checks are currently supportedc                 s  s    | ]}t |V  qd S N)int)r5   xr   r   r   	<genexpr>   s    z"parse_test_case.<locals>.<genexpr>.z/{}, line {}: "{}" is not a valid python versionrC   rB      zW{}, line {}: Only minor or patch version checks are currently supported with "==": "{}"c                 S     g | ]}t |qS r   )expand_variablesr5   liner   r   r   r<      r8   \c                 S  rJ   r   )fix_win_pathrL   r   r   r   r<      r8   outout1	triggeredzInvalid section header z in z	 at line z, line z#: Required output section not foundzIStale modules after pass {} must be a subset of rechecked modules ({}:{})main)6parse_test_datadatanamesuite	base_path
native_seposr   join	posixpathrequired_out_sectionidargrK   appendrecompilerstripSdirnamer&   openreadmatchrE   lensetsplitgroup
setdefaultadd
startswith
ValueErrorformatrM   tuplesysversion_infosepkeysissubsetexpand_errorsinputoutputoutput2	last_linefilesoutput_filesexpected_stale_modulesexpected_rechecked_modulesdeleted_pathsrR   normalize_outputexpected_fine_grained_targets)&r!   
test_itemsrX   r[   out_section_missingr   r}   r~   rz   r{   r   stale_modulesrechecked_modulesrR   r;   item
first_itemcontents
file_entrympathfnamfsrc_pathpassnummodulesreprocessedmnumfullargsversion_checkr_   
compare_opversion_strr?   
tmp_outputry   	file_pathr   r   r   parse_test_case,   s*  



&
&(
&(
&&










r   c                      s   e Zd ZU dZded< ded< ded< ded< d	Zd
Zded< ded< ded< ded< dZded< ded< ded< ded< d= fd(d)Zd>d*d+Z	d>d,d-Z
d>d.d/Zd?d1d2Zd@dAd8d9ZdBd;d<Z  ZS )Cr"   zNHolds parsed data-driven test cases, and handles directory setup and teardown.DataSuiteCollectorparent	list[str]ry   rz   zdict[int, list[str]]r{    r   zlist[tuple[str, str]]r}   zdict[int, set[str]]r   r   r   TrE   r|   z$list[tuple[str, str | Pattern[str]]]r~   r   rR   rW   	DataSuiter&   r   rV   writescachebool	only_whenplatform
str | NoneskipxfailrU   rM   r#   r$   c                   sv   t  || || _|| _|| _|| _|dkrtjdks%|dkr'tjdkr'd}|| _|	| _	|
| _
|| _d | _d | _d S )Nwindowswin32posixT)super__init__rW   r&   r   r   rs   r   r   r   rU   rM   old_cwdtmpdir)selfr   rW   r&   rV   r   r   r   r   r   rU   rM   	__class__r   r   r      s   
zDataDrivenTestCase.__init__c              	   C  s   | j rt   n
| jr| tjj | t}|d usJ d| }|  z|	|  W d S  t
yz   | jdd }|ry| jd usFJ tj|tj| jj}td| j d|  tj|sq| jsiJ tj| j|}t| jj|  w )NzShould not happen--save-failures-tozCopying data from test z to )r   pytestr   
add_markermark	getparentr   objsetuprun_case	Exceptionconfig	getoptionr   rZ   r   r[   basenamerV   printisabsr   shutilcopytree)r   r   rW   save_dir
target_dirr   r   r   runtest  s,   


zDataDrivenTestCase.runtestc              	     s|  t | d t | _tjdd| _t| jj t	t
 i  | jD ]]\}}td|}|rVt|d}|dks;J tdd|}t|}t|||} |g | q"tj|}tj|d	d
 t|ddd}	|	| W d    n1 szw   Y  q"| j D ]\}}
|dksJ |
D ]}t|} |g t|| qq rt nd} fddtd|d D | _d S )N)r!   z
mypy-test-)prefixz.*\.([0-9]+)$r%   r>   z	\.[0-9]+$r   T)exist_okwr,   r-   c                   s   g | ]}  |g qS r   )get)r5   r   stepsr   r   r<   N  s    z,DataDrivenTestCase.setup.<locals>.<listcomp>) r   rZ   getcwdr   tempfileTemporaryDirectoryr   chdirrV   mkdirr   r}   ra   rh   rE   rl   submodule_from_pathr   rm   r`   r   re   makedirsrf   writer   itemsr   maxranger   )r   r   r   r   r   r   r   	operationdirr   pathsmax_stepr   r   r   r   ,  s:   


"zDataDrivenTestCase.setupc                 C  sZ   | j d ur
| jd usJ dt| j  z| j  W n	 ty$   Y nw d | _ d | _d S )Nztest was not properly set up)r   r   rZ   r   cleanupOSErrorr   r   r   r   teardownP  s   
zDataDrivenTestCase.teardowntuple[str, int, str]c                 C  s   | j | j| jfS rD   )r&   rM   rV   r   r   r   r   
reportinfoZ  s   zDataDrivenTestCase.reportinfoNexcinfor   style
Any | Nonec                 C  sF   | tr
| }n| j| |jdd}d| j d| j d| S )Nshort)r   zdata: :z:
)errisinstance
SystemExitexconlyr   _prunetracebackgetreprr&   rM   )r   r   r   excreprr   r   r   repr_failure]  s
   

zDataDrivenTestCase.repr_failurelist[list[FileOperation]]c                 C  s   | j S )ax  Return a list of descriptions of file operations for each incremental step.

        The first list item corresponds to the first incremental step, the second for the
        second step, etc. Each operation can either be a file modification/creation (UpdateFile)
        or deletion (DeleteFile).

        Defaults to having two steps if there aern't any operations.
        r   r   r   r   r   
find_stepsj  s   	zDataDrivenTestCase.find_steps)r   r   rW   r   r&   r   rV   r   r   r   r   r   r   r   r   r   r   r   rU   r   rM   rE   r#   r$   r#   r$   )r#   r   rD   )r   r   r   r   r#   r   )r#   r   )r   r   r   __doc__r   r&   rM   r   r   r   r   r   r   r   r   __classcell__r   r   r   r   r"      s0   
 


$

r   r   c                 C  s<   t dd| } t d| }|d= d|}t dd|}|S )Nz\.pyi?$r   z[/\\]r   rH   z\.__init__$)ra   r   rk   r[   )r   partsr   r   r   r   r   v  s   
r   c                   @  s<   e Zd ZU dZdZdZded< ded< dZdZdddZ	dS )TestItemzVParsed test caseitem.

    An item is of the form
      [id arg]
      .. data ..
    r   r   r_   r   rU   r   r^   r   rM   rE   r#   r$   c                 C  s   || _ || _|| _|| _d S rD   )r^   r_   rU   rM   )r   r^   r_   rU   rM   r   r   r   r     s   
zTestItem.__init__N)
r^   r   r_   r   rU   r   rM   rE   r#   r$   )
r   r   r   r   r^   r_   r   r&   rM   r   r   r   r   r   r     s   
 r   raw_datarV   list[TestItem]c           
      C  s  dd| d g|  d }g }g }d}d}d}d}|t|k r||  }	|| drn|	drn|rIt|}t|}|t||t||d  |}|	dd	 }d}d
|v rk||	d
d d }|d|	d
 }g }n4|| dr||| dd  n!|| ds|||  n|| dr||| dd  |d7 }|t|k s|rt|}t|}|t||||d  |S )z>Parse a list of lines that represent a sequence of test items.r   z[case ]r)   Nr   [r%    z\[z--z----r>   )
rk   ri   r3   ro   endswithcollapse_line_continuation
strip_listr`   r   index)
r   rV   linesretrU   r^   r_   ii0sr   r   r   rT     sD   rT   lr   c                 C  s^   g }| D ]}| tdd| qt|dkr-|d dkr-|  t|dkr-|d dks|S )zReturn a stripped copy of l.

    Strip whitespace at the end of all lines, and strip all empty
    lines from the end of the array.
    z\s+$r   r   r   )r`   ra   r   ri   pop)r  rr  r   r   r   r     s   r   c              	   C  sX   g }d}| D ]#}t dd|}|r|d  t dd|7  < n|| |d}q|S )NFz\\$r   r   z^ +rN   )ra   r   r`   r   )r  r  contr  ssr   r   r   r     s   
r   r  c                 C  s   |  dtS )Nz<ROOT>)replaceroot_dir)r  r   r   r   rK     s   rK   ry   rz   r   c           	      C  s   t t| D ]s}| | ddd D ]e}td| }|rx|ddkr)d}n|ddkr3d}n	|dd	kr<d
}|d}|d}|dd}|du rc|| d|d  d| d|  q|| d|d  d| d| d| 	 qqdS )zTransform comments such as '# E: message' or
    '# E:3: message' in input.

    The result is lines like 'fnam:line: error: message'.
    z # r%   Nz*^([ENW]):((?P<col>\d+):)? (?P<message>.*)$EerrorNnoteWwarningcolmessagez\##r   z: )	r   ri   rk   ra   searchr3   rl   r	  r`   )	ry   rz   r   r  possible_err_commentr   severityr  r  r   r   r   rx     s*   

&*rx   rM   c                 C  sP   |  tt dd} td| }|s| S | \}}}d| dd|p%d|S )z`Changes Windows paths to Linux paths in error messages.

    E.g. foo\bar.py -> foo/bar.py.
    rN   /z^([\S/]+):(\d+:)?(\s+.*)z{}:{}{}r   )r	  r
  ra   rh   groupsrq   )rM   r   filenamelinenor  r   r   r   rO     s   rO   c                 C  sL   t d| }|s
| S d| d|d |ddd| |dd S )zChanges filename paths to Linux paths in Cobertura output files.

    E.g. filename="pkg\subpkg\a.py" -> filename="pkg/subpkg/a.py".
    z&<class .* filename="(?P<filename>.*?)"z{}{}{}Nr%   r  rN   r  )ra   r  rq   startrl   r	  end)rM   r   r   r   r   fix_cobertura_filename  s   0r  parserr   c                 C  sf   |  d}|jddddd |jdd dd	 |jd
ddd |jddddd |jdd dtdd d S )Nmypyz--update-data
store_trueFzLUpdate test data to reflect actual output (supported only for certain tests))actiondefaulthelpr   zBCopy the temp directories from failing tests to a target directory)r"  r#  z--mypy-verbosecountz/Set the verbose flag when creating mypy Options)r!  r#  z--mypyc-showcz%Display C code on mypyc test failuresz--mypyc-debugdebuggerz8Run the first mypyc run test with the specified debugger)r"  destchoicesr#  )getgroup	addoptionr   )r  rl   r   r   r   pytest_addoption)  s8   

r*  	collectorr   objectr   c                 C  s.   t |trt|tr|turtj| |dS dS )zCalled by pytest on each object in modules configured in conftest.py files.

    collector is pytest.Collector, returns Optional[pytest.Class]
    r   rV   N)
isinstancetype
issubclassr   r   from_parent)r+  rV   r   r   r   r   pytest_pycollect_makeitemJ  s   
r2  r   DataFileCollectorrW   r   r&   Iterator[DataDrivenTestCase]c                 c  s&   t |dd}| }W d   n1 sw   Y  d}tjd|tjtjB d}|d dd	 }t }td	t	||D ]S}	||	|	|  \}
}}}}}}|
|v r\t
d
|
| j||rd|d	d nd}tj| ||t|
|jt|||t|t|||dV  ||dd	 7 }||
h q=dS )zIterate over raw test cases in file, at collection time, ignoring sub items.

    The collection phase is slow, so any heavy processing should be deferred to after
    uninteresting tests are filtered (when using -k PATTERN switch).
    zutf-8r-   Nr@   zz^\[case ([a-zA-Z_0-9]+)(-writescache)?(-only_when_cache|-only_when_nocache)?(-posix|-windows)?(-skip)?(-xfail)?\][ \t]*$\n)flagsr   r)   r%   z1Found a duplicate test name "{}" in {} on line {})r   rW   r&   rV   r   r   r   r   r   rU   rM   )rf   rg   ra   rk   DOTALL	MULTILINEr$  rj   r   ri   RuntimeErrorrq   rV   r"   r1  add_test_name_suffixtest_name_suffixr   update)r   rW   r&   r   rU   
NUM_GROUPScasesline_no
test_namesr  rV   r   r   platform_flagr   r   r   r   r   r   split_test_cases[  sJ   


rA  c                   @  s   e Zd ZdddZdS )r   r#   Iterator[DataFileCollector]c                 c  sH    | j }tj|jsJ d|j d|jD ]
}tj| |dV  qdS )zNCalled by pytest on each of the object returned from pytest_pycollect_makeitemzTest data prefix (z) not set correctlyr-  N)r   rZ   r   isdirdata_prefixr}   r3  r1  )r   rW   	data_filer   r   r   collect  s   
zDataSuiteCollector.collectN)r#   rB  )r   r   r   rF  r   r   r   r   r     s    r   c                      s:   e Zd ZU dZded< ed fddZdd
dZ  ZS )r3  zvRepresents a single `.test` data driven test file.

    More context: https://github.com/python/mypy/issues/11662
    r   r   rV   r   r#   c                  s   t  j||dS )N)rV   )r   r1  )clsr   rV   r   r   r   r1    s   zDataFileCollector.from_parentr4  c                 c  s0    t | | jjtj| jjj| jdE d H  d S )N)r   rW   r&   )rA  r   r   rZ   r   r[   rD  rV   r   r   r   r   rF    s   zDataFileCollector.collect)r   r   rV   r   r#   r3  )r#   r4  )	r   r   r   r   r   classmethodr1  rF  r   r   r   r   r   r3    s   
 suffixc                 C  s<   t d| }|r|d}| d t|  | | S | | S )Nz-[-A-Za-z0-9]+$r   )ra   r  rl   ri   )rV   rI  r   magic_suffixr   r   r   r9    s
   
r9  testcaser   c                 C  s   d| j  v pd| jv S )Nincremental)rV   lowerr&   )rK  r   r   r   is_incremental  s   rN  c                 C  sD   t dd | jD rdS | jD ]\}}tj|dr dS qdS )Nc                 s  s    | ]	}t d |V  qdS )z# flags[2-9]:N)ra   rh   rL   r   r   r   rG     s    z#has_stable_flags.<locals>.<genexpr>Fz	mypy.ini.T)anyry   r}   rZ   r   r   ro   )rK  r  r   r   r   r   has_stable_flags  s   rP  c                   @  sB   e Zd ZU ded< eZeZdZdZ	dZ
dddZedddZdS )r   r   r}   Fr   r#   r$   c                 C  s   dS )zSetup fixtures (ad-hoc)Nr   r   r   r   r   r     s    zDataSuite.setuprK  r"   c                 C  s   t rD   )NotImplementedError)r   rK  r   r   r   r     s   zDataSuite.run_caseNr   )rK  r"   r#   r$   )r   r   r   r   r   rX   r   rD  r]   rY   r:  r   r   r   r   r   r   r   r     s   
 
)r!   r"   r#   r$   )r   r   r#   r   )r   r   rV   r   r#   r   )r  r   r#   r   )r  r   r#   r   )ry   r   rz   r   r   r   r#   r$   )rM   r   r#   r   )r  r   r#   r$   )r+  r   rV   r   r   r,  r#   r   )r   r3  rW   r   r&   r   r#   r4  )rV   r   rI  r   r#   r   )rK  r"   r#   r   ):r   
__future__r   rZ   os.pathr\   ra   r   rs   r   abcr   r/   r   r   r   r   r   typing_extensionsr	   r
   r   r   mypy.test.configr   r   r   r   normpathr
  r   r   r   r   r    r   Itemr"   r   r   rT   r   r   rK   rx   rO   r  r*  r2  rA  Classr   	Collectorr3  r9  rN  rP  r   r   r   r   r   <module>   sR    
 , 
 


-






!
5


	