Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_tabnanny.cpython-310.opt-2.pyc

o

0�i�5�@s�	ddlmZmZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZm
Z
ddlmZddddd	d
d�ZGdd
�d
�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)�)�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(eZdZ	d	dd�Zdd�Zdd�ZdS)
�TemporaryPyFile�NcCs||_||_dS�N)�source_code�dir)�selfr�	directory�r�9/opt/alt/python310/lib64/python3.10/test/test_tabnanny.py�__init__Bs
zTemporaryPyFile.__init__cCsNtjd|jddd��}|�|j�Wd�n1swY|j|_|jS)N�wz.pyF)�moder�suffix�delete)�tempfileZNamedTemporaryFiler�writer�name�	file_path)r�frrr�	__enter__Fs
��zTemporaryPyFile.__enter__cCst|j�dSr)rr )r�exc_type�	exc_value�
exc_tracebackrrr�__exit__NszTemporaryPyFile.__exit__)rN)�__name__�
__module__�__qualname__rr"r&rrrrr?s

rc@�eZdZ	dd�ZdS)�TestFormatWitnessesc	Cs\	gd�}|D]$\}}|j||d��|�t�|�|�Wd�n1s&wYqdS)N))ZTestzat tab sizes T, e, s, t)rzat tab size )�tz
at tab size t)z  t  zat tab sizes  ,  , t,  ,  )�words�expected)�subTest�assertEqual�tabnannyZformat_witnesses)r�testsr-r.rrr�test_format_witnessesUs���z)TestFormatWitnesses.test_format_witnessesN)r'r(r)r3rrrrr+R�r+c@r*)�TestErrPrintc
Cs�	ddgdfdgdfgd�dfgdfg}|D];\}}|j||d��(t��
}tj|�Wd�n1s5wY|�|��|�Wd�n1sLwYqdS)	N�first�secondz
first second
zfirst
)���z1 2 3
�
)Z	argumentsr.)r/rr1Zerrprintr0�getvalue)rr2�argsr.�stderrrrr�
test_errprintfs

�����zTestErrPrint.test_errprintN)r'r(r)r?rrrrr5cr4r5c@seZdZdd�ZdS)�TestNannyNagc	Cs&	t�ddd�dddd�ft�ddd�dddd�fg}|D]s\}}|��}|��}|��}|j||dd	��|�|d|�Wd�n1sIwY|j||d
d��|�|d
|�Wd�n1sjwY|j||dd
��|�|d|�Wd�n1s�wYqdS)NrZfooZbar)�lineno�msg�line�ZtestmsgZtestlinerA)�line_numberr.rB)rBr.rC)rCr.)r1�NannyNagZ
get_linenoZget_msgZget_liner/r0)rr2Znannyr.rErBrCrrr�test_all_methodsws2
�
��
������zTestNannyNag.test_all_methodsN)r'r(r)rGrrrrr@vsr@c@sheZdZ	dd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�	TestCheckcCs|�ttdtj�dt_dS)N�verboser)Z
addCleanup�setattrr1rI)rrrr�setUp�s
zTestCheck.setUprc	Cs|	t�� }t��
}t�|�Wd�n1swYWd�n1s'wY|�|��|�|�|��|�dSr)rrr1�checkr0r<)rZdir_or_file�out�err�stdoutr>rrr�verify_tabnanny_check�s��zTestCheck.verify_tabnanny_checkcC�>	ttd��}|�|�Wd�dS1swYdS�Nr�r�SOURCE_CODESrP�rr rrr�test_correct_file��"�zTestCheck.test_correct_filecCs�	t����}|�d�g}ttd|d�}ttd|d�}|��}|�r}||fD]
}|�|�d��q&dt_t�� }t��
}	t�	|�Wd�n1sKwYWd�n1sZwY|�
�}|D]}
|j|
d��|�|
|�Wd�n1s~wYqe|�
|	�
�d�Wd�n1s�wYWd�n1s�wYWd�dSWd�dS1s�wYdS)Nz: listing directory
r�rz: Clean bill of health.
r8)rCr)r�TemporaryDirectoryrrT�appendr1rIrrrLr<r/�assertInr0)r�tmp_dir�linesZfile1Zfile2Z
file1_pathZ
file2_pathr rOr>rCrrr�test_correct_directory_verbose�s6
�������"�z(TestCheck.test_correct_directory_verbosec	Csz	t���.}ttd|d��
|�|�Wd�n1swYWd�dSWd�dS1s6wYdS)NrrX�rrYrrTrP)rr\rrr�test_correct_directory�s
��"�z TestCheck.test_correct_directorycC�T	ttd��}d}|�d|��}|j||d�Wd�dS1s#wYdS)Nr
�Iunindent does not match any outer indentation level (<tokenize>, line 3)
�: Indentation Error: �rNrS�rr rNrrr�test_when_wrong_indented�s"�z"TestCheck.test_when_wrong_indentedcCra)Nr	z(('EOF in multi-line statement', (7, 0))
z: Token Error: rdrSrerrr�test_when_tokenize_tokenerror�s"�z'TestCheck.test_when_tokenize_tokenerrorcCsb	ttd�� }|�d�}|d7}|d7}dt_|j||d�Wd�dS1s*wYdS)Nrz': *** Line 3: trouble in tab city! ***
z%offending line: '\tprint("world")\n'
z$indent not equal e.g. at tab size 1
r8�rM)rrTr1rIrP�rr rMrrr� test_when_nannynag_error_verbose�s
"�z*TestCheck.test_when_nannynag_error_verbosecCsL	ttd��}|�d�}|j||d�Wd�dS1swYdS)Nrz 3 '\tprint("world")\n'
rhrSrirrr�test_when_nannynag_error�s

"�z"TestCheck.test_when_nannynag_errorcCs>	d}|�dtj�dt�tj��d|�d�}|j||d�dS)Nz
no_file.pyz: I/O Error: [Errno z] z: r;rd)�errnoZENOENT�os�strerrorrP)r�pathrNrrr�test_when_no_file�s
��zTestCheck.test_when_no_filec
Cs�	t���U}ttd|d�}ttd|d�}|�*}|�}d}|�d|��}|j||d�Wd�n1s6wYWd�n1sEwYWd�dSWd�dS1s]wYdS)Nr
rXrrbrcrdr_)rr\Z
error_fileZ	code_fileZe_fileZc_filerNrrr�test_errored_directory�s$
�����"�z TestCheck.test_errored_directoryN)rr)r'r(r)rKrPrVr^r`rfrgrjrkrprqrrrrrH�s


rHc@s(eZdZ	e�d�dd��Zdd�ZdS)�TestProcessTokensztabnanny.NannyNagc	Csz	ttd��,}t|��}t�t�|j��Wd�n1s wY|�|j	�Wd�dS1s6wYdSrR)
rrT�openr1�process_tokens�tokenize�generate_tokens�readlineZassertFalseZcalled)rZMockNannyNagr r!rrr�test_with_correct_codes
�"�z(TestProcessTokens.test_with_correct_codecCs�	dD]c}|j|d��Stt|��=}t|��)}t�|j�}|�tj	��
t�
|�Wd�n1s4wYWd�n1sCwYWd�n1sRwYWd�n1sawYqdS)N)r
r)�key)r/rrTrsrurvrwZassertRaisesr1rFrt)rryr r!�tokensrrr�test_with_errored_codes_samples
s"
���������z1TestProcessTokens.test_with_errored_codes_samplesN)r'r(r)rZpatchrxr{rrrrrrs

rrc@sPeZdZ	dddd�dd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Z	dS)�TestCommandLinerF)rOr>�partialc
Gs�	tjddg|�R�\}}}t�|�}t�|�}|rQ||f||ffD],\}}	|	��}
|��D]}|j||
d��|�||
�Wd�n1sHwYq.q"dS|�|��|���|�|��|���dS)Nz-mr1)�std�output)rZassert_python_okrm�fsdecode�
splitlinesr/r[ZassertListEqual)rrOr>r}r=�_rMrNr~rZ_outputZ_stdrrr�validate_cmd"s 

����zTestCommandLine.validate_cmdcCsT	ttd��}|�d�}|d7}|j||d�Wd�dS1s#wYdS)Nr
rczHunindent does not match any outer indentation level (<tokenize>, line 3)�r>�rrTr�)rr r>rrr�test_with_errored_file3s
"�z&TestCommandLine.test_with_errored_filecCrQrRr�rUrrr�test_with_error_free_file;rWz)TestCommandLine.test_with_error_free_filecCs&	td�}d|�d�}|j|d�dS)Nztabnanny.pyzUsage: z [-v] file_or_directory ...r�)rr�)rror>rrr�test_command_usage@sz"TestCommandLine.test_command_usagecCsN	ttd��}|�d�}|jd||d�Wd�dS1s wYdS)Nrr;z-q)rOr�)rr rOrrr�test_quiet_flagFs

"�zTestCommandLine.test_quiet_flagcC�T	ttd��}t�d���}|jd||dd�Wd�dS1s#wYdS)Nr�$offending line: '\tprint("world")\n'z-vT�rOr}�rrT�textwrap�dedent�stripr��rrorOrrr�test_verbose_modeL���"�z!TestCommandLine.test_verbose_modecCr�)Nrr�z-vvTr�r�r�rrr�test_double_verbose_modeTr�z(TestCommandLine.test_double_verbose_modeN)
r'r(r)r�r�r�r�r�r�r�rrrrr|sr|)Zunittestrrrlrmr1rurr�Ztest.supportrrrrZtest.support.os_helperrrTrr+r5r@rHrrr|rrrr�<module>s0�-p