o
    tBh                     @  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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 dd	lmZmZ d
gZG dd deZdddZdddZd ddZG dd dejZdS )!zEnd-to-end test cases for the daemon (dmypy).

These are special because they run multiple shell commands.

This also includes some unit tests.
    )annotationsN)%filter_out_missing_top_level_packages)FileSystemCache)SearchPaths)PREFIXtest_temp_dir)DataDrivenTestCase	DataSuite)assert_string_arrays_equalnormalize_error_messageszdaemon.testc                   @  s   e Zd ZeZdddZdS )	DaemonSuitetestcaser   returnNonec                 C  sB   |j drtjdk rtd zt| W td d S td w )N	_python38)      z'Not supported on this version of Pythonz
dmypy kill)nameendswithsysversion_infopytestskiptest_daemonrun_cmd)selfr    r   k/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/mypy/test/testdaemon.pyrun_case    s
   

zDaemonSuite.run_caseNr   r   r   r   )__name__
__module____qualname__daemon_filesfilesr   r   r   r   r   r      s    r   r   r   r   r   c                 C  s   | j d us	J dtt| jD ]G\}}|d }|dd  }|ds%J |dd   }|dtj}t	|\}}|
 }t|}|rK|d|  t||d|d |f  qd S )Nztest was not properly set upr      $z{python}z== Return code: %dz,Command %d (%s) did not give expected output)old_cwd	enumerateparse_scriptinput
startswithstripreplacer   
executabler   
splitlinesr   appendr
   )r   istepcmdexpected_linesstsoutputoutput_linesr   r   r   r   *   s$   r   r*   	list[str]list[list[str]]c                 C  s\   g }g }| D ]}| dr|r|d  dsJ || g }|| q|r,|| |S )zParse testcase.input into steps.

    Each command starts with a line starting with '$'.
    The first line (less '$') is sent to the shell.
    The remaining lines are expected output.
    r&   r   )r+   r0   )r*   stepsr2   liner   r   r   r)   >   s   


r)   strtuple[int, str]c              
   C  s   |  drtjd |  } |  drtjd |  } tj }t|d< ztj| dtj	dt
|d}d|fW S  tjyK } z|j|jfW  Y d }~S d }~ww )	Nzdmypy z	 -m mypy.zmypy z -m
PYTHONPATHT)shellstderrtextcwdenvr   )r+   r   r.   osenvironcopyr   
subprocesscheck_outputSTDOUTr   CalledProcessError
returncoder6   )r*   rC   r6   errr   r   r   r   S   s   



r   c                   @  s$   e Zd ZdZdddZdd	d
ZdS )DaemonUtilitySuitezUnit tests for helpersr   r   c                   s   t  p |  d |  d |  d |  d |  d |  d |  d |  d |  d	 d fdd}t|df|df|d|df|dfd}t }th d||}|h dkslJ W d    d S 1 sww   Y  d S )Nzbase/a/z	base/b.pyz
base/c.pyizbase/missing.txtztypeshed/d.pyiztypeshed/@python2/ezpkg1/f-stubszpkg2/g-python2-stubszmpath/sub/long_name/pr<   r   c                   s   t j | S )N)rD   pathjoin)rN   tdr   r   makepathr   s   zODaemonUtilitySuite.test_filter_out_missing_top_level_packages.<locals>.makepathbasez	mpath/subpkg1pkg2typeshed)python_path	mypy_pathpackage_pathtypeshed_path>
   abcdefgffmissing	long_name>   r\   r]   r^   r_   ra   re   )rN   r<   r   r<   )tempfileTemporaryDirectory	make_filer   r   r   )r   rS   searchfscacheresr   rQ   r   *test_filter_out_missing_top_level_packagesf   s.   

"z=DaemonUtilitySuite.test_filter_out_missing_top_level_packagesrT   r<   rO   c                 C  sl   t j||}t jt j|dd |ds4t|d}|d W d    d S 1 s-w   Y  d S d S )NT)exist_ok/wz# test file)rD   rO   rP   makedirsdirnamer   openwrite)r   rT   rO   fullpathra   r   r   r   rh      s   
"zDaemonUtilitySuite.make_fileN)r   r   )rT   r<   rO   r<   r   r   )r    r!   r"   __doc__rl   rh   r   r   r   r   rM   c   s    
rM   r   )r*   r8   r   r9   )r*   r<   r   r=   )ru   
__future__r   rD   rG   r   rf   unittestr   mypy.dmypy_serverr   mypy.fscacher   mypy.modulefinderr   mypy.test.configr   r   mypy.test.datar   r	   mypy.test.helpersr
   r   r#   r   r   r)   r   TestCaserM   r   r   r   r   <module>   s(    


