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mZm	Z	 ddl
mZmZ ddlmZmZmZ zddlZW n eyC   dZY nw ddlZejZg dZG dd	 d	eZdddZdddZ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.
    )annotationsN)PREFIXtest_temp_dir)DataDrivenTestCase	DataSuite)assert_string_arrays_equalcheck_test_output_filesnormalize_error_messages)zcmdline.testzcmdline.pyproject.testreports.testzenvvars.testc                   @  s   e Zd ZeZdZd	ddZdS )
PythonCmdlineSuiteTtestcaser   returnNonec                 C  sH   t d u rtj|jdkrtd dgt|j D ]}t	|| qd S )Nr
   z$Cannot import lxml. Is it installed?   )
lxmlospathbasenamefilepytestskipsortedoutput2test_python_cmdline)selfr   step r   M/home/garg/my-data/venv/lib/python3.10/site-packages/mypy/test/testcmdline.pyrun_case(   s
   
zPythonCmdlineSuite.run_caseN)r   r   r   r   )__name__
__module____qualname__cmdline_filesfiles
native_sepr   r   r   r   r   r   $   s    r   r   r   r   intr   r   c              	     s  | j d us	J dd}tjt|}t|ddd}| jD ]
}|| d qW d    n1 s2w   Y  t| jd }t	| jdkrLt
| jd nd }|d	 d
|vr\|d d|vre|d d|vrn|d d|vrw|d d|v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|pd  fdd|D }tj|| tjtj |	d}| \}}|j}dd t|d D }dd t|d D }dtjv rt|D ]\}}|d r|||d! =  nqt| | jr;|s|r4td"| j r(d#| nd|d|| f t!| | d S | j"rEt#|| }|rJdnd}||krY|d$|  |dkra| j$n| j | }d%d |D }t%||d&&| j'| j(| j r~d#| 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--show-error-codesz--hide-error-codesz--disallow-empty-bodiesz--allow-empty-bodiesz--no-force-uppercase-builtinsz--force-uppercase-builtinsz--no-force-union-syntaxz--force-union-syntaxz-mmypyCOLUMNSpypath
PYTHONPATH c                   s    g | ]}| d tj qS )z$CWD)replacer   r   abspath).0argcwdr   r   
<listcomp>M   s     z'test_python_cmdline.<locals>.<listcomp>)stdoutstderrr4   envc                 S     g | ]}| d qS z
rstripr1   sr   r   r   r5   T       c                 S  r9   r:   r;   r=   r   r   r   r5   U   r?   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.   )r/   r   sepr=   r   r   r   r5   q   s    zInvalid output ({}, line {}){}))old_cwdr   r   joinr   openinputwrite
parse_argslen	parse_cwdappendpython3_pathenvironcopypopr0   r   isdirpathsep
subprocessPopenPIPEcommunicate
returncodestr
splitlines	enumerate
startswithremoveoutput_filesAssertionErrorr   r   normalize_outputr	   outputr   formatr   line)r   r   programprogram_pathr   r>   args
custom_cwdfixedr8   
extra_pathprocessoutberrbresultouterrposrb   obvious_resultexpected_outr   r3   r   r   /   s   
 








"
r   rb   rX   	list[str]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rb   mr   r   r   rI   {   s   rI   
str | Nonec                 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)rs   rt   ru   rw   r   r   r   rK      s   rK   )r   r   r   r%   r   r   )rb   rX   r   rr   )rb   rX   r   ry   )__doc__
__future__r   r   rs   rS   sysmypy.test.configr   r   mypy.test.datar   r   mypy.test.helpersr   r   r	   r   ImportErrorr   
executablerM   r"   r   r   rI   rK   r   r   r   r   <module>   s*    

L