o
    HXh5                     @   s   	 d dl mZ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
mZmZmZ d dlmZ ddddd	d
dZG dd dZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdS )    )TestCasemockN)captured_stderrcaptured_stdoutscript_helperfindfile)unlinkzCfruits = [
    "Apple",
    "Orange",
    "Banana",

print(fruits)
zLif True:
    print("hello")
  print("world")
else:
    print("else called")
zIif True:
 	print("hello")
	print("world")
else:
    print("else called")
zNif True:
    print("hello")
    print("world")
else:
    print("else called")
zGdef my_func():
	  print("hello world")
	  if True:
		print("If called")zLdef my_func():
		print("Hello world")
		if True:
	        print("If called"))incomplete_expressionwrong_indentednannynag_errored
error_freetab_space_errored_1tab_space_errored_2c                   @   s(   e Zd Z	 d	ddZdd Zdd ZdS )
TemporaryPyFile Nc                 C   s   || _ || _d S N)source_codedir)selfr   	directory r   </opt/python-3.10.19/usr/lib/python3.10/test/test_tabnanny.py__init__B   s   
zTemporaryPyFile.__init__c                 C   sN   t jd| jddd}|| j W d    n1 sw   Y  |j| _| jS )Nwz.pyF)moder   suffixdelete)tempfileNamedTemporaryFiler   writer   name	file_path)r   fr   r   r   	__enter__F   s   
zTemporaryPyFile.__enter__c                 C   s   t | j d S r   )r   r!   )r   exc_type	exc_valueexc_tracebackr   r   r   __exit__N   s   zTemporaryPyFile.__exit__)r   N)__name__
__module____qualname__r   r#   r'   r   r   r   r   r   ?   s
    
r   c                   @      e Zd Z	 dd ZdS )TestFormatWitnessesc              	   C   s\   	 g d}|D ]$\}}| j ||d | t|| W d    n1 s&w   Y  qd S )N))ZTestzat tab sizes T, e, s, t)r   zat tab size )tzat tab size t)z  t  zat tab sizes  ,  , t,  ,  )wordsexpected)subTestassertEqualtabnannyZformat_witnesses)r   testsr.   r/   r   r   r   test_format_witnessesU   s   z)TestFormatWitnesses.test_format_witnessesN)r(   r)   r*   r4   r   r   r   r   r,   R       r,   c                   @   r+   )TestErrPrintc              
   C   s   	 ddgdfdgdfg ddfg dfg}|D ];\}}| j ||d( t }tj|  W d    n1 s5w   Y  | | | W d    n1 sLw   Y  qd S )	Nfirstsecondzfirst second
zfirst
)         z1 2 3

)Z	argumentsr/   )r0   r   r2   Zerrprintr1   getvalue)r   r3   argsr/   stderrr   r   r   test_errprintf   s   

zTestErrPrint.test_errprintN)r(   r)   r*   r@   r   r   r   r   r6   c   r5   r6   c                   @   s   e Zd Zdd ZdS )TestNannyNagc              	   C   s&  	 t dddddddft dddddddfg}|D ]s\}}| }| }| }| j||d d	 | |d | W d    n1 sIw   Y  | j||d
 d | |d
 | W d    n1 sjw   Y  | j||d d | |d | W d    n1 sw   Y  qd S )Nr   ZfooZbar)linenomsgline   ZtestmsgZtestlinerB   )line_numberr/   rC   )rC   r/   rD   )rD   r/   )r2   NannyNagZ
get_linenoZget_msgZget_liner0   r1   )r   r3   Znannyr/   rF   rC   rD   r   r   r   test_all_methodsw   s2   


zTestNannyNag.test_all_methodsN)r(   r)   r*   rH   r   r   r   r   rA   v   s    rA   c                   @   sh   e Zd Z	 dd ZdddZdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )	TestCheckc                 C   s   |  ttdtj dt_d S )Nverboser   )Z
addCleanupsetattrr2   rJ   )r   r   r   r   setUp   s   
zTestCheck.setUpr   c              	   C   s|   	 t   }t }t| W d    n1 sw   Y  W d    n1 s'w   Y  | | | | | | d S r   )r   r   r2   checkr1   r=   )r   Zdir_or_fileouterrstdoutr?   r   r   r   verify_tabnanny_check   s    zTestCheck.verify_tabnanny_checkc                 C   >   	 t td }| | W d    d S 1 sw   Y  d S Nr   r   SOURCE_CODESrQ   r   r!   r   r   r   test_correct_file      "zTestCheck.test_correct_filec                 C   s  	 t  }|dg}ttd |d}ttd |d}|}|r}||fD ]
}||d q&dt_t  }t }	t	| W d    n1 sKw   Y  W d    n1 sZw   Y  |
 }|D ]}
| j|
d | |
| W d    n1 s~w   Y  qe| |	
 d W d    n1 sw   Y  W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nz: listing directory
r   r   z: Clean bill of health.
r9   )rD   r   )r   TemporaryDirectoryr   rU   appendr2   rJ   r   r   rM   r=   r0   assertInr1   )r   tmp_dirlinesZfile1Zfile2Z
file1_pathZ
file2_pathr!   rP   r?   rD   r   r   r   test_correct_directory_verbose   s6   
  "z(TestCheck.test_correct_directory_verbosec              	   C   sz   	 t  .}ttd |d | | W d    n1 sw   Y  W d    d S W d    d S 1 s6w   Y  d S )Nr   rY   r   rZ   r   rU   rQ   )r   r]   r   r   r   test_correct_directory   s   
"z TestCheck.test_correct_directoryc                 C   T   	 t td }d}|d| }| j||d W d    d S 1 s#w   Y  d S )Nr
   Iunindent does not match any outer indentation level (<tokenize>, line 3)
: Indentation Error: rO   rT   r   r!   rO   r   r   r   test_when_wrong_indented   s   "z"TestCheck.test_when_wrong_indentedc                 C   rb   )Nr	   z(('EOF in multi-line statement', (7, 0))
z: Token Error: re   rT   rf   r   r   r   test_when_tokenize_tokenerror   s   "z'TestCheck.test_when_tokenize_tokenerrorc                 C   sb   	 t td  }|d}|d7 }|d7 }dt_| j||d W d    d S 1 s*w   Y  d S )Nr   z': *** Line 3: trouble in tab city! ***
z%offending line: '\tprint("world")\n'
z$indent not equal e.g. at tab size 1
r9   rN   )r   rU   r2   rJ   rQ   r   r!   rN   r   r   r    test_when_nannynag_error_verbose   s   
"z*TestCheck.test_when_nannynag_error_verbosec                 C   sL   	 t td }| d}| j||d W d    d S 1 sw   Y  d S )Nr   z 3 '\tprint("world")\n'
ri   rT   rj   r   r   r   test_when_nannynag_error   s
   
"z"TestCheck.test_when_nannynag_errorc                 C   s>   	 d}|dt j dtt j d|d}| j||d d S )Nz
no_file.pyz: I/O Error: [Errno z] z: r<   re   )errnoENOENTosstrerrorrQ   )r   pathrO   r   r   r   test_when_no_file   s   
zTestCheck.test_when_no_filec              
   C   s   	 t  U}ttd |d}ttd |d}|*}|}d}|d| }| j||d W d    n1 s6w   Y  W d    n1 sEw   Y  W d    d S W d    d S 1 s]w   Y  d S )Nr
   rY   r   rc   rd   re   r`   )r   r]   Z
error_fileZ	code_fileZe_fileZc_filerO   r   r   r   test_errored_directory   s$   
 "z TestCheck.test_errored_directoryN)r   r   )r(   r)   r*   rL   rQ   rW   r_   ra   rg   rh   rk   rl   rr   rs   r   r   r   r   rI      s    
rI   c                   @   s(   e Zd Z	 eddd Zdd ZdS )TestProcessTokensztabnanny.NannyNagc              	   C   sz   	 t td ,}t|}tt|j W d    n1 s w   Y  | |j	 W d    d S 1 s6w   Y  d S rS   )
r   rU   openr2   process_tokenstokenizegenerate_tokensreadlineZassertFalseZcalled)r   ZMockNannyNagr!   r"   r   r   r   test_with_correct_code  s   
"z(TestProcessTokens.test_with_correct_codec                 C   s   	 dD ]c}| j |dS tt| =}t|)}t|j}| tj	 t
| W d    n1 s4w   Y  W d    n1 sCw   Y  W d    n1 sRw   Y  W d    n1 saw   Y  qd S )N)r   r   )key)r0   r   rU   ru   rw   rx   ry   ZassertRaisesr2   rG   rv   )r   r{   r!   r"   tokensr   r   r   test_with_errored_codes_samples  s"   
z1TestProcessTokens.test_with_errored_codes_samplesN)r(   r)   r*   r   Zpatchrz   r}   r   r   r   r   rt     s
    
rt   c                   @   sP   e Zd Z	 ddddddZdd Zdd	 Zd
d Zdd Zdd Zdd Z	dS )TestCommandLiner   F)rP   r?   partialc             
   G   s   	 t jddg|R  \}}}t|}t|}|rQ||f||ffD ],\}}	|	 }
| D ]}| j||
d | ||
 W d    n1 sHw   Y  q.q"d S | | |  | | |  d S )Nz-mr2   )stdoutput)r   Zassert_python_okro   fsdecode
splitlinesr0   r\   ZassertListEqual)r   rP   r?   r   r>   _rN   rO   r   r   Z_outputZ_stdr   r   r   validate_cmd"  s    

zTestCommandLine.validate_cmdc                 C   sT   	 t td }|d}|d7 }| j||d W d    d S 1 s#w   Y  d S )Nr
   rd   zHunindent does not match any outer indentation level (<tokenize>, line 3)r?   r   rU   r   )r   r!   r?   r   r   r   test_with_errored_file3  s   
"z&TestCommandLine.test_with_errored_filec                 C   rR   rS   r   rV   r   r   r   test_with_error_free_file;  rX   z)TestCommandLine.test_with_error_free_filec                 C   s&   	 t d}d| d}| j|d d S )Nztabnanny.pyzUsage: z [-v] file_or_directory ...r   )r   r   )r   rq   r?   r   r   r   test_command_usage@  s   z"TestCommandLine.test_command_usagec                 C   sN   	 t td }| d}| jd||d W d    d S 1 s w   Y  d S )Nr   r<   z-q)rP   r   )r   r!   rP   r   r   r   test_quiet_flagF  s
   
"zTestCommandLine.test_quiet_flagc                 C   T   	 t td }td }| jd||dd W d    d S 1 s#w   Y  d S )Nr   $offending line: '\tprint("world")\n'z-vTrP   r   r   rU   textwrapdedentstripr   r   rq   rP   r   r   r   test_verbose_modeL     "z!TestCommandLine.test_verbose_modec                 C   r   )Nr   r   z-vvTr   r   r   r   r   r   test_double_verbose_modeT  r   z(TestCommandLine.test_double_verbose_modeN)
r(   r)   r*   r   r   r   r   r   r   r   r   r   r   r   r~     s    r~   )Zunittestr   r   rm   ro   r2   rw   r   r   Ztest.supportr   r   r   r   Ztest.support.os_helperr   rU   r   r,   r6   rA   rI   rt   r~   r   r   r   r   <module>   s0    -p