o
    tBha2                     @  sZ  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 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"m#Z# zddl$Z$W n e%yq   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vre')d G dd deZ+dS )zType checker test cases    )annotationsN)build)Graph)CompileError)BuildSourceFindModuleCacheSearchPaths)core_modules)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-python38.test)r   	   zcheck-python39.test)r   
   zcheck-python310.test)darwinwin32zcheck-modules-case.testc                   @  s`   e Zd ZeZd&ddZg dfd'ddZd(ddZd)ddZd*ddZ	d+dd Z
	d,d-d#d$Zd%S ).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 rK   j/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/mypy/test/testcheck.pyrun_case7   s6   
 zTypeCheckSuite.run_caser   
operationslist[FileOperation]incremental_stepr9   c              
   C  s  d |j}| ||}|jD ]\}}t|}|dr%|tjv r%tj|= q|dks.|dkrY|D ]'\}	}
}|	dkrWt|
ddd}|	| W d    n1 sPw   Y   nq0n|dkrat
| t|||}d	|_d	|_d	|_d
|jv rxd	|_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 }z2ztj||td}|j}W n t y } z	|j!}W Y d }~nd }~ww W tjd |ksJ tjd= ntjd |ksJ tjd= w |j"rt#|}|dkrd}|j$}n"|dkr!d}|j$}n|dkr5d| d }|j%&|g }nt' ||krJ|j()ddrJt*|| t+|||,|j|j- |r|jtjkrk| .||j|j/|j0 d}|rx|t1|d 7 }|j2&|d }|j/j3}dd |D }|d urt4||| |dkr|dkrdnt1|d }|j5&|d }|d urt6d| ||j/j7 |j8&|d }|d urt6d| ||j/j9 |j:rt;||dd d S d S )N
_pluginr   r'   __main__wutf8encodingToptionalcolumns
errorcodesFplugins)sourcesoptionsalt_lib_pathz,Unexpected type checker output ({}, line {})zBUnexpected type checker output in incremental, run 1 ({}, line {})z3Unexpected type checker output in incremental, run z ({}, line {})z--update-datatargetsc                   s,   g | ] t  fd dtdg D s qS )c                 3  s    | ]}  |V  qd S )N)
startswith).0modtrK   rL   	<genexpr>   s    z:TypeCheckSuite.run_case_once.<locals>.<listcomp>.<genexpr>mypy_extensions)anyr	   )ra   rK   rc   rL   
<listcomp>   s    z0TypeCheckSuite.run_case_once.<locals>.<listcomp>r&    	recheckedstaleztmp/)strip_prefix)<joininputparse_modulerE   r   endswithsysmodulesopenwriter   r   use_builtins_fixturesenable_incomplete_featuresshow_tracebackr,   strict_optionalshow_column_numbersshow_error_codesr$   writescacher)   devnull	cache_dirappendr   r*   r
   insertr   r   errorsr   messagesnormalize_outputr   outputr3   getAssertionErrorconfig	getoptionr   r   r<   lineverify_cachemanagergraphstrexpected_fine_grained_targetsprocessed_targetsr   expected_rechecked_modulesr   rechecked_modulesexpected_stale_modulesstale_modulesoutput_filesr   )rA   r!   rN   rP   original_program_textmodule_datar,   _modulemodule_nameprogram_pathprogram_textfr]   r\   
plugin_dirresaemsgr   r/   expectedactualsuffixexpected_recheckedexpected_stalerK   rK   rL   r@   U   s   














zTypeCheckSuite.run_case_oncer   list[tuple[str, str, str]]r   	list[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 rK   )transitive_errorr*   )ra   idrF   r   rK   rL   	<setcomp>   s     z.TypeCheckSuite.verify_cache.<locals>.<setcomp>c                 S  s   i | ]\}}}||qS rK   rK   )ra   r   r*   textrK   rK   rL   
<dictcomp>       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_pathsrr   itemsfind_module_filesupdatefind_missing_cache_filesr   r)   r*   isfilerm   r]   r}   rs   readr`   )rA   r   r   r   r   error_pathsbusted_pathsrr   missing_pathscachedir_tagr   rK   r   rL   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'   )setr7   matchr:   add)rA   r   hitsr   rF   prK   rK   rL   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 rK   )r*   )ra   r   r   rK   rK   rL   r      r   z4TypeCheckSuite.find_module_files.<locals>.<dictcomp>)rr   r   )rA   r   rK   rK   rL   r      s   z TypeCheckSuite.find_module_filesrr   c                 C  sN   d}i }|  D ]\}}t|||}t|||||s |||< qt| S )NT)r   r   find_cache_metavalidate_metar   values)rA   rr   r   ignore_errorsmissingr   r*   metarK   rK   rL   r      s   z'TypeCheckSuite.find_missing_cache_filesr   r   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_. ]+)$NrK   )fscacher]    zCan't find ad hoc case file: rU   rV   rS   main)r7   r8   	MULTILINEr:   r   r   r   splitfind_module
isinstancer   rs   r   r~   )rA   r   rP   rF   	alt_regexalt_mmodule_namesoutsearch_pathscacher   r*   r   rK   rK   rL   ro     s(   


zTypeCheckSuite.parse_moduleN)r!   r   r"   r#   )r!   r   rN   rO   rP   r9   r"   r#   )
r   r   r   r   r   r   r   r   r"   r#   )r   r   r"   r   )r   r   r"   r   )rr   r   r   r   r"   r   )r   )r   r   rP   r9   r"   r   )__name__
__module____qualname__typecheck_filesrE   rM   r@   r   r   r   r   ro   rK   rK   rK   rL   r    4   s    
!
}

	
r    ),__doc__
__future__r   r)   r7   rq   mypyr   
mypy.buildr   mypy.errorsr   mypy.modulefinderr   r   r   mypy.semanal_mainr	   mypy.test.configr
   r   mypy.test.datar   r   r   r   mypy.test.helpersr   r   r   r   r   r   r   r   r   r(   ImportErrorr-   r   version_inforemoveplatformr    rK   rK   rK   rL   <module>   s:    ,








