o
    2g                     @  s   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m	Z	 ddl
mZ ddlmZ ddlmZ ddlmZmZ dd	lmZmZ ejZed
ZG dd deZdddZdddZdS )a  Test cases for running mypy programs using a Python interpreter.

Each test case type checks a program then runs it using Python. The
output (stdout) of the program is compared to expected output. Type checking
uses full builtins and other stubs.

Note: Currently Python interpreter paths are hard coded.

Note: These test cases are *not* included in the main test suite, as including
      this suite would slow down the main suite too much.
    )annotationsN)TemporaryDirectory)api)PYTHON3_VERSION)test_temp_dir)DataDrivenTestCase	DataSuite)assert_string_arrays_equalsplit_linesz\b_program.py\bc                   @  s$   e Zd ZddgZe Zd
ddZd	S )PythonEvaluationSuitezpythoneval.testzpythoneval-asyncio.testtestcaser   returnNonec                 C  s   t |tj| jjd d S )Nz.mypy_cache)test_python_evaluationospathjoin	cache_dirname)selfr    r   P/home/garg/my-data/venv/lib/python3.10/site-packages/mypy/test/testpythoneval.pyrun_case%   s   zPythonEvaluationSuite.run_caseN)r   r   r   r   )__name__
__module____qualname__filesr   r   r   r   r   r   r   r   !   s    r   r   r   r   strr   r   c                 C  s  | j dus	J dg d}t}|ddttt  tdd| j	tj
}|rb|d }|D ](}|dr\|d	d }|d\}}	t|t|	ftjjtjjfkr\ dS q4|| d
| j d }
tjt|
}|| t|ddd}| j	D ]
}|| d qW d   n1 sw   Y  |d|  g }t|\}}}||  D ]/}|ttj r||tttj d d q| ttj td }||d q|dkr| j!s|d |dkr|st"j|d|
gtdd}|t#|j$|j% t&| t'|D ]\}}tjjd tjj |v r0|tjjd ||< qt(t)| |d| j* d| j+ d dS )z~Runs Mypy in a subprocess.

    If this passes without errors, executes the script again with a given Python
    version.
    Nztest was not properly set up)z--show-tracebackz--no-silence-site-packagesz--no-error-summaryz--hide-error-codesz--allow-empty-bodiesz--force-uppercase-builtinsz
--test-envz--python-version=.z# flags: (.*)$
   =_.pywutf8)encodingz--cache-dir=z
/z!!! Mypy crashed !!!r   z-WignoreT)cwdcapture_outputtypeshedzInvalid output (z, line )),old_cwdpython3_pathappendr   mapr   r   researchinput	MULTILINEgroupsplit
startswithintsysversion_infomajorminorextendr   r   r   r   openwriter   run
splitlinesseplenrstripreplaceoutput
subprocessr
   stdoutstderrremove	enumerater	   adapt_outputfileline)r   r   mypy_cmdlineinterpretermadditional_flagsflagtargetted_python_versiontargetted_majortargetted_minorprogramprogram_pathrM   srF   outerr
returncoderN   procir   r   r   r   )   sb   	



$

r   	list[str]c                   s"   d| j  d   fdd| jD S )z<Translates the generic _program.py into the actual filename.r"   r#   c                   s   g | ]}t  |qS r   )
program_resub).0rN   rW   r   r   
<listcomp>u   s    z adapt_output.<locals>.<listcomp>)r   rF   )r   r   rc   r   rL   r   s   rL   )r   r   r   r   r   r   )r   r   r   r_   )__doc__
__future__r   r   os.pathr1   rG   r9   tempfiler   mypyr   mypy.defaultsr   mypy.test.configr   mypy.test.datar   r   mypy.test.helpersr	   r
   
executabler.   compiler`   r   r   rL   r   r   r   r   <module>   s$    

I