
    <e5                     @   	 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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                   $    e Zd Z	 ddZd Zd ZdS )TemporaryPyFile Nc                 "    || _         || _        d S N)source_codedir)selfr   	directorys      )/usr/lib/python3.11/test/test_tabnanny.py__init__zTemporaryPyFile.__init__B   s    &    c                     t          j        d| j        dd          5 }|                    | j                   d d d            n# 1 swxY w Y   |j        | _        | j        S )Nwz.pyF)moder   suffixdelete)tempfileNamedTemporaryFiler   writer   name	file_path)r   fs     r   	__enter__zTemporaryPyFile.__enter__F   s    ($(5
 
 
 	&GGD$%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& ~s   AA	A	c                 .    t          | j                   d S r   )r	   r%   )r   exc_type	exc_valueexc_tracebacks       r   __exit__zTemporaryPyFile.__exit__N   s    t~r   )r   N)__name__
__module____qualname__r   r'   r,    r   r   r   r   ?   sI        5         r   r   c                       e Zd Z	 d ZdS )TestFormatWitnessesc                     	 g d}|D ]\\  }}|                      ||          5  |                     t          j        |          |           d d d            n# 1 swxY w Y   ]d S )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   s    I
 
 
  % 	M 	MOE8EH== M M  !:5!A!A8LLLM M M M M M M M M M M M M M M	M 	Ms   )AA	 A	N)r-   r.   r/   r=   r0   r   r   r2   r2   R   s+        0M M M M Mr   r2   c                       e Zd Z	 d ZdS )TestErrPrintc                 T   	 ddgdfdgdfg ddfg dfg}|D ]\  }}|                      ||          5  t                      5 }t          j        |  d d d            n# 1 swxY w Y   |                     |                                |           d d d            n# 1 swxY w Y   d S )	Nfirstsecondzfirst second
zfirst
)         z1 2 3

)	argumentsr7   )r8   r   r:   errprintr9   getvalue)r   r<   argsr7   stderrs        r   test_errprintzTestErrPrint.test_errprintf   sN   Px "23Y	"YY	"J	
 $ 	? 	?ND(x@@ ? ?$&& -&%t,,- - - - - - - - - - - - - - -  !2!2X>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?	? 	?s5   BABA!!B$A!%+BB 	#B 	N)r-   r.   r/   rL   r0   r   r   r?   r?   c   s&        (? ? ? ? ?r   r?   c                       e Zd Zd ZdS )TestNannyNagc                    	 t          j        ddd          ddddft          j        ddd          ddddfg}|D ]5\  }}|                                }|                                }|                                }|                     ||d         	          5  |                     |d         |           d d d            n# 1 swxY w Y   |                     ||d
                   5  |                     |d
         |           d d d            n# 1 swxY w Y   |                     ||d                   5  |                     |d         |           d d d            n# 1 swxY w Y   7d S )Nr   foobar)linenomsgline   testmsgtestlinerR   )line_numberr7   rS   )rS   r7   rT   )rT   r7   )r:   NannyNag
get_linenoget_msgget_liner8   r9   )r   r<   nannyr7   rX   rS   rT   s          r   test_all_methodszTestNannyNag.test_all_methodsw   sa   C !!UE22UE::
 !!Y
;;Y
CC	
  % 	9 	9OE8**,,K--//C>>##D'(82D    B B   (!3[AAAB B B B B B B B B B B B B B B #@@ 7 7  %#6667 7 7 7 7 7 7 7 7 7 7 7 7 7 74(62BCC 9 9  &!148889 9 9 9 9 9 9 9 9 9 9 9 9 9 9	9 	9s6   CC	C	,DD	D	=E&&E*	-E*	N)r-   r.   r/   r^   r0   r   r   rN   rN   v   s#        9 9 9 9 9r   rN   c                   T    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dS )	TestCheckc                 v    |                      t          t          dt          j                   dt          _        d S )Nverboser   )
addCleanupsetattrr:   rb   )r   s    r   setUpzTestCheck.setUp   s+    9h6FGGGr   r   c                 h   	 t                      5 }t                      5 }t          j        |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     |                                |           |                     |                                |           d S r   )r   r   r:   checkr9   rI   )r   dir_or_fileouterrstdoutrK   s         r   verify_tabnanny_checkzTestCheck.verify_tabnanny_check   s   	  	(&/*;*; 	(vN;'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(**C000**C00000s3   AA A A	AA	AAAc                     	 t          t          d                   5 }|                     |           d d d            d S # 1 swxY w Y   d S Nr   r   SOURCE_CODESrl   r   r%   s     r   test_correct_filezTestCheck.test_correct_file   s    ;\,788 	2I&&y111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2   ?AAc           
      d   	 t          j                    5 }|dg}t          t          d         |          }t          t          d         |          }|5 }|5 }||fD ]}|                    |d           dt
          _        t                      5 }t                      5 }	t          j	        |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |
                                }|D ]F}
|                     |
          5  |                     |
|           d d d            n# 1 swxY w Y   G|                     |	
                                d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nz: listing directory
r   r   z: Clean bill of health.
rC   )rT   r   )r!   TemporaryDirectoryr   rp   appendr:   rb   r   r   rg   rI   r8   assertInr9   )r   tmp_dirlinesfile1file2
file1_path
file2_pathr%   rk   rK   rT   s              r   test_correct_directory_verbosez(TestCheck.test_correct_directory_verbose   s*   	 (** 	8g888:E#L$>'RRRE#L$>'RRRE 8*e 8z",j!9 L LILLI!J!J!JKKKK#$ $&& ,&/2C2C ,vN7+++, , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,**! 4 4D400 4 4dF3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4  !2!2B7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8		8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   AF%F:E6C	"C7C	CC	
CC	E6CE6!C"1E6D6*E66D::E6=D:>,E6*F6E::F=E:>FF%F	F%F	F%%F),F)c                     	 t          j                    5 }t          t          d         |          5  |                     |           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   ru   r!   rv   r   rp   rl   )r   ry   s     r   test_correct_directoryz TestCheck.test_correct_directory   s    O(** 	4g l!;wOOO 4 4**73334 4 4 4 4 4 4 4 4 4 4 4 4 4 4	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s4   A,AA,A	A,A	A,,A03A0c                     	 t          t          d                   5 }d}|d| }|                     ||           d d d            d S # 1 swxY w Y   d S )Nr   Iunindent does not match any outer indentation level (<tokenize>, line 3)
: Indentation Error: rj   ro   r   r%   rj   s      r   test_when_wrong_indentedz"TestCheck.test_when_wrong_indented   s    P\*:;<< 	;	*C<<s<<C&&yc&:::		; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;   !A

AAc                     	 t          t          d                   5 }d}|d| }|                     ||           d d d            d S # 1 swxY w Y   d S )Nr
   z(('EOF in multi-line statement', (7, 0))
z: Token Error: r   ro   r   s      r   test_when_tokenize_tokenerrorz'TestCheck.test_when_tokenize_tokenerror   s    S\*ABCC 	;y=C6666C&&yc&:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;r   c                     	 t          t          d                   5 }|d}|dz  }|dz  }dt          _        |                     ||           d d d            d S # 1 swxY 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
rC   ri   )r   rp   r:   rb   rl   r   r%   ri   s      r    test_when_nannynag_error_verbosez*TestCheck.test_when_nannynag_error_verbose   s    	 \*<=>> 	;)JJJC??C::C H&&yc&:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   3AA #A c                     	 t          t          d                   5 }| d}|                     ||           d d d            d S # 1 swxY w Y   d S )Nr   z 3 '\tprint("world")\n'
r   ro   r   s      r   test_when_nannynag_errorz"TestCheck.test_when_nannynag_error   s    Q\*<=>> 	;)===C&&yc&:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   AA
A
c                     	 d}|dt           j         dt          j        t           j                   d|d}|                     ||           d S )Nz
no_file.pyz: I/O Error: [Errno z] z: rF   r   )errnoENOENTosstrerrorrl   )r   pathrj   s      r   test_when_no_filezTestCheck.test_when_no_file   sq    D 9 9el 9 9U\**9 9.29 9 9""4S"11111r   c                 x   	 t          j                    5 }t          t          d         |          }t          t          d         |          }|5 }|5 }d}|d| }|                     ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   ru   r   r   r   r   r   )r   ry   
error_file	code_filee_filec_filerj   s          r   test_errored_directoryz TestCheck.test_errored_directory   s   M(** 	=g(-.'  J (\*g  I  =vy =F6====**7*<<<	= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=sY   ;B/B!B 4B BBBBB/B	B/B	B//B36B3N)r   r   )r-   r.   r/   re   rl   rr   r   r   r   r   r   r   r   r   r0   r   r   r`   r`      s        #  1 1 1 12 2 2
8 8 804 4 4; ; ;; ; ;; ; ;; ; ;2 2 2= = = = =r   r`   c                   H    e Zd Z	  ej        d          d             Zd ZdS )TestProcessTokensztabnanny.NannyNagc                 F   	 t          t          d                   5 }t          |          5 }t          j        t          j        |j                             d d d            n# 1 swxY w Y   |                     |j	                   d d d            d S # 1 swxY w Y   d S rn   )
r   rp   openr:   process_tokenstokenizegenerate_tokensreadlineassertFalsecalled)r   MockNannyNagr%   r&   s       r   test_with_correct_codez(TestProcessTokens.test_with_correct_code  s   K\,788 	2Ii NA'(@(L(LMMMN N N N N N N N N N N N N N N\0111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s4   B,A$B$A(	(B+A(	,BBBc           
         	 dD ]}|                      |          5  t          t          |                   5 }t          |          5 }t	          j        |j                  }|                     t          j	                  5  t          j
        |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )N)r   r   )key)r8   r   rp   r   r   r   r   assertRaisesr:   rY   r   )r   r   r%   r&   tokenss        r   test_with_errored_codes_samplesz1TestProcessTokens.test_with_errored_codes_samples  s   L B 	< 	<C#&& < <$\#%677 <9i <A!)!9!*!E!E!..x/@AA < <$3F;;;< < < < < < < < < < < < < < << < < < < < < < < < < < < < << < < < < < < < < < < < < < << < < < < < < < < < < < < < <	< 	<s|   C&C9B8	 B!B8	!B%%B8	(B%)B8	,C8B<<C?B< CC&CC&CC&&C*	-C*	N)r-   r.   r/   r   patchr   r   r0   r   r   r   r     sM        .TZ#$$2 2 %$2< < < < <r   r   c                   D    e Zd Z	 dddddZd Zd Zd Zd Zd	 Zd
 Z	dS )TestCommandLiner   F)rk   rK   partialc                r   	 t          j        ddg|R  \  }}}t          j        |          }t          j        |          }|r||f||ffD ]u\  }}	|	                                }
|                                D ]G}|                     ||
          5  |                     ||
           d d d            n# 1 swxY w Y   Hvd S |                     |                                |                                           |                     |                                |                                           d S )Nz-mr:   )stdoutput)r   assert_python_okr   fsdecode
splitlinesr8   rx   assertListEqual)r   rk   rK   r   rJ   _ri   rj   r   r   _output_stds               r   validate_cmdzTestCommandLine.validate_cmd"  s   P#4T:MMMM3 k#k# 	H!'}= 5 5V ++--NN,, 5 5D$w?? 5 5dG4445 5 5 5 5 5 5 5 5 5 5 5 5 5 555 5   !1!163D3D3F3FGGG  !1!163D3D3F3FGGGGGs   B44B8;B8c                     	 t          t          d                   5 }|d}|dz  }|                     ||           d d d            d S # 1 swxY w Y   d S )Nr   r   zHunindent does not match any outer indentation level (<tokenize>, line 3)rK   r   rp   r   )r   r%   rK   s      r   test_with_errored_filez&TestCommandLine.test_with_errored_file3  s    F\*:;<< 	8	";;;F , -Fi777		8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   "AAAc                     	 t          t          d                   5 }|                     |           d d d            d S # 1 swxY w Y   d S rn   r   rq   s     r   test_with_error_free_filez)TestCommandLine.test_with_error_free_file;  s    O\,788 	)Ii(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)rs   c                 ^    	 t          d          }d| d}|                     |           d S )Nztabnanny.pyzUsage: z [-v] file_or_directory ...r   )r   r   )r   r   rK   s      r   test_command_usagez"TestCommandLine.test_command_usage@  s?    3&&<4<<<(((((r   c                     	 t          t          d                   5 }| d}|                     d||           d d d            d S # 1 swxY w Y   d S )Nr   rF   z-q)rk   r   )r   r%   rk   s      r   test_quiet_flagzTestCommandLine.test_quiet_flagF  s    8\*<=>> 	>)!%%%FdIf===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s   AAAc                     	 t          t          d                   5 }t          j        d                                          }|                     d||d           d d d            d S # 1 swxY w Y   d S )Nr   $offending line: '\tprint("world")\n'z-vTrk   r   r   rp   textwrapdedentstripr   r   r   rk   s      r   test_verbose_modez!TestCommandLine.test_verbose_modeL  s    J\*<=>> 	G$_: egg  dDFFF		G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G   A A))A-0A-c                     	 t          t          d                   5 }t          j        d                                          }|                     d||d           d d d            d S # 1 swxY w Y   d S )Nr   r   z-vvTr   r   r   s      r   test_double_verbose_modez(TestCommandLine.test_double_verbose_modeT  s    P\*<=>> 	H$_: egg  eT&$GGG		H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hr   N)
r-   r.   r/   r   r   r   r   r   r   r   r0   r   r   r   r     s        5)+B H H H H H"8 8 8) ) )
) ) )> > >G G GH H H H Hr   r   )unittestr   r   r   r   r:   r   r!   r   test.supportr   r   r   r   test.support.os_helperr	   rp   r   r2   r?   rN   r`   r   r   r0   r   r   <module>r      s  
 $ # # # # # # #  				    $ $ $ $ $ $ $ $ $ $ $ $ ) ) ) ) ) )
		%	%	%	!	'K* *Z       &M M M M M( M M M"? ? ? ? ?8 ? ? ?&9 9 9 9 98 9 9 96m= m= m= m= m= m= m= m=`< < < < < < < <<;H ;H ;H ;H ;Hh ;H ;H ;H ;H ;Hr   