python (3.12.0)

(root)/
lib/
python3.12/
test/
__pycache__/
test_tabnanny.cpython-312.pyc

Αe7dZddlmZmZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZm
Z
mZddlmZdddd	d
ddZGd
dZGddeZGddeZGddeZGddeZGddeZGddeZy)zfTesting `tabnanny` module.

Glossary:
    * errored    : Whitespace related problems present in file.
)TestCasemockN)captured_stderrcaptured_stdout
script_helperfindfile)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_expressionwrong_indentednannynag_errored
error_freetab_space_errored_1tab_space_errored_2c$eZdZdZddZdZdZy)TemporaryPyFilez+Create a temporary python source code file.Nc ||_||_yN)source_codedir)selfr	directorys   F/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/test/test_tabnanny.py__init__zTemporaryPyFile.__init__Bs&ctjd|jdd5}|j|jdddj
|_|jS#1swY&xYw)Nwz.pyF)modersuffixdelete)tempfileNamedTemporaryFilerwritername	file_path)rfs  r	__enter__zTemporaryPyFile.__enter__Fs^

(
($((5
	&

GGD$$%	&~~	&	&sA%%A.c.t|jyr)r	r$)rexc_type	exc_value
exc_tracebacks    r__exit__zTemporaryPyFile.__exit__Nst~~r)N)__name__
__module____qualname____doc__rr&r+rrrr?s5rrceZdZdZdZy)TestFormatWitnessesz&Testing `tabnanny.format_witnesses()`.cgd}|D]F\}}|j||5|jtj||dddHy#1swYSxYw)z;Asserting formatter result by giving various input samples.))Testzat tab sizes T, e, s, t)r,zat tab size )tz
at tab size t)z  t  zat tab sizes  ,  , t,  ,  )wordsexpectedN)subTestassertEqualtabnannyformat_witnesses)rtestsr7r8s    rtest_format_witnessesz)TestFormatWitnesses.test_format_witnessesUsj
 %	MOE8EH=
M  !:!:5!A8L
M
M	M
M
Ms&AA	N)r-r.r/r0r>r1rrr3r3Rs0Mrr3ceZdZdZdZy)TestErrPrintzTesting `tabnanny.errprint()`.c	ddgdfdgdfgddfgdfg}|D]\}}|j||5|jt5t5}t	j
|d	d	d	|j
j|d	d	d	d	d	d	y	#1swY<xYw#1swY xYw#1swYxYw)
zBAsserting result of `tabnanny.errprint()` by giving sample inputs.firstsecondz
first second
zfirst
)z1 2 3

)	argumentsr8N)r9assertRaises
SystemExitrr;errprintr:getvalue)rr=argsr8stderrs     r
test_errprintzTestErrPrint.test_errprintfsx
 "23Y	"
	"
J	
$	CND(x@
C&&z2C(*1f ))401$$V__%6BC
C
C	C11CC
C
Cs;B6B*B	#(B*B6B'
#B**B3/B66B?	N)r-r.r/r0rOr1rrr@r@cs(Crr@ceZdZdZy)TestNannyNagcltjdddddddftjdddddddfg}|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
#1swYtxYw#1swYLxYw#1swYxYw)z5Asserting behaviour of `tabnanny.NannyNag` exception.rfoobar)linenomsglinetestmsgtestlinerU)line_numberr8NrV)rVr8rW)rWr8)r;NannyNag
get_linenoget_msgget_liner9r:)rr=nannyr8r[rVrWs       rtest_all_methodszTestNannyNag.test_all_methodsxsW!!!UE2UE:

!!!Y
;Y
C
	
 %	9OE8**,K--/C>>#D'(82D
B  (!3[A
B#@
7  %#6
74(62BC
9  &!148
9
9	9
B
B
7
7
9
9s$	D=D1D*D	D'	*D3	N)r-r.r/rar1rrrQrQws9rrQcTeZdZdZdZddZdZdZdZdZ	dZ
d	Zd
ZdZ
dZy
)	TestCheckzTesting tabnanny.check().cn|jttdtjdt_y)Nverboser)
addCleanupsetattrr;re)rs rsetUpzTestCheck.setUps"9h6F6FGrc*t5}t5}tj|dddddd|j	j||j	j|y#1swYRxYw#1swYVxYw)aRCommon verification for tabnanny.check().

        Use this method to assert expected values of `stdout` and `stderr` after
        running tabnanny.check() on given `dir` or `file` path. Because
        tabnanny.check() captures exceptions and writes to `stdout` and
        `stderr`, asserting standard outputs is the only way.
        N)rrr;checkr:rL)rdir_or_fileouterrstdoutrNs      rverify_tabnanny_checkzTestCheck.verify_tabnanny_checksw
	(&/*;	(vNN;'	(	(*C0*C0	(	(	(	(s!B	A=B	=B	B		Bctttd5}|j|dddy#1swYyxYw)z-A python source code file without any errors.r
NrSOURCE_CODESrorr$s  rtest_correct_filezTestCheck.test_correct_files4
\,7
8	2I&&y1	2	2	2.7c
tj5}|dg}ttd|}ttd|}|5}|5}||fD]}|j	|ddt
_t5}t5}	tj|ddddddj}|D]/}
|j|
5|j|
|ddd1|j	jddddddddddy#1swYxYw#1swYxYw#1swYxYw#1swY>xYw#1swYBxYw#1swYyxYw)	aDirectory containing few error free python source code files.

        Because order of files returned by `os.lsdir()` is not fixed, verify the
        existence of each output lines at `stdout` using `in` operator.
        `verbose` mode of `tabnanny.verbose` asserts `stdout`.
        z: listing directory
r
rz: Clean bill of health.
rDN)rWr,)r TemporaryDirectoryrrrappendr;rerrrjrLr9assertInr:)rtmp_dirlinesfile1file2
file1_path
file2_pathr$rnrNrWs           rtest_correct_directory_verbosez(TestCheck.test_correct_directory_verbosest
(
(
*	8g{"78:E#L$>'RE#L$>'RE
8*e
8z",j!9LILLI=0I!JKL$% $&,&/2C,vNN7+,,*!4D404

dF3444  !2B7
8
8		8	8,,,,44
8
8
8
8		8	8s1E&E	3E<D6	D*D6	%/EE'*EEE&*D3/D6	6D?
;EEEEEE#	E&&E/ctj5}ttd|5|j	|ddddddy#1swYxYw#1swYyxYw)zADirectory which contains few error free python source code files.r
rwN)r rxrrrro)rr{s  rtest_correct_directoryz TestCheck.test_correct_directorys\

(
(
*	4g l!;wO
4**73
4	4	4
4
4	4	4s!AA
A
A	AA"cttd5}d}|d|}|jt5|j	||ddddddy#1swYxYw#1swYyxYw)zBA python source code file eligible for raising `IndentationError`.rIunindent does not match any outer indentation level (<tokenize>, line 3)
: Indentation Error: rmNrrrrIrJrorr$rms   rtest_when_wrong_indentedz"TestCheck.test_when_wrong_indentedsz
\*:;
<	?	*CM!6se<C"":.
?**9#*>
?		?	?
?
?		?	?"A#AA#A 	A##A,cttd5}d}|d|}|jt5|j	||ddddddy#1swYxYw#1swYyxYw)zEA python source code file eligible for raising 'tokenize.TokenError'.r
z(('EOF in multi-line statement', (7, 0))
: Token Error: rNrrs   rtest_when_tokenize_tokenerrorz'TestCheck.test_when_tokenize_tokenerrorsw
\*AB
C	?y=CM6C"":.
?**9#*>
?	?	?
?
?	?	?rcttd5}|d}|dz
}|dz
}dt_|j	||dddy#1swYyxYw)zA python source code file eligible for raising `tabnanny.NannyNag`.

        Tests will assert `stdout` after activating `tabnanny.verbose` mode.
        rz': *** Line 3: trouble in tab city! ***
z#offending line: '\tprint("world")'
z3inconsistent use of tabs and spaces in indentation
rDrlN)rrrr;rerorr$rls   r test_when_nannynag_error_verbosez*TestCheck.test_when_nannynag_error_verbosesg
\*<=
>	;)M!IJC<<CIIC H&&yc&:
	;	;	;s.A

Acttd5}|d}|j||dddy#1swYyxYw)zCA python source code file eligible for raising `tabnanny.NannyNag`.rz 3 '\tprint("world")'
rNrqrs   rtest_when_nannynag_errorz"TestCheck.test_when_nannynag_errorsG
\*<=
>	;)K9:C&&yc&:	;	;	;s5>cd}|dtjdtjtjd|d}|j	t
5|j
||dddy#1swYyxYw)z6A python file which does not exist actually in system.z
no_file.pyz: I/O Error: [Errno z] z: rGrN)errnoENOENTosstrerrorrIrJro)rpathrms   rtest_when_no_filezTestCheck.test_when_no_filesq-ell^2U\\*+2dXR9


z
*	6&&t&5	6	6	6sA22A;c	tj5}ttd|}ttd|}|5}|5}d}|d|}|j	t
5|j
||ddddddddddddy#1swY"xYw#1swY&xYw#1swY*xYw#1swYyxYw)z?Directory containing wrongly indented python source code files.rrwr
rrrN)r rxrrrrIrJro)rr{
error_file	code_filee_filec_filerms       rtest_errored_directoryz TestCheck.test_errored_directorys

(
(
*	Ag(-.'J(\*gI
Avy
AF6
"7u=&&z2A..wC.@A	
A
A	A	AAA	
A
A
A
A	A	AsS+B;B/B#"B	6B#>B/B;B 
B##B,(B//B8	4B;;CN)r,r,)r-r.r/r0rhrortrrrrrrrrr1rrrcrcs=#12
804??;;6ArrccFeZdZdZej
ddZdZy)TestProcessTokensz$Testing `tabnanny.process_tokens()`.ztabnanny.NannyNagc,ttd5}t|5}tjtj|jddd|j|jdddy#1swY-xYw#1swYyxYw)z=A python source code without any whitespace related problems.r
N)
rrropenr;process_tokenstokenizegenerate_tokensreadlineassertFalsecalled)rMockNannyNagr$r%s    rtest_with_correct_codez(TestProcessTokens.test_with_correct_code	s\,7
8	2Ii
NA''(@(@(LM
N\001	2	2
N
N	2	2s"B
3A>#B
>B	B

Bc
dD]}|j|5tt|5}t|5}t	j
|j}|jtj5tj|ddddddddddddy#1swY$xYw#1swY(xYw#1swY,xYw#1swYxYw)z>A python source code with whitespace related sampled problems.)rr)keyN)r9rrrrrrrrIr;r\r)rrr$r%tokenss     rtest_with_errored_codes_samplesz1TestProcessTokens.test_with_errored_codes_samplessB	<C#&
<$\#%67<9i<A!)!9!9!**!E!..x/@/@A<$33F;<<<
<
<	<
<<<<<<
<
<sQCC?B;	6B/B;	CC/B84B;	;C
CCCC	N)r-r.r/r0rpatchrrr1rrrrs(.TZZ#$2%2<rrcFeZdZdZddddddZdZdZdZd	Zd
Z	dZ
y)
TestCommandLinez+Tests command line interface of `tabnanny`.r,F)rnrNpartialexpect_failurecf|rtjddg|\}}}ntjddg|\}}}tj|}tj|}|rd||f||ffD]X\}	}
|
j}|	jD]0}|j
||5|j||ddd2Zy|j|j|j|j|j|jy#1swYxYw)zBCommon function to assert the behaviour of command line interface.z-mr;)stdoutputN)	rassert_python_failureassert_python_okrfsdecode
splitlinesr9rzassertListEqual)
rrnrNrrrM_rlrmrr_output_stds
             rvalidate_cmdzTestCommandLine.validate_cmd's'==dJVQUVKAsC'88zQDQKAsCkk#kk#!'
}=
5V ++-NN,5D$w?5

dG4555
5
  !163D3D3FG  !163D3D3FG	55s*D''D0cttd5}|d}|dz
}|j||ddddy#1swYyxYw)z8Should displays error when errored python file is given.rrzFunindent does not match any outer indentation level (<string>, line 3)TrNrNrrrr)rr$rNs   rtest_with_errored_filez&TestCommandLine.test_with_errored_file;s[
\*:;
<	M	"
_5F-
.FitL		M	M	Ms	;Actttd5}|j|dddy#1swYyxYw)zAShould not display anything if python file is correctly indented.r
Nrrss  rtest_with_error_free_filez)TestCommandLine.test_with_error_free_fileCs4
\,7
8	)Ii(	)	)	)rucLtd}d|d}|j|dy)z%Should display usage on no arguments.ztabnanny.pyzUsage: z [-v] file_or_directory ...TrN)rr)rrrNs   rtest_command_usagez"TestCommandLine.test_command_usageHs.
&4& ;<=rcttd5}|d}|jd||dddy#1swYyxYw)z*Should display less when quite mode is on.rrGz-q)rnNr)rr$rns   rtest_quiet_flagzTestCommandLine.test_quiet_flagNsH
\*<=
>	>)!{"%FdIf=	>	>	>s6?cttd5}tjdj	}|jd||ddddy#1swYyxYw)z<Should display more error information if verbose mode is on.r"offending line: '\tprint("world")'z-vTrnrNrrrtextwrapdedentstriprrrrns   rtest_verbose_modez!TestCommandLine.test_verbose_modeTs_
\*<=
>	G$__7eg

dDF		G	G	G9AActtd5}tjdj	}|jd||ddddy#1swYyxYw)zBShould display detailed error information if double verbose is on.rrz-vvTrNrrs   rtest_double_verbose_modez(TestCommandLine.test_double_verbose_mode\s_
\*<=
>	H$__7eg

eT&$G		H	H	HrN)r-r.r/r0rrrrrrrr1rrrr$s65)+BV[H(M)
>>GHrr)r0unittestrrrrr;rr rtest.supportrrrrtest.support.os_helperr	rrrr3r@rQrcrrr1rr<module>rs
$	$$)
		%	%	%	!	'K*Z&M(M"C8C(9896qAqAh<<<>Hh>Hr