Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_tabnanny.cpython-311.pyc
�

�Ke�5��B�dZddlmZmZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZm
Z
mZddlmZdddd	d
dd�ZGd
�d��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZdS)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�ZdS)�TemporaryPyFilez+Create a temporary python source code file.�Nc�"�||_||_dS�N)�source_code�dir)�selfr�	directorys   �</usr/local/apps/python3/lib/python3.11/test/test_tabnanny.py�__init__zTemporaryPyFile.__init__Bs��&��������c���tjd|jdd���5}|�|j��ddd��n#1swxYwY|j|_|jS)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	�A	c�.�t|j��dSr)r	r%)r�exc_type�	exc_value�
exc_tracebacks    r�__exit__zTemporaryPyFile.__exit__Ns���t�~�����r)rN)�__name__�
__module__�__qualname__�__doc__rr'r,�rrrr?sL������5�5������������rrc��eZdZdZd�ZdS)�TestFormatWitnessesz&Testing `tabnanny.format_witnesses()`.c���gd�}|D]\\}}|�||���5|�tj|��|��ddd��n#1swxYwY�]dS)z;Asserting formatter result by giving various input samples.))�Testzat tab sizes T, e, s, t)rz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_witnessesUs���
�
�
�� %�	M�	M�O�E�8����E�H��=�=�
M�
M�� � ��!:�5�!A�!A�8�L�L�L�
M�
M�
M�
M�
M�
M�
M�
M�
M�
M�
M����
M�
M�
M�
M��	M�	Ms�)A�A	�A	N)r-r.r/r0r>r1rrr3r3Rs.������0�0�M�M�M�M�Mrr3c��eZdZdZd�ZdS)�TestErrPrintzTesting `tabnanny.errprint()`.c�R�ddgdfdgdfgd�dfgdfg}|D]�\}}|�||���5t��5}tj|�d	d	d	��n#1swxYwY|�|���|��d	d	d	��n#1swxYwY��d	S)
zBAsserting result of `tabnanny.errprint()` by giving sample inputs.�first�secondz
first second
zfirst
)���z1 2 3
�
)�	argumentsr8N)r9rr;�errprintr:�getvalue)rr=�argsr8�stderrs     r�
test_errprintzTestErrPrint.test_errprintfsM���x�
 �"2�3��Y�	�"�
�Y�Y�	�"�
��J�	
��$�	?�	?�N�D�(�����x��@�@�
?�
?�$�&�&�-�&��%�t�,�,�-�-�-�-�-�-�-�-�-�-�-����-�-�-�-�� � ����!2�!2�X�>�>�>�
?�
?�
?�
?�
?�
?�
?�
?�
?�
?�
?����
?�
?�
?�
?��	?�	?s5�B�A�B�A � B�#A �$+B�B	�"B	N)r-r.r/r0rMr1rrr@r@cs)������(�(�
?�
?�
?�
?�
?rr@c��eZdZd�ZdS)�TestNannyNagc���tjddd��dddd�ftjddd��dddd�fg}|D�]5\}}|���}|���}|���}|�||d�	��5|�|d|��d
d
d
��n#1swxYwY|�||d���5|�|d|��d
d
d
��n#1swxYwY|�||d
���5|�|d
|��d
d
d
��n#1swxYwY��7d
S)z5Asserting behaviour of `tabnanny.NannyNag` exception.r�foo�bar)�lineno�msg�line��testmsg�testlinerS)�line_numberr8NrT)rTr8rU)rUr8)r;�NannyNag�
get_lineno�get_msg�get_liner9r:)rr=�nannyr8rYrTrUs       r�test_all_methodszTestNannyNag.test_all_methodsws^���!�!�U�E�2�2��U�E�:�:�
�
�!�!�Y�
�;�;��Y�
�C�C�
�	
�� %�	9�	9�O�E�8��*�*�,�,�K��-�-�/�/�C��>�>�#�#�D����'�(�8�2D����
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�(�6�2B��C�C�
9�
9�� � ��&�!1�4�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_r1rrrOrOvs#������9�9�9�9�9rrOc�V�eZdZdZd�Zdd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�ZdS)�	TestCheckzTesting tabnanny.check().c�v�|�ttdtj��dt_dS)N�verboser)�
addCleanup�setattrr;rc)rs r�setUpzTestCheck.setUp�s+�������9�h�6F�G�G�G�����rrc�f�t��5}t��5}tj|��ddd��n#1swxYwYddd��n#1swxYwY|�|���|��|�|���|��dS)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:rJ)r�dir_or_file�out�err�stdoutrLs      r�verify_tabnanny_checkzTestCheck.verify_tabnanny_check�s���
�
�	(�&�/�*;�*;�	(�v��N�;�'�'�'�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(����	(�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(����	(�	(�	(�	(�������*�*�C�0�0�0�������*�*�C�0�0�0�0�0s1�A�?�A�A	�A�A	�A�A�Ac��ttd��5}|�|��ddd��dS#1swxYwYdS)z-A python source code file without any errors.r
N�r�SOURCE_CODESrm�rr%s  r�test_correct_filezTestCheck.test_correct_file�s���
�\�,�7�
8�
8�	2�I��&�&�y�1�1�1�	2�	2�	2�	2�	2�	2�	2�	2�	2�	2�	2�	2����	2�	2�	2�	2�	2�	2��>�A�Ac
�b�tj��5}|�d�g}ttd|���}ttd|���}|5}|5}||fD]}|�|�d����dt
_t��5}t��5}	tj	|��ddd��n#1swxYwYddd��n#1swxYwY|�
��}|D]F}
|�|
���5|�|
|��ddd��n#1swxYwY�G|�
|	�
��d��ddd��n#1swxYwYddd��n#1swxYwYddd��dS#1swxYwYdS)	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)rUr)r!�TemporaryDirectoryrrp�appendr;rcrrrhrJr9�assertInr:)r�tmp_dir�lines�file1�file2�
file1_path�
file2_pathr%rlrLrUs           r�test_correct_directory_verbosez(TestCheck.test_correct_directory_verbose�s%���
(�
*�
*�	8�g��8�8�8�:�E�#�L��$>�'�R�R�R�E�#�L��$>�'�R�R�R�E��
8�*�e�
8�z�",�j�!9�L�L�I��L�L�I�!J�!J�!J�K�K�K�K�#$�� �$�&�&�,�&�/�2C�2C�,�v��N�7�+�+�+�,�,�,�,�,�,�,�,�,�,�,����,�,�,�,�,�,�,�,�,�,�,�,�,�,�,����,�,�,�,����*�*��!�4�4�D����4��0�0�4�4��
�
�d�F�3�3�3�4�4�4�4�4�4�4�4�4�4�4����4�4�4�4��� � ����!2�!2�B�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��AF$�F�:E5�C	�!C�6C	�C�C	�	C�
C	�
E5�C
�E5� C
�!1E5�D5�)E5�5D9�9E5�<D9�=,E5�)F�5E9�9F�<E9�=F�F$�F	�F$�F	�F$�$F(�+F(c���tj��5}ttd|���5|�|��ddd��n#1swxYwYddd��dS#1swxYwYdS)zADirectory which contains few error free python source code files.r
ruN�r!rvrrprm)rrys  r�test_correct_directoryz TestCheck.test_correct_directory�s���
�
(�
*�
*�	4�g� ��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+�+A/�2A/c��ttd��5}d}|�d|��}|�||���ddd��dS#1swxYwYdS)zBA python source code file eligible for raising `IndentationError`.r�Iunindent does not match any outer indentation level (<tokenize>, line 3)
�: Indentation Error: �rkNro�rr%rks   r�test_when_wrong_indentedz"TestCheck.test_when_wrong_indented�s���
�\�*:�;�
<�
<�	;�	�*�C��<�<�s�<�<�C��&�&�y�c�&�:�:�:�		;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;����	;�	;�	;�	;�	;�	;��!A	�	A
�A
c��ttd��5}d}|�d|��}|�||���ddd��dS#1swxYwYdS)zEA python source code file eligible for raising 'tokenize.TokenError'.r
z(('EOF in multi-line statement', (7, 0))
z: Token Error: r�Nror�s   r�test_when_tokenize_tokenerrorz'TestCheck.test_when_tokenize_tokenerror�s���
�\�*A�B�
C�
C�	;�y�=�C��6�6��6�6�C��&�&�y�c�&�:�:�:�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;����	;�	;�	;�	;�	;�	;r�c���ttd��5}|�d�}|dz
}|dz
}dt_|�||���ddd��dS#1swxYwYdS)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")\n'
z$indent not equal e.g. at tab size 1
rD�rjN)rrpr;rcrm�rr%rjs   r� test_when_nannynag_error_verbosez*TestCheck.test_when_nannynag_error_verbose�s���
�\�*<�=�
>�
>�	;�)��J�J�J�C��?�?�C��:�:�C� �H���&�&�y�c�&�:�:�:�
	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;����	;�	;�	;�	;�	;�	;s�3A�A�"Ac��ttd��5}|�d�}|�||���ddd��dS#1swxYwYdS)zCA python source code file eligible for raising `tabnanny.NannyNag`.rz 3 '\tprint("world")\n'
r�Nror�s   r�test_when_nannynag_errorz"TestCheck.test_when_nannynag_error�s���
�\�*<�=�
>�
>�	;�)��=�=�=�C��&�&�y�c�&�:�:�:�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;����	;�	;�	;�	;�	;�	;s�A�A	�A	c��d}|�dtj�dtjtj���d|�d�}|�||���dS)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�strerrorrm)r�pathrks   r�test_when_no_filezTestCheck.test_when_no_file�sn�����9�9�e�l�9�9���U�\�*�*�9�9�.2�9�9�9���"�"�4�S�"�1�1�1�1�1rc�v�tj��5}ttd|���}ttd|���}|5}|5}d}|�d|��}|�||���ddd��n#1swxYwYddd��n#1swxYwYddd��dS#1swxYwYdS)z?Directory containing wrongly indented python source code files.rrur
r�r�r�Nr�)rry�
error_file�	code_file�e_file�c_filerks       r�test_errored_directoryz TestCheck.test_errored_directory�s���
�
(�
*�
*�	=�g�(��-�.�'����J�(��\�*�g����I��
=�v�y�
=�F�6���=�=��=�=���*�*�7��*�<�<�<�	
=�
=�
=�
=�
=�
=�
=�
=�
=�
=�
=����
=�
=�
=�
=�
=�
=�
=�
=�
=�
=�
=�
=�
=�
=�
=����
=�
=�
=�
=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=����	=�	=�	=�	=�	=�	=sY�;B.�B�!A?�3B�?B�B�B�B�
B.�B	�B.�B	�B.�.B2�5B2N)rr)r-r.r/r0rfrmrrrr�r�r�r�r�r�r�r1rrrara�s�������#�#����1�1�1�1�2�2�2�
8�8�8�04�4�4�;�;�;�;�;�;�;�;�;�;�;�;�2�2�2�
=�
=�
=�
=�
=rrac�J�eZdZdZejd��d���Zd�ZdS)�TestProcessTokensz$Testing `tabnanny.process_tokens()`.ztabnanny.NannyNagc�D�ttd��5}t|��5}tjtj|j����ddd��n#1swxYwY|�|j	��ddd��dS#1swxYwYdS)z=A python source code without any whitespace related problems.r
N)
rrp�openr;�process_tokens�tokenize�generate_tokens�readline�assertFalse�called)r�MockNannyNagr%r&s    r�test_with_correct_codez(TestProcessTokens.test_with_correct_codes���\�,�7�
8�
8�	2�I��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�Bc
���dD]�}|�|���5tt|��5}t|��5}t	j|j��}|�tj	��5tj
|��ddd��n#1swxYwYddd��n#1swxYwYddd��n#1swxYwYddd��n#1swxYwY��dS)z>A python source code with whitespace related sampled problems.)rr)�keyN)r9rrpr�r�r�r��assertRaisesr;rZr�)rr�r%r&�tokenss     r�test_with_errored_codes_samplesz1TestProcessTokens.test_with_errored_codes_samples
s���B�	<�	<�C����#��&�&�
<�
<�$�\�#�%6�7�7�<�9��i���<�A�!)�!9�!�*�!E�!E��!�.�.�x�/@�A�A�<�<�$�3�F�;�;�;�<�<�<�<�<�<�<�<�<�<�<����<�<�<�<�<�<�<�<�<�<�<�<�<�<�<����<�<�<�<�<�<�<�<�<�<�<�<�<�<�<����<�<�<�<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<����
<�
<�
<�
<��	<�	<s|�C%�C�9B7	�?B �B7	� B$�$B7	�'B$�(B7	�+C�7B;
�;C�>B;
�?C�C%�C�C%�C�C%�%C)	�,C)	N)r-r.r/r0r�patchr�r�r1rrr�r�sP������.�.��T�Z�#�$�$�2�2�%�$�2�<�<�<�<�<rr�c�F�eZdZdZdddd�d�Zd�Zd�Zd�Zd	�Zd
�Z	d�Z
dS)
�TestCommandLinez+Tests command line interface of `tabnanny`.rF)rlrL�partialc�p�tjddg|�R�\}}}tj|��}tj|��}|r�||f||ffD]u\}}	|	���}
|���D]G}|�||
���5|�||
��ddd��n#1swxYwY�H�vdS|�|���|�����|�|���|�����dS)zBCommon function to assert the behaviour of command line interface.z-mr;)�std�outputN)r�assert_python_okr��fsdecode�
splitlinesr9rx�assertListEqual)rrlrLr�rK�_rjrkr�r��_output�_stds            r�validate_cmdzTestCommandLine.validate_cmd"s���#�4�T�:�M��M�M�M���3���k�#�����k�#�����	H�!'��
���}�=�
5�
5���V� �+�+�-�-���N�N�,�,�5�5�D����$�w��?�?�5�5��
�
�d�G�4�4�4�5�5�5�5�5�5�5�5�5�5�5����5�5�5�5��5�
5�
5�
� � ����!1�!1�6�3D�3D�3F�3F�G�G�G�� � ����!1�!1�6�3D�3D�3F�3F�G�G�G�G�Gs�B3�3B7�:B7c��ttd��5}|�d�}|dz
}|�||���ddd��dS#1swxYwYdS)z8Should displays error when errored python file is given.rr�zHunindent does not match any outer indentation level (<tokenize>, line 3)�rLN�rrpr�)rr%rLs   r�test_with_errored_filez&TestCommandLine.test_with_errored_file3s���
�\�*:�;�
<�
<�	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�Ac��ttd��5}|�|��ddd��dS#1swxYwYdS)zAShould not display anything if python file is correctly indented.r
Nr�rqs  r�test_with_error_free_filez)TestCommandLine.test_with_error_free_file;s���
�\�,�7�
8�
8�	)�I����i�(�(�(�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)����	)�	)�	)�	)�	)�	)rsc�\�td��}d|�d�}|�|���dS)z%Should display usage on no arguments.ztabnanny.pyzUsage: z [-v] file_or_directory ...r�N)rr�)rr�rLs   r�test_command_usagez"TestCommandLine.test_command_usage@s<���
�&�&��<�4�<�<�<�������(�(�(�(�(rc��ttd��5}|�d�}|�d||���ddd��dS#1swxYwYdS)z*Should display less when quite mode is on.rrGz-q)rlNr�)rr%rls   r�test_quiet_flagzTestCommandLine.test_quiet_flagFs���
�\�*<�=�
>�
>�	>�)�!�%�%�%�F����d�I�f��=�=�=�	>�	>�	>�	>�	>�	>�	>�	>�	>�	>�	>�	>����	>�	>�	>�	>�	>�	>s�A�A
�
A
c���ttd��5}tjd�����}|�d||d���ddd��dS#1swxYwYdS)z<Should display more error information if verbose mode is on.r�$offending line: '\tprint("world")\n'z-vT�rlr�N�rrp�textwrap�dedent�stripr��rr�rls   r�test_verbose_modez!TestCommandLine.test_verbose_modeLs���
�\�*<�=�
>�
>�	G�$��_�:����e�g�g�
�
���d�D����F�F�F�		G�	G�	G�	G�	G�	G�	G�	G�	G�	G�	G�	G����	G�	G�	G�	G�	G�	G��AA(�(A,�/A,c���ttd��5}tjd�����}|�d||d���ddd��dS#1swxYwYdS)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_modeTs���
�\�*<�=�
>�
>�	H�$��_�:����e�g�g�
�
���e�T�&�$��G�G�G�		H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H����	H�	H�	H�	H�	H�	Hr�N)r-r.r/r0r�r�r�r�r�r�r�r1rrr�r�s�������5�5�)+�B��H�H�H�H�H�"8�8�8�)�)�)�
)�)�)�>�>�>�G�G�G�H�H�H�H�Hrr�)r0�unittestrrr�r�r;r�r!r��test.supportrrrr�test.support.os_helperr	rprr3r@rOrar�r�r1rr�<module>r�s"����
$�#�#�#�#�#�#�#�����	�	�	�	�����������������$�$�$�$�$�$�$�$�$�$�$�$�)�)�)�)�)�)�
	�	%�	%�	%�	!�	'�K*�*��Z��������&M�M�M�M�M�(�M�M�M�"?�?�?�?�?�8�?�?�?�&9�9�9�9�9�8�9�9�9�6m=�m=�m=�m=�m=��m=�m=�m=�`<�<�<�<�<��<�<�<�<;H�;H�;H�;H�;H�h�;H�;H�;H�;H�;Hr