
    X-Ph                        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mZ ddlmZmZ dd	lmZmZ d
gZ G d de          ZddZddZddZ G 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                      e Zd ZeZddZdS )DaemonSuitetestcaser	   returnNonec                l    	 t          |           t          d           d S # t          d           w xY w)Nz
dmypy kill)test_daemonrun_cmd)selfr   s     T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/test/testdaemon.pyrun_casezDaemonSuite.run_case   s?    	"!!! L!!!!!GL!!!!s   " 3Nr   r	   r   r   )__name__
__module____qualname__daemon_filesfilesr        r   r   r      s-        E" " " " " "r   r   r   r	   r   r   c                   | j         
J d            t          t          | j                            D ]\  }}|d         }|dd          }|                    d          sJ |dd                                          }|                    dt          j                  }t          |          \  }}|
                                }t          |          }|r|                    d|z             t          ||d|dz   |fz             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replacesys
executabler   
splitlinesr   appendr   )r   istepcmdexpected_linesstsoutputoutput_liness           r   r   r   &   s   '')G'''\(.99:: 
 
41gabb~~c"""""!""gmmookk*cn55cllV((**/== 	< 4s :;;;":a!eS\I	
 	
 	
 	

 
r   r&   	list[str]list[list[str]]c                   g }g }| D ]b}|                     d          r6|r4|d                              d          sJ |                    |           g }|                    |           c|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&   stepsr/   lines       r   r%   r%   :   s     ED  ??3 	 Aw))#.....T"""D TLr   strtuple[int, str]c                   | dd                               d          r	d| vr| dz  } |                      d          rt          j        dz   | z   } |                      d          rt          j        dz   | z   } t          j                                        }t          |d	<   	 t          j        | d
t          j	        d
t          |          }d|fS # t          j        $ r}|j        |j        fcY d }~S d }~ww xY w)Nr!   zmypy run --z--show-error-codesz --hide-error-codesz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
returncoder3   )r&   rB   r3   errs       r   r   r   O   s   QRRyM** '/C5/P/P&&!! 5,u4   /&.
*//

CC*(j&7d[^
 
 
 &y( * * *~sz)))))))*s   ,C C2C-'C2-C2c                  "    e Zd ZdZd
dZddZd	S )DaemonUtilitySuitezUnit tests for helpersr   r   c           	        t          j                    5 |                     d           |                     d           |                     d           |                     d           |                     d           |                     d           |                     d           |                     d           |                     d	           dfd}t           |d          f |d          f |d           |d          f |d          f          }t	                      }t          h d||          }|h dk    sJ 	 d d d            d S # 1 swxY w 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                D    t           j                            |           S )N)rC   pathjoin)rO   tds    r   makepathzODaemonUtilitySuite.test_filter_out_missing_top_level_packages.<locals>.makepathp   s    w||B***r   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`   rb   rf   )rO   r:   r   r:   )tempfileTemporaryDirectory	make_filer   r   r   )r   rT   searchfscacheresrS   s        @r   *test_filter_out_missing_top_level_packagesz=DaemonUtilitySuite.test_filter_out_missing_top_level_packagesd   s   (** 	AbNN2y)))NN2{+++NN2|,,,NN21222NN2/000NN24555NN2~...NN25666NN25666+ + + + + + !%Xf--/#8K002&hv..0@0@A'x
335	  F &''G7QQQSY[b C @@@@@@@@1	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	As   D=E  E$'E$rU   r:   rQ   c                V   t           j                            ||          }t          j        t           j                            |          d           |                    d          s@t          |d          5 }|                    d           d d d            d S # 1 swxY w Y   d S d S )NT)exist_ok/wz# test file)rC   rQ   rR   makedirsdirnameendswithopenwrite)r   rU   rQ   fullpathrb   s        r   ri   zDaemonUtilitySuite.make_file   s    7<<d++
BGOOH--====}}S!! 	'h$$ '&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '	' 	's   9BB #B N)r   r   )rU   r:   rQ   r:   r   r   )r   r   r   __doc__rm   ri   r   r   r   rM   rM   a   sF          A A A A6' ' ' ' ' 'r   rM   r   )r&   r5   r   r6   )r&   r:   r   r;   )rx   
__future__r   rC   rF   r*   rg   unittest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   <module>r      sw    # " " " " " 				     



   C C C C C C ( ( ( ( ( ( ) ) ) ) ) ) 2 2 2 2 2 2 2 2 8 8 8 8 8 8 8 8 R R R R R R R R " " " " ") " " "
 
 
 
(   ** * * *$#' #' #' #' #'* #' #' #' #' #'r   