B
    '(bA                 @   s   d 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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 dd	lmZmZ d
gZG dd deZeddddZee eee  dddZeeeef 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.
    N)ListTuple)SearchPaths)FileSystemCache)%filter_out_missing_top_level_packages)test_temp_dirPREFIX)DataDrivenTestCase	DataSuite)assert_string_arrays_equalnormalize_error_messageszdaemon.testc               @   s    e Zd ZeZeddddZdS )DaemonSuiteN)testcasereturnc             C   s   zt | W d td X d S )Nz
dmypy kill)test_daemonrun_cmd)selfr    r   C/home/dcms/DCMS/lib/python3.7/site-packages/mypy/test/testdaemon.pyrun_case    s    zDaemonSuite.run_case)__name__
__module____qualname__daemon_filesfilesr	   r   r   r   r   r   r      s   r   )r   r   c             C   s   | j d k	stdxtt| jD ]\}}|d }|dd  }|dsLt|dd   }|dtj	}t
|\}}| }t|}|r|d|  t||d|d |f  q"W d S )Nztest was not properly set upr      $z{python}z== Return code: %dz,Command %d (%s) did not give expected output)Zold_cwdAssertionError	enumerateparse_scriptinput
startswithstripreplacesys
executabler   
splitlinesr   appendr   )r   istepcmdZexpected_linesstsoutputZoutput_linesr   r   r   r   (   s     r   )r    r   c             C   s`   g }g }xD| D ]<}| dr@|r@|d  ds2t|| g }|| qW |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!   r   r'   )r    Zstepsr)   liner   r   r   r   ;   s    



r   c          
   C   s   |  drtjd |  } |  dr0tjd |  } tj }t|d< y tj| dtj	dt
|d}d|fS  tjk
r } z|j|jfS d }~X Y nX d S )	Nzdmypy z	 -m mypy.zmypy z -m
PYTHONPATHT)shellstderruniversal_newlinescwdenvr   )r!   r$   r%   osenvironcopyr   
subprocesscheck_outputSTDOUTr   CalledProcessError
returncoder,   )r    r3   r,   errr   r   r   r   P   s     


r   c               @   s0   e Zd ZdZddddZeeddddZdS )	DaemonUtilitySuitezUnit tests for helpersN)r   c                s  t   |  d |  d |  d |  d |  d |  d |  d |  d |  d	 ttd
 fdd}t|df|df|d|df|dfd}t }tddddddddddh
||}|ddddddddhkstW d Q R X 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   c                s   t j | S )N)r4   pathjoin)r>   )tdr   r   makepathr   s    zODaemonUtilitySuite.test_filter_out_missing_top_level_packages.<locals>.makepathbasez	mpath/subZpkg1Zpkg2Ztypeshed)Zpython_pathZ	mypy_pathpackage_pathZtypeshed_pathabcdefgZ	long_nameffmissing)tempfileTemporaryDirectory	make_filestrr   r   r   r   )r   rB   searchZfscacheresr   )rA   r   *test_filter_out_missing_top_level_packagesf   s*    

z=DaemonUtilitySuite.test_filter_out_missing_top_level_packages)rC   r?   r   c          	   C   sR   t j||}t jt j|dd |dsNt|d}|d W d Q R X d S )NT)exist_ok/wz# test file)r4   r?   r@   makedirsdirnameendswithopenwrite)r   rC   r?   fullpathrJ   r   r   r   rP      s
    
zDaemonUtilitySuite.make_file)r   r   r   __doc__rT   rQ   rP   r   r   r   r   r=   c   s   r=   )!r^   r4   r7   r$   rN   Zunittesttypingr   r   Zmypy.modulefinderr   Zmypy.fscacher   Zmypy.dmypy_serverr   Zmypy.test.configr   r   Zmypy.test.datar	   r
   Zmypy.test.helpersr   r   r   r   r   rQ   r   intr   ZTestCaser=   r   r   r   r   <module>   s$   