B
    '(b&                 @   s   d 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	m
Z
 ddlmZmZ ddlmZmZmZ yddlZW n ek
r   dZY nX ddlZejZdd	d
dgZG dd deZeeddddZeee dddZeee dddZdS )zsTest cases for the command line.

To begin we test that "mypy <directory>[/]" always recurses down the
whole tree.
    N)List)Optional)test_temp_dirPREFIX)DataDrivenTestCase	DataSuite)assert_string_arrays_equalnormalize_error_messagescheck_test_output_fileszcmdline.testzcmdline.pyproject.testzreports.testzenvvars.testc               @   s$   e Zd ZeZdZeddddZdS )PythonCmdlineSuiteTN)testcasereturnc             C   sL   t d kr$tj|jdkr$td x"dgt|j D ]}t	|| q6W d S )Nzreports.testz$Cannot import lxml. Is it installed?   )
lxmlospathbasenamefilepytestskipsortedoutput2test_python_cmdline)selfr   step r   D/home/dcms/DCMS/lib/python3.7/site-packages/mypy/test/testcmdline.pyrun_case,   s    
zPythonCmdlineSuite.run_case)__name__
__module____qualname__cmdline_filesfilesZ
native_sepr   r   r   r   r   r   r   (   s   r   )r   r   r   c          	   C   s  | j d k	stdd}tjt|}t|ddd&}x| jD ]}|| d q<W W d Q R X t	| jd }t
| jdkrt| jd nd }|d	 d
|kr|d tddg}tj }	|	dd  tjtjtd}
t|	d< tj|
r
|	d  tj|
 7  < tj|| tjtjtjt|p,d|	d}| \}}|j}dd t|d D }dd t|d D }dtjkrx2t|D ]&\}}|dr|||d = P qW t| | jr|s|rtd| j rd| nd|d|| f t!| | n| j"r"t#|| }|r,dnd}||krJ|d|  |dkrZ| j$n| j | }dd |D }t%||d&| j'| j(| j rd| nd d S )Nztest was not properly set upz_program.pywutf8)encoding
r   r   z--show-tracebackz--error-summaryz--no-error-summaryz-mZmypyCOLUMNSZpypath
PYTHONPATH )stdoutstderrcwdenvc             S   s   g | ]}| d qS )z
)rstrip).0sr   r   r   
<listcomp>S   s    z'test_python_cmdline.<locals>.<listcomp>c             S   s   g | ]}| d qS )z
)r.   )r/   r0   r   r   r   r1   T   s    PYCHARM_HOSTEDzpydev debugger:    z6Expected zero status and empty stderr%s, got %d and
%sz on step %dz== Return code: c             S   s   g | ]}| d tj dqS )tmpr)   )replacer   sep)r/   r0   r   r   r   r1   p   s    zInvalid output ({}, line {}){}))Zold_cwdAssertionErrorr   r   joinr   openinputwrite
parse_argslen	parse_cwdappendpython3_pathenvironcopypopabspathr   isdirpathsep
subprocessPopenPIPEcommunicate
returncodestr
splitlines	enumerate
startswithremoveZoutput_filesr   r
   Znormalize_outputr	   outputr   formatr   line)r   r   programZprogram_pathr   r0   argsZ
custom_cwdZfixedr-   
extra_pathprocessZoutbZerrbresultouterrposrS   Zobvious_resultZexpected_outr   r   r   r   3   sj     







r   )rS   r   c             C   s"   t d| }|sg S |d S )zParse the first line of the program for the command line.

    This should have the form

      # cmd: mypy <options>

    For example:

      # cmd: mypy pkg/
    z# cmd: mypy (.*)$r   )rematchgroupsplit)rS   mr   r   r   r<   w   s    r<   c             C   s   t d| }|r|dS dS )zParse the second line of the program for the command line.

    This should have the form

      # cwd: <directory>

    For example:

      # cwd: main/subdir
    z# cwd: (.*)$r   N)r\   r]   r^   )rS   r`   r   r   r   r>      s    r>   )__doc__r   r\   rG   systypingr   r   Zmypy.test.configr   r   Zmypy.test.datar   r   Zmypy.test.helpersr   r	   r
   r   ImportErrorr   
executabler@   r!   r   intr   rL   r<   r>   r   r   r   r   <module>   s.   
D