HEX
Server: Apache
System: Linux bd12.noc223.com 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User: handcraf (1693)
PHP: 8.1.28
Disabled: NONE
Upload Files
File: //opt/alt/python312/lib64/python3.12/test/__pycache__/test_tabnanny.cpython-312.pyc
�

�h�e�7���dZddlmZmZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZm
Z
mZddlmZdddd	d
dd�ZGd
�d�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�ZGd�de�Zy)zfTesting `tabnanny` module.

Glossary:
    * errored    : Whitespace related problems present in file.
�)�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�$�eZdZdZdd�Zd�Zd�Zy)�TemporaryPyFilez+Create a temporary python source code file.Nc� �||_||_y�N)�source_code�dir)�selfr�	directorys   �9/opt/alt/python312/lib64/python3.12/test/test_tabnanny.py�__init__zTemporaryPyFile.__init__Bs��&������c���tjd|jdd��5}|j|j�ddd�j
|_|jS#1swY�&xYw)N�wz.pyF)�moder�suffix�delete)�tempfile�NamedTemporaryFiler�writer�name�	file_path)r�fs  r�	__enter__zTemporaryPyFile.__enter__Fs^��
�
(�
(��$�(�(�5��
�	&�
�
�G�G�D�$�$�%�	&�������~�~��	&�	&�s�A%�%A.c�.�t|j�yr)r	r$)r�exc_type�	exc_value�
exc_tracebacks    r�__exit__zTemporaryPyFile.__exit__Ns���t�~�~�r)�N)�__name__�
__module__�__qualname__�__doc__rr&r+�rrrr?s��5���rrc��eZdZdZd�Zy)�TestFormatWitnessesz&Testing `tabnanny.format_witnesses()`.c��gd�}|D]F\}}|j||��5|jtj|�|�ddd��Hy#1swY�SxYw)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,  ,  )�words�expectedN)�subTest�assertEqual�tabnanny�format_witnesses)r�testsr7r8s    r�test_format_witnessesz)TestFormatWitnesses.test_format_witnessesUsj��
�� %�	M�O�E�8����E�H��=�
M�� � ��!:�!:�5�!A�8�L�
M�
M�	M�
M�
M�s�&A�A	N)r-r.r/r0r>r1rrr3r3Rs��0�Mrr3c��eZdZdZd�Zy)�TestErrPrintzTesting `tabnanny.errprint()`.c	��ddgdfdgdfgd�dfgdfg}|D]�\}}|j||��5|jt�5t�5}t	j
|�d	d	d	�|j
j�|�d	d	d	�d	d	d	���y	#1swY�<xYw#1swY� xYw#1swY��xYw)
zBAsserting result of `tabnanny.errprint()` by giving sample inputs.�first�secondz
first second
zfirst
)���z1 2 3
�
)�	argumentsr8N)r9�assertRaises�
SystemExitrr;�errprintr:�getvalue)rr=�argsr8�stderrs     r�
test_errprintzTestErrPrint.test_errprintfs����x�
 �"2�3��Y�	�"�
�	�"�
��J�	
��$�	C�N�D�(�����x��@�
C��&�&�z�2�C�(�*�1�f� �)�)�4�0�1��$�$�V�_�_�%6��B�C�
C�
C�	C�1�1��C�C��
C�
C�s;�B6�B*�B	�#(B*�B6�B'
�#B*�*B3�/B6�6B?	N)r-r.r/r0rOr1rrr@r@cs��(�Crr@c��eZdZd�Zy)�TestNannyNagc�l�tjddd�dddd�ftjddd�dddd�fg}|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
#1swY�txYw#1swY�LxYw#1swY��xYw)z5Asserting behaviour of `tabnanny.NannyNag` exception.r�foo�bar)�lineno�msg�line��testmsg�testlinerU)�line_numberr8NrV)rVr8rW)rWr8)r;�NannyNag�
get_lineno�get_msg�get_liner9r:)rr=�nannyr8r[rVrWs       r�test_all_methodszTestNannyNag.test_all_methodsxsW���!�!�!�U�E�2��U�E�:�
�
�!�!�!�Y�
�;��Y�
�C�
�	
�� %�	9�O�E�8��*�*�,�K��-�-�/�C��>�>�#�D����'�(�8�2D���
B�� � ��(�!3�[�A�
B����#�����@�
7�� � ��%��#�6�
7����4�(�6�2B��C�
9�� � ��&�!1�4�8�
9�
9�	9�
B�
B��
7�
7��
9�
9�s$�	D�=D�1D*�D	�D'	�*D3	N)r-r.r/rar1rrrQrQws��9rrQc�T�eZdZdZd�Zdd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy
)�	TestCheckzTesting tabnanny.check().c�n�|jttdtj�dt_y)N�verboser)�
addCleanup�setattrr;re)rs r�setUpzTestCheck.setUp�s"�������9�h�6F�6F�G���rc�*�t�5}t�5}tj|�ddd�ddd�|j	j�|�|j	j�|�y#1swY�RxYw#1swY�VxYw)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)r�dir_or_file�out�err�stdoutrNs      r�verify_tabnanny_checkzTestCheck.verify_tabnanny_check�sw���
�	(�&�/�*;�	(�v��N�N�;�'�	(�	(�������*�C�0�������*�C�0�	(�	(��	(�	(�s!�B	�A=�B	�=B	�B	�	Bc�t�ttd�5}|j|�ddd�y#1swYyxYw)z-A python source code file without any errors.r
N�r�SOURCE_CODESro�rr$s  r�test_correct_filezTestCheck.test_correct_file�s4��
�\�,�7�
8�	2�I��&�&�y�1�	2�	2�	2���.�7c
���tj�5}|�d�g}ttd|��}ttd|��}|5}|5}||fD]}|j	|�d���dt
_t�5}t�5}	tj|�ddd�ddd�j�}|D]/}
|j|
��5|j|
|�ddd��1|j	j�d�ddd�ddd�ddd�y#1swY��xYw#1swY��xYw#1swY��xYw#1swY�>xYw#1swY�BxYw#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 �TemporaryDirectoryrrr�appendr;rerrrjrLr9�assertInr:)r�tmp_dir�lines�file1�file2�
file1_path�
file2_pathr$rnrNrWs           r�test_correct_directory_verbosez(TestCheck.test_correct_directory_verbose�st���
(�
(�
*�	8�g��{�"7�8�:�E�#�L��$>�'�R�E�#�L��$>�'�R�E��
8�*�e�
8�z�",�j�!9�L�I��L�L�I�=�0I�!J�K�L�$%�� �$�&�,�&�/�2C�,�v��N�N�7�+�,�,����*��!�4�D����4��0�4��
�
�d�F�3�4�4�4�� � ����!2�B�7�
8�
8�		8�	8�,�,��,�,��4�4��
8�
8��
8�
8��		8�	8�s��1E&�E�	3E�<D6	�D*�D6	�%/E�E�'*E�E�E&�*D3�/D6	�6D?
�;E�E�E�E�E�E#	�E&�&E/c���tj�5}ttd|��5|j	|�ddd�ddd�y#1swY�xYw#1swYyxYw)zADirectory which contains few error free python source code files.r
rwN)r rxrrrro)rr{s  r�test_correct_directoryz TestCheck.test_correct_directory�s\��
�
(�
(�
*�	4�g� ��l�!;�w�O�
4��*�*�7�3�
4�	4�	4�
4�
4��	4�	4�s!�A�A
�A�
A	�A�A"c���ttd�5}d}|�d|��}|jt�5|j	||��ddd�ddd�y#1swY�xYw#1swYyxYw)zBA python source code file eligible for raising `IndentationError`.r�Iunindent does not match any outer indentation level (<tokenize>, line 3)
�: Indentation Error: �rmN�rrrrIrJro�rr$rms   r�test_when_wrong_indentedz"TestCheck.test_when_wrong_indented�sz��
�\�*:�;�
<�	?�	�*�C��M�!6�s�e�<�C��"�"�:�.�
?��*�*�9�#�*�>�
?�		?�	?�
?�
?��		?�	?��"�A#�A�A#�A 	�A#�#A,c���ttd�5}d}|�d|��}|jt�5|j	||��ddd�ddd�y#1swY�xYw#1swYyxYw)zEA python source code file eligible for raising 'tokenize.TokenError'.r
z(('EOF in multi-line statement', (7, 0))
�: Token Error: r�Nr�r�s   r�test_when_tokenize_tokenerrorz'TestCheck.test_when_tokenize_tokenerror�sw��
�\�*A�B�
C�	?�y�=�C��M����6�C��"�"�:�.�
?��*�*�9�#�*�>�
?�	?�	?�
?�
?��	?�	?�r�c��ttd�5}|�d�}|dz
}|dz
}dt_|j	||��ddd�y#1swYyxYw)z�A 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
rD�rlN)rrrr;rero�rr$rls   r� test_when_nannynag_error_verbosez*TestCheck.test_when_nannynag_error_verbose�sg��
�\�*<�=�
>�	;�)��M�!I�J�C��<�<�C��I�I�C� �H���&�&�y�c�&�:�
	;�	;�	;�s�.A
�
Ac��ttd�5}|�d�}|j||��ddd�y#1swYyxYw)zCA python source code file eligible for raising `tabnanny.NannyNag`.rz 3 '\tprint("world")'
r�Nrqr�s   r�test_when_nannynag_errorz"TestCheck.test_when_nannynag_error�sG��
�\�*<�=�
>�	;�)��K�9�:�C��&�&�y�c�&�:�	;�	;�	;�s�5�>c��d}|�dtj�dtjtj��d|�d�}|j	t
�5|j
||��ddd�y#1swYyxYw)z6A python file which does not exist actually in system.z
no_file.pyz: I/O Error: [Errno z] z: rGr�N)�errno�ENOENT�os�strerrorrIrJro)r�pathrms   r�test_when_no_filezTestCheck.test_when_no_file�sq������-�e�l�l�^�2����U�\�\�*�+�2�d�X�R�9��
�
�
�z�
*�	6��&�&�t��&�5�	6�	6�	6�s�A2�2A;c	��tj�5}ttd|��}ttd|��}|5}|5}d}|�d|��}|j	t
�5|j
||��ddd�ddd�ddd�ddd�y#1swY�"xYw#1swY�&xYw#1swY�*xYw#1swYyxYw)z?Directory containing wrongly indented python source code files.rrwr
r�r�r�N)r rxrrrrIrJro)rr{�
error_file�	code_file�e_file�c_filerms       r�test_errored_directoryz TestCheck.test_errored_directory�s���
�
(�
(�
*�	A�g�(��-�.�'��J�(��\�*�g��I��
A�v�y�
A�F�6���
�"7��u�=���&�&�z�2�A��.�.�w�C�.�@�A�	
A�
A�	A�	A�A�A��	
A�
A��
A�
A��	A�	A�sS�+B;�B/�B#�"B	�6B#�>B/�B;�B 
�B#�#B,�(B/�/B8	�4B;�;CN)r,r,)r-r.r/r0rhrortr�r�r�r�r�r�r�r�r1rrrcrc�s=��#��1�2�
8�04�?�?�;�;�6�Arrcc�F�eZdZdZej
d�d��Zd�Zy)�TestProcessTokensz$Testing `tabnanny.process_tokens()`.ztabnanny.NannyNagc�,�ttd�5}t|�5}tjtj|j��ddd�|j|j�ddd�y#1swY�-xYw#1swYyxYw)z=A python source code without any whitespace related problems.r
N)
rrr�openr;�process_tokens�tokenize�generate_tokens�readline�assertFalse�called)r�MockNannyNagr$r%s    r�test_with_correct_codez(TestProcessTokens.test_with_correct_code	s����\�,�7�
8�	2�I��i��
N�A��'�'��(@�(@����(L�M�
N����\�0�0�1�	2�	2�
N�
N��	2�	2�s"�B
�3A>�#B
�>B	�B
�
Bc
��dD]�}|j|��5tt|�5}t|�5}t	j
|j�}|jtj�5tj|�ddd�ddd�ddd�ddd���y#1swY�$xYw#1swY�(xYw#1swY�,xYw#1swY��xYw)z>A python source code with whitespace related sampled problems.)rr)�keyN)r9rrrr�r�r�r�rIr;r\r�)rr�r$r%�tokenss     r�test_with_errored_codes_samplesz1TestProcessTokens.test_with_errored_codes_sampless���B�	<�C����#��&�
<�$�\�#�%6�7�<�9��i��<�A�!)�!9�!9�!�*�*�!E��!�.�.�x�/@�/@�A�<�$�3�3�F�;�<�<�<�
<�
<�	<�
<�<��<�<��<�<��
<�
<�sQ�C�C�?B;	�6B/�B;	�C�C�/B8�4B;	�;C
�C�C�C�C	N)r-r.r/r0r�patchr�r�r1rrr�r�s(��.��T�Z�Z�#�$�2�%�2�<rr�c�F�eZdZdZddddd�d�Zd�Zd�Zd�Zd	�Zd
�Z	d�Z
y)
�TestCommandLinez+Tests command line interface of `tabnanny`.r,F)rnrN�partial�expect_failurec�f�|rtjddg|���\}}}ntjddg|���\}}}tj|�}tj|�}|rd||f||ffD]X\}	}
|
j�}|	j�D]0}|j
||��5|j||�ddd��2�Zy|j|j�|j��|j|j�|j��y#1swY��xYw)zBCommon function to assert the behaviour of command line interface.z-mr;)�std�outputN)	r�assert_python_failure�assert_python_okr��fsdecode�
splitlinesr9rz�assertListEqual)
rrnrNr�r�rM�_rlrmr�r��_output�_stds
             r�validate_cmdzTestCommandLine.validate_cmd's���'�=�=�d�J�V�QU�V�K�A�s�C�'�8�8��z�Q�D�Q�K�A�s�C��k�k�#����k�k�#����!'��
���}�=�
5���V� �+�+�-���N�N�,�5�D����$�w��?�5��
�
�d�G�4�5�5�5�
5�
� � ����!1�6�3D�3D�3F�G�� � ����!1�6�3D�3D�3F�G�	5�5�s�*D'�'D0c��ttd�5}|�d�}|dz
}|j||d��ddd�y#1swYyxYw)z8Should displays error when errored python file is given.rr�zFunindent does not match any outer indentation level (<string>, line 3)T�rNr�N�rrrr�)rr$rNs   r�test_with_errored_filez&TestCommandLine.test_with_errored_file;s[��
�\�*:�;�
<�	M�	�"�
�_�5�F��-�
.�F����i��t��L�		M�	M�	M�s	�;�Ac�t�ttd�5}|j|�ddd�y#1swYyxYw)zAShould not display anything if python file is correctly indented.r
Nr�rss  r�test_with_error_free_filez)TestCommandLine.test_with_error_free_fileCs4��
�\�,�7�
8�	)�I����i�(�	)�	)�	)�ruc�L�td�}d|�d�}|j|d��y)z%Should display usage on no arguments.ztabnanny.pyzUsage: z [-v] file_or_directory ...Tr�N)rr�)rr�rNs   r�test_command_usagez"TestCommandLine.test_command_usageHs.���
�&���4�&� ;�<��������=rc��ttd�5}|�d�}|jd||��ddd�y#1swYyxYw)z*Should display less when quite mode is on.rrGz-q)rnNr�)rr$rns   r�test_quiet_flagzTestCommandLine.test_quiet_flagNsH��
�\�*<�=�
>�	>�)�!�{�"�%�F����d�I�f��=�	>�	>�	>�s�6�?c���ttd�5}tjd�j	�}|jd||d��ddd�y#1swYyxYw)z<Should display more error information if verbose mode is on.r�"offending line: '\tprint("world")'z-vT�rnr�N�rrr�textwrap�dedent�stripr��rr�rns   r�test_verbose_modez!TestCommandLine.test_verbose_modeTs_��
�\�*<�=�
>�	G�$��_�_�7���e�g�
�
���d�D����F�		G�	G�	G���9A�Ac���ttd�5}tjd�j	�}|jd||d��ddd�y#1swYyxYw)zBShould display detailed error information if double verbose is on.rr�z-vvTr�Nr�r�s   r�test_double_verbose_modez(TestCommandLine.test_double_verbose_mode\s_��
�\�*<�=�
>�	H�$��_�_�7���e�g�
�
���e�T�&�$��G�		H�	H�	H�r�N)r-r.r/r0r�r�r�r�r�r�r�r1rrr�r�$s6��5�)+�B��V[�H�(M�)�
>�>�G�Hrr�)r0�unittestrrr�r�r;r�r r��test.supportrrrr�test.support.os_helperr	rrrr3r@rQrcr�r�r1rr�<module>r�s����
$��	�����$�$�)�
	�	%�	%�	%�	!�	'�K*��Z��&M�(�M�"C�8�C�(9�8�9�6qA��qA�h<��<�<>H�h�>Hr