o
    2g5                     @  s~  d Z ddlm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mZmZ ddlmZmZ dd	lmZmZmZmZ dd
lmZmZmZmZmZmZmZm Z  ddl!m"Z" zddl#Z#W n e$yo   dZ#Y nw ddl%Z%eddZ&ej'dk re&(d ej'dk re&(d ej'dk re&(d ej'dk re&(d ej'dk re&(d ej)dvre&(d G dd deZ*dS )zType checker test cases    )annotationsN)build)Graph)CompileError)BuildSourceFindModuleCacheSearchPaths)test_data_prefixtest_temp_dir)DataDrivenTestCase	DataSuiteFileOperationmodule_from_path)assert_module_equivalenceassert_string_arrays_equalassert_target_equivalencecheck_test_output_filesfind_test_filesnormalize_error_messagesparse_optionsperform_file_operations)update_testcase_outputzcheck-*.test)pattern)   	   zcheck-python39.test)r   
   zcheck-python310.test)r      zcheck-python311.test)r      zcheck-python312.test)r      zcheck-python313.test)darwinwin32zcheck-modules-case.testc                   @  sj   e Zd ZeZd(ddZd)d	d
Z		d*d+ddZd,ddZd-ddZ	d.dd Z
d/d"d#Z	d0d1d&d'ZdS )2TypeCheckSuitetestcaser   returnNonec                 C  s  t d u rtj|jdkrtd d|j v p"d|jv p"d|jv }|rt	dgt
|j  }ttjD ]#\}}}|D ]}td|}|rYt|d|krYtd||q>q7| }	td|d D ]}
|
d }|t|	k rz|d	krz|	| ng }| |||
 qfd S | | d S )
Nzcheck-reports.testz$Cannot import lxml. Is it installed?incremental	serialize   z
\.([2-9])$   z7Output file {} exists though test case only has {} runsr   )lxmlospathbasenamefilepytestskipnamelowermaxlistoutput2keyswalkcurdirresearchintgroup
ValueErrorformat
find_stepsrangelenrun_case_once)selfr"   r%   	num_stepsdndirsfilesr-   mstepsstepidxops rL   K/home/garg/my-data/venv/lib/python3.10/site-packages/mypy/test/testcheck.pyrun_case;   s6   
 zTypeCheckSuite.run_casea	list[str]c                   sv   |j }|jr|t|jkrd S ddd dd t fdd	|D D t|j|d   fd
dd|j|d < d S )N_msgstrr#   c                 S  s   |  dd S )N:r   )	partition)rQ   rL   rL   rM   	_filename^   s   z8TypeCheckSuite._sort_output_if_needed.<locals>._filenamec                 S  s   i | ]\}}||qS rL   rL   ).0rJ   r-   rL   rL   rM   
<dictcomp>a   s    z9TypeCheckSuite._sort_output_if_needed.<locals>.<dictcomp>c                 3  s    | ]} |V  qd S )NrL   )rV   msg)rU   rL   rM   	<genexpr>a   s    z8TypeCheckSuite._sort_output_if_needed.<locals>.<genexpr>c                   s     | dS )N)get)rX   rU   file_weightsrL   rM   <lambda>c   s    z7TypeCheckSuite._sort_output_if_needed.<locals>.<lambda>)key)rQ   rR   r#   rR   )output_inline_startrF   r@   output	enumeratesorted)rB   r"   rO   rJ   rL   r\   rM   _sort_output_if_neededY   s   
 z%TypeCheckSuite._sort_output_if_neededNr   
operationslist[FileOperation] | Noneincremental_stepr:   c              
     s  |d u rg }d  j}| ||} jD ]\}}t|}|dr+|tjv r+tj|= q|dks4|dkr_|D ]'\}	}
}|	dkr]t|
ddd}|	| W d    n1 sVw   Y   nq6n|dkrgt
| t| |}d	|_d	|_d
 jv r{d	|_d jv rd|_d jvr jd |_d jvrd	|_d jvrd	|_|r|jrd	|_n
d|_ jstj|_g }|D ]\}	}
}|t|
|	|rd n| qtj td}tjd| d }z3ztj||t d}|j!}W n t"y } z	|j#}W Y d }~nd }~ww W tjd |ks	J tjd= ntjd |ksJ tjd= w  j$r%t%|}|dk rE|dkr2d}n	|dks9J d}| & |  j'}nd| d } j()|g }||krg j*+ddrgt, ||d t-|||. j j/ |r|jtjkr| 0||j!|j1|j2 d}|r|t3|d 7 } j4)|d } fdd|j1j5D }|d urt6||| |dkr|dkrdnt3|d } j7)|d }|d urt8d| ||j1j9  j:)|d }|d urt8d| ||j1j;  j<r t= |d d! d S d S )"N
_pluginr   r(   __main__wutf8encodingTcolumns
errorcodesFabstract	_no_empty	lowercasezunion-errorplugins)sourcesoptionsalt_lib_pathr'   zBUnexpected type checker output in incremental, run 1 ({}, line {})z,Unexpected type checker output ({}, line {})z3Unexpected type checker output in incremental, run z ({}, line {})z--update-data)rg   targetsc                   s   g | ]\}}| j v r|qS rL   )test_modules)rV   moduletargetr"   rL   rM   
<listcomp>   s
    
z0TypeCheckSuite.run_case_once.<locals>.<listcomp> 	recheckedstaleztmp/)strip_prefix)>joininputparse_modulerF   r   endswithsysmodulesopenwriter   r   use_builtins_fixturesshow_tracebackr-   show_column_numbershide_error_codesr0   allow_empty_bodiesforce_uppercase_builtinsforce_union_syntaxr%   writescacher*   devnull	cache_dirappendr   r+   r	   insertr   r
   errorsr   messagesnormalize_outputr   rd   ra   r4   r[   config	getoptionr   r   r=   lineverify_cachemanagergraphrR   expected_fine_grained_targetsprocessed_targetsr   expected_rechecked_modulesr   rechecked_modulesexpected_stale_modulesstale_modulesoutput_filesr   )rB   r"   re   rg   original_program_textmodule_datar-   _rz   module_nameprogram_pathprogram_textfrv   ru   
plugin_dirresrO   erX   ra   r0   expectedactualsuffixexpected_recheckedexpected_stalerL   r|   rM   rA   f   s   















zTypeCheckSuite.run_case_oncer   list[tuple[str, str, str]]r   build.BuildManagerr   r   c                   s   |  |} fdd|j D }| |}|dd |D  | ||}|s.|r.J d||ks<td| d| tj	tj
|jjdsKJ tj
|jjd	}	tj	|	s\J t|	}
|
 d
sjJ W d    d S 1 suw   Y  d S )Nc                   s    h | ]\}} | j r|jqS rL   )transitive_errorr+   )rV   idrG   r   rL   rM   	<setcomp>   s     z.TypeCheckSuite.verify_cache.<locals>.<setcomp>c                 S  s   i | ]\}}}||qS rL   rL   )rV   r   r+   textrL   rL   rM   rW          z/TypeCheckSuite.verify_cache.<locals>.<dictcomp>z-Some modules reported error despite no errorszcache data discrepancy z != z
.gitignorezCACHEDIR.TAGz+Signature: 8a477f597d28d172789f06886806bc55)find_error_message_pathsr   itemsfind_module_filesupdatefind_missing_cache_filesAssertionErrorr*   r+   isfiler   rv   r   r   read
startswith)rB   r   rO   r   r   error_pathsbusted_pathsr   missing_pathscachedir_tagr   rL   r   rM   r      s   



"zTypeCheckSuite.verify_cacheset[str]c                 C  s8   t  }|D ]}td|}|r|d}|| q|S )Nz.([^\s:]+):(\d+:)?(\d+:)? (error|warning|note):r(   )setr8   matchr;   add)rB   rO   hitsr   rG   prL   rL   rM   r     s   

z'TypeCheckSuite.find_error_message_pathsdict[str, str]c                 C  s   dd |j  D S )Nc                 S  s   i | ]\}}||j qS rL   )r+   )rV   r   rz   rL   rL   rM   rW     r   z4TypeCheckSuite.find_module_files.<locals>.<dictcomp>)r   r   )rB   r   rL   rL   rM   r     s   z TypeCheckSuite.find_module_filesr   c                 C  sN   d}i }|  D ]\}}t|||}t|||||s |||< qt| S )NT)r   r   find_cache_metavalidate_metar   values)rB   r   r   ignore_errorsmissingr   r+   metarL   rL   rM   r     s   z'TypeCheckSuite.find_missing_cache_filesr   rR   c              	   C  s   t jd|t jd}|dkr"d| d}t j||t jd}|dur"|}|rw|d}g }ttfddd}t|ddd}	|d	D ]5}
|	|
}t	|t
sRJ d
|
 t|dd}| }W d   n1 sgw   Y  ||
||f q?|S dd|fgS )a+  Return the module and program names for a test case.

        Normally, the unit tests will parse the default ('__main__')
        module and follow all the imports listed there. You can override
        this behavior and instruct the tests to check multiple modules
        by using a comment like this in the test case input:

          # cmd: mypy -m foo.bar foo.baz

        You can also use `# cmdN:` to have a different cmd for incremental
        step N (2, 3, ...).

        Return a list of tuples (module name, file name, program text).
        z!# cmd: mypy -m ([a-zA-Z0-9_. ]+)$)flagsr(   z# cmdz: mypy -m ([a-zA-Z0-9_. ]+)$NrL   )fscacherv    zCan't find ad hoc case file: rl   rm   rj   main)r8   r9   	MULTILINEr;   r   r
   r   splitfind_module
isinstancerR   r   r   r   )rB   r   rg   rG   	alt_regexalt_mmodule_namesoutsearch_pathscacher   r+   r   rL   rL   rM   r     s(   


zTypeCheckSuite.parse_module)r"   r   r#   r$   )r"   r   rO   rP   r#   r$   )Nr   )r"   r   re   rf   rg   r:   r#   r$   )
r   r   rO   rP   r   r   r   r   r#   r$   )rO   rP   r#   r   )r   r   r#   r   )r   r   r   r   r#   r   )r   )r   rR   rg   r:   r#   r   )__name__
__module____qualname__typecheck_filesrF   rN   rd   rA   r   r   r   r   r   rL   rL   rL   rM   r!   8   s    

 


	
r!   )+__doc__
__future__r   r*   r8   r   mypyr   
mypy.buildr   mypy.errorsr   mypy.modulefinderr   r   r   mypy.test.configr	   r
   mypy.test.datar   r   r   r   mypy.test.helpersr   r   r   r   r   r   r   r   mypy.test.update_datar   r)   ImportErrorr.   r   version_inforemoveplatformr!   rL   rL   rL   rM   <module>   sB    (













