
    7bh7                        	 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      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)    )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                   "    e Zd Z	 ddZd Zd Zy)TemporaryPyFileNc                      || _         || _        y N)source_codedir)selfr   	directorys      </opt/python-3.12.12/usr/lib/python3.12/test/test_tabnanny.py__init__zTemporaryPyFile.__init__B   s    &    c                     t        j                  d| j                  dd      5 }|j                  | j                         d d d        j
                  | _        | j                  S # 1 sw Y   &xY w)Nwz.pyF)moder   suffixdelete)tempfileNamedTemporaryFiler   writer   name	file_path)r   fs     r   	__enter__zTemporaryPyFile.__enter__F   sY    (($((5
GGD$$%
 ~~
 
s   A%%A.c                 .    t        | j                         y r   )r	   r$   )r   exc_type	exc_valueexc_tracebacks       r   __exit__zTemporaryPyFile.__exit__N   s    t~~r   ) N)__name__
__module____qualname__r   r&   r+    r   r   r   r   ?   s    5r   r   c                       e Zd Z	 d Zy)TestFormatWitnessesc                     	 g d}|D ]F  \  }}| j                  ||      5  | j                  t        j                  |      |       d d d        H y # 1 sw Y   SxY w)N))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tabnannyformat_witnesses)r   testsr6   r7   s       r   test_format_witnessesz)TestFormatWitnesses.test_format_witnessesU   sV    I
  %OE8EH=  !:!:5!A8L >=  %==s   &AA	N)r-   r.   r/   r=   r0   r   r   r2   r2   R   s    0Mr   r2   c                       e Zd Z	 d Zy)TestErrPrintc           	         	 ddgdfdgdfg ddfg dfg}|D ]  \  }}| j                  ||      5  | j                  t              5  t               5 }t	        j
                  |  d d d        | j                  j                         |       d d d        d d d         y # 1 sw Y   <xY w# 1 sw Y    xY w# 1 sw Y   xY w)	Nfirstsecondzfirst second
zfirst
)         z1 2 3

)	argumentsr7   )r8   assertRaises
SystemExitr   r:   errprintr9   getvalue)r   r<   argsr7   stderrs        r   test_errprintzTestErrPrint.test_errprintf   s    Px "23Y	"	"J	
 $ND(x@&&z2(*f ))40 +$$V__%6B 3 A@ $ +* 32 A@s;   B7B+B	$(B+B7B($B++B40B77C 	N)r-   r.   r/   rN   r0   r   r   r?   r?   c   s    (Cr   r?   c                       e Zd Zd Zy)TestNannyNagc                 n   	 t        j                  ddd      ddddft        j                  ddd      ddddfg}|D ]  \  }}|j                         }|j                         }|j	                         }| j                  ||d   	      5  | j                  |d   |       d d d        | j                  ||d
         5  | j                  |d
   |       d d d        | j                  ||d         5  | j                  |d   |       d d d         y # 1 sw Y   txY w# 1 sw Y   LxY w# 1 sw Y   xY w)Nr   foobar)linenomsgline   testmsgtestlinerT   )line_numberr7   rU   )rU   r7   rV   )rV   r7   )r:   NannyNag
get_linenoget_msgget_liner8   r9   )r   r<   nannyr7   rZ   rU   rV   s          r   test_all_methodszTestNannyNag.test_all_methodsx   s=   C !!!UE2UE:
 !!!Y
;Y
C	
  %OE8**,K--/C>>#D'(82D     (!3[A #@  %#6 A4(62BC  &!148 DC  %  A@CCs$   
D>D2D+D	D(	+D4	N)r-   r.   r/   r`   r0   r   r   rP   rP   w   s    9r   rP   c                   R    e Zd Z	 d ZddZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)	TestCheckc                 n    | j                  t        t        dt        j                         dt        _        y )Nverboser   )
addCleanupsetattrr:   rd   )r   s    r   setUpzTestCheck.setUp   s"    9h6F6FGr   c                 ,   	 t               5 }t               5 }t        j                  |       d d d        d d d        | j	                  j                         |       | j	                  j                         |       y # 1 sw Y   RxY w# 1 sw Y   VxY wr   )r   r   r:   checkr9   rK   )r   dir_or_fileouterrstdoutrM   s         r   verify_tabnanny_checkzTestCheck.verify_tabnanny_check   sj    	 &/*;vNN;' +<*C0*C0 +<*;s!   B
A>B
>B	B

Bc                 v    	 t        t        d         5 }| j                  |       d d d        y # 1 sw Y   y xY wNr   r   SOURCE_CODESrn   r   r$   s     r   test_correct_filezTestCheck.test_correct_file   s.    ;\,78I&&y1 988   /8c           
         	 t        j                         5 }|dg}t        t        d   |      }t        t        d   |      }|5 }|5 }||fD ]  }|j	                  |d        dt
        _        t               5 }t               5 }	t        j                  |       d d d        d d d        j                         }|D ]/  }
| j                  |
      5  | j                  |
|       d d d        1 | j                  	j                         d       d d d        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   >xY w# 1 sw Y   BxY w# 1 sw Y   y xY w)Nz: listing directory
r   r   z: Clean bill of health.
rC   )rV   r,   )r    TemporaryDirectoryr   rr   appendr:   rd   r   r   ri   rK   r8   assertInr9   )r   tmp_dirlinesfile1file2
file1_path
file2_pathr$   rm   rM   rV   s              r   test_correct_directory_verbosez(TestCheck.test_correct_directory_verbose   s5   	 ((*g{"78:E#L$>'RE#L$>'RE*ez",j!9ILLI=0I!JK ": $% $&&/2CvNN7+ 3D&*!D40dF3 10 "   !2B7 ',	 +* 3D2C&& 10 ',e	 +*s   1E'E
3E=D7	D+D7	&/EE(*EEE'+D40D7	7E <EEEEEE$	 E''E0c                     	 t        j                         5 }t        t        d   |      5  | j	                  |       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   rw   )r    rx   r   rr   rn   )r   r{   s     r   test_correct_directoryz TestCheck.test_correct_directory   sN    O((*g l!;wO**73 P +*OO +*s!   AAAA	AA#c                     	 t        t        d         5 }d}|d| }| j                  t              5  | j	                  ||       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   Iunindent does not match any outer indentation level (<tokenize>, line 3)
: Indentation Error: rl   r   rr   rH   rI   rn   r   r$   rl   s      r   test_when_wrong_indentedz"TestCheck.test_when_wrong_indented   sm    P\*:;<	*CM!6se<C"":.**9#*> /	 =< /.	 =<"   A$AA$A!	A$$A-c                     	 t        t        d         5 }d}|d| }| j                  t              5  | j	                  ||       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr
   z(('EOF in multi-line statement', (7, 0))
z: Token Error: r   r   r   s      r   test_when_tokenize_tokenerrorz'TestCheck.test_when_tokenize_tokenerror   sl    S\*ABCy=CM6C"":.**9#*> / DC /. DCr   c                     	 t        t        d         5 }|d}|dz  }|dz  }dt        _        | j	                  ||       d d d        y # 1 sw Y   y xY w)Nr   z': *** Line 3: trouble in tab city! ***
z#offending line: '\tprint("world")'
z3inconsistent use of tabs and spaces in indentation
rC   rk   )r   rr   r:   rd   rn   r   r$   rk   s      r    test_when_nannynag_error_verbosez*TestCheck.test_when_nannynag_error_verbose   sc    	 \*<=>)M!IJC<<CIIC H&&yc&: ?>>s   .AAc                     	 t        t        d         5 }| d}| j                  ||       d d d        y # 1 sw Y   y xY w)Nr   z 3 '\tprint("world")'
r   rq   r   s      r   test_when_nannynag_errorz"TestCheck.test_when_nannynag_error   sA    Q\*<=>)K9:C&&yc&: ?>>s   6?c                     	 d}|dt         j                   dt        j                  t         j                         d|d}| j	                  t
              5  | j                  ||       d d d        y # 1 sw Y   y xY w)Nz
no_file.pyz: I/O Error: [Errno z] z: rF   r   )errnoENOENTosstrerrorrH   rI   rn   )r   pathrl   s      r   test_when_no_filezTestCheck.test_when_no_file   sk    D-ell^2U\\*+2dXR9z*&&t&5 +**s   A33A<c           	         	 t        j                         5 }t        t        d   |      }t        t        d   |      }|5 }|5 }d}|d| }| j	                  t
              5  | j                  ||       d d d        d d d        d d d        d d d        y # 1 sw Y   "xY w# 1 sw Y   &xY w# 1 sw Y   *xY w# 1 sw Y   y xY w)Nr   rw   r   r   r   r   )r    rx   r   rr   rH   rI   rn   )r   r{   
error_file	code_filee_filec_filerl   s          r   test_errored_directoryz TestCheck.test_errored_directory   s    M((*g(-.'J (\*gI vyF6
"7u=&&z2..wC.@ 3	 (1 +* 32	 (1y +*sS   +B<B0B$#B	7B$?B0B<B!B$$B-)B00B9	5B<<CN)r,   r,   )r-   r.   r/   rg   rn   rt   r   r   r   r   r   r   r   r   r0   r   r   rb   rb      s=    #12
804??;;6Ar   rb   c                   D    e Zd Z	  ej                  d      d        Zd Zy)TestProcessTokensztabnanny.NannyNagc                 .   	 t        t        d         5 }t        |      5 }t        j                  t        j                  |j                               d d d        | j                  |j                         d d d        y # 1 sw Y   -xY w# 1 sw Y   y xY wrp   )
r   rr   openr:   process_tokenstokenizegenerate_tokensreadlineassertFalsecalled)r   MockNannyNagr$   r%   s       r   test_with_correct_codez(TestProcessTokens.test_with_correct_code	  sj    K\,78IiA''(@(@(LM !\001 98  98s"   B3A?#B?B	BBc           
         	 dD ]  }| j                  |      5  t        t        |         5 }t        |      5 }t	        j
                  |j                        }| j                  t        j                        5  t        j                  |       d d d        d d d        d d d        d d d         y # 1 sw Y   $xY w# 1 sw Y   (xY w# 1 sw Y   ,xY w# 1 sw Y   xY w)N)r   r   )key)r8   r   rr   r   r   r   r   rH   r:   r[   r   )r   r   r$   r%   tokenss        r   test_with_errored_codes_samplesz1TestProcessTokens.test_with_errored_codes_samples  s    L BC#&$\#%679iA!)!9!9!**!E!..x/@/@A$33F; B ) 8 '& B
 BA ) 87 '&sQ   CC?B<	7B0B<	CC0B95B<	<CCCCC	N)r-   r.   r/   r   patchr   r   r0   r   r   r   r     s(    .TZZ#$2 %2<r   r   c                   D    e Zd Z	 ddddddZd Zd Zd Zd Zd	 Zd
 Z	y)TestCommandLiner,   F)rm   rM   partialexpect_failurec                h   	 |rt        j                  ddg| \  }}}nt        j                  ddg| \  }}}t        j                  |      }t        j                  |      }|rd||f||ffD ]X  \  }	}
|
j                         }|	j                         D ]0  }| j                  ||      5  | j                  ||       d d d        2 Z y | j                  |j                         |j                                | j                  |j                         |j                                y # 1 sw Y   xY w)Nz-mr:   )stdoutput)	r   assert_python_failureassert_python_okr   fsdecode
splitlinesr8   rz   assertListEqual)r   rm   rM   r   r   rL   _rk   rl   r   r   _output_stds                r   validate_cmdzTestCommandLine.validate_cmd'  s   P'==dJVQUVKAsC'88zQDQKAsC kk#kk#!'}=V ++-NN,D$w?dG4 @? -  >   !163D3D3FG  !163D3D3FG	 @?s   +D((D1c                     	 t        t        d         5 }|d}|dz  }| j                  ||d       d d d        y # 1 sw Y   y xY w)Nr   r   zFunindent does not match any outer indentation level (<string>, line 3)TrM   r   r   rr   r   )r   r$   rM   s      r   test_with_errored_filez&TestCommandLine.test_with_errored_file;  sR    F\*:;<	"%:;F - .FitL	 =<<s	   <Ac                 v    	 t        t        d         5 }| j                  |       d d d        y # 1 sw Y   y xY wrp   r   rs   s     r   test_with_error_free_filez)TestCommandLine.test_with_error_free_fileC  s.    O\,78Ii( 988ru   c                 N    	 t        d      }d| d}| j                  |d       y )Nztabnanny.pyzUsage: z [-v] file_or_directory ...Tr   )r   r   )r   r   rM   s      r   test_command_usagez"TestCommandLine.test_command_usageH  s1    3&4& ;<=r   c                     	 t        t        d         5 }| d}| j                  d||       d d d        y # 1 sw Y   y xY w)Nr   rF   z-q)rm   r   )r   r$   rm   s      r   test_quiet_flagzTestCommandLine.test_quiet_flagN  sB    8\*<=>)!{"%FdIf= ?>>s	   7A c                     	 t        t        d         5 }t        j                  d      j	                         }| j                  d||d       d d d        y # 1 sw Y   y xY w)Nr   "offending line: '\tprint("world")'z-vTrm   r   r   rr   textwrapdedentstripr   r   r   rm   s      r   test_verbose_modez!TestCommandLine.test_verbose_modeT  sU    J\*<=>$__7eg  dDF	 ?>>   9AAc                     	 t        t        d         5 }t        j                  d      j	                         }| j                  d||d       d d d        y # 1 sw Y   y xY w)Nr   r   z-vvTr   r   r   s      r   test_double_verbose_modez(TestCommandLine.test_double_verbose_mode\  sU    P\*<=>$__7eg  eT&$G	 ?>>r   N)
r-   r.   r/   r   r   r   r   r   r   r   r0   r   r   r   r   $  s6    5)+BV[ H(M)
>>GHr   r   )unittestr   r   r   r   r:   r   r    r   test.supportr   r   r   r   test.support.os_helperr	   rr   r   r2   r?   rP   rb   r   r   r0   r   r   <module>r      s   
 $  	    $ $ )
		%	%	%	!	'K*Z &M( M"C8 C(98 96qA qAh< <<>Hh >Hr   