Current File : //usr/local/apps/python3/lib/python3.11/lib2to3/tests/__pycache__/test_refactor.cpython-311.pyc
�

�Ke*1���dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZddl
mZej�ej�e��d��Zej�ed��Zej�e��	e
jd��Zej���n#ej���wxYwe
jd��ZGd	�d
ej��ZdS)z
Unit tests for refactor.py.
�N)�refactor�pygram�
fixer_base)�token�data�fixers�myfixes�
lib2to3.fixesc���eZdZd�Zd�Zd�Zdedfd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zedddfd�Zd�Zd�Zefd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z dS)�TestRefactoringToolc�N�tj�t��dS�N)�sys�path�append�	FIXER_DIR��selfs �E/usr/local/apps/python3/lib/python3.11/lib2to3/tests/test_refactor.py�setUpzTestRefactoringTool.setUps������	�"�"�"�"�"�c�B�tj���dSr)rr�poprs r�tearDownzTestRefactoringTool.tearDown"s����������rc��t||��D].\}}t||��s|�d|z|���/dS)Nz%s are not instances of %s)�zip�
isinstance�fail)r�	instances�classes�inst�clss     r�check_instancesz#TestRefactoringTool.check_instances%s[���Y��0�0�	M�	M�I�D�#��d�C�(�(�
M��	�	�6��B�G�L�L�L��	M�	MrNc�.�tj|||��Sr)r�RefactoringTool)r�optionsr�explicits    r�rtzTestRefactoringTool.rt*s���'����B�B�Brc��|�ddi��}|�d|jj��|�d|jjj��dS)N�print_functionT�print�r(�assertNotIn�grammar�keywords�driver�rr(s  r�test_print_function_optionz.TestRefactoringTool.test_print_function_option-sX��
�W�W�&��.�
/�
/������"�*�"5�6�6�6�����"�)�"3�"<�=�=�=�=�=rc��|�ddi��}|�d|jj��|�d|jjj��dS)N�
exec_functionT�execr,r1s  r�test_exec_function_optionz-TestRefactoringTool.test_exec_function_option2sW��
�W�W�o��-�
.�
.��������!4�5�5�5�������!2�!;�<�<�<�<�<rc���|���}|�|j��|�ddi��}|�|j��dS)N�write_unchanged_filesT)r(�assertFalser8�
assertTruer1s  r�!test_write_unchanged_files_optionz5TestRefactoringTool.test_write_unchanged_files_option7sX��
�W�W�Y�Y������1�2�2�2�
�W�W�-��5�
6�
6������0�1�1�1�1�1rc�4�gd�}tjd��}tjdd��}tjd��}|�|d�|D����|�||��|�|d�|D����dS)N)r'�first�last�parrot�preorderr	Fc��g|]}d|z��S)�fix_���.0�names  r�
<listcomp>zBTestRefactoringTool.test_fixer_loading_helpers.<locals>.<listcomp>Bs��#G�#G�#G�d�F�T�M�#G�#G�#Grc��g|]}d|z��S)zmyfixes.fix_rCrDs  rrGzBTestRefactoringTool.test_fixer_loading_helpers.<locals>.<listcomp>Es��E�E�E�D�.�4�/�E�E�Er)r�get_all_fix_names�get_fixers_from_package�assertEqual)r�contents�non_prefixed�prefixed�
full_namess     r�test_fixer_loading_helpersz.TestRefactoringTool.test_fixer_loading_helpers=s���F�F�F���1�)�<�<���-�i��?�?���5�i�@�@�
�����#G�#G�h�#G�#G�#G�H�H�H�����x�0�0�0�����E�E�H�E�E�E�	G�	G�	G�	G�	Grc�2�tj}t}|��}|�|d��|��|�|d��|d����|�|d��|d����|�|d��|d����d}|�||��|d	����d
}|�||��|d����d}|�||��|d����d
}|�||��|d	����d}|�||��|d����d}|�||��|d	����d}|D]!}|�||��|���"d}|�||��|d����d}|�||��|��d}|�||��|d����d}|�||��|d����d}|�||��|��dS)N�z%from __future__ import print_function)r*z!from __future__ import generators)�
generatorsz*from __future__ import generators, feature)rS�featurez1from __future__ import generators, print_function)rSr*z1from __future__ import print_function, generators)r*rSz(from __future__ import (print_function,)z3from __future__ import (generators, print_function)z2from __future__ import (generators, nested_scopes))rS�
nested_scopeszGfrom __future__ import generators
from __future__ import print_function)�fromzfrom 4zfrom xzfrom x 5z	from x imz
from x importzfrom x import 4z1'docstring'
from __future__ import print_functionz9'docstring'
'somng'
from __future__ import print_functionz/# comment
from __future__ import print_functionz5# comment
'doc'
from __future__ import print_functionz3class x: pass
from __future__ import print_function)r�_detect_future_features�	frozensetrK)r�run�fs�empty�inp�invalids      r�test_detect_future_featuresz/TestRefactoringTool.test_detect_future_featuresGs����.��
������������R���%�(�(�(������D�E�E���/�0�0�	2�	2�	2������@�A�A���O�,�,�	.�	.�	.������I�J�J���5�6�6�	8�	8�	8�A�������S���2�2�&F�#G�#G�H�H�H�
@�������S���2�2�&F�#G�#G�H�H�H�8�������S���2�2�&9�#:�#:�;�;�;�C�������S���2�2�&F�#G�#G�H�H�H�B�������S���2�2�&E�#F�#F�G�G�G�)�������S���2�2�&F�#G�#G�H�H�H����	.�	.�C����S�S��X�X�u�-�-�-�-�B�������S���2�2�&9�#:�#:�;�;�;�K�������S���5�)�)�)�@�������S���2�2�&9�#:�#:�;�;�;�G�������S���2�2�&9�#:�#:�;�;�;�D�������S���5�)�)�)�)�)rc�N�Gd�dtj��}Gd�dtj��}Gd�dtj��}|ig��}|ig��}|ig��}tj|||g��}|�t
jj��}|�|||g��|�tj
��}	|�|	||g��|���D]}
|�|
|g���dS)Nc��eZdZdS)�;TestRefactoringTool.test_get_headnode_dict.<locals>.NoneFixN)�__name__�
__module__�__qualname__rCrr�NoneFixraus�������Drrec��eZdZdZdS)�@TestRefactoringTool.test_get_headnode_dict.<locals>.FileInputFixzfile_input< any * >N�rbrcrd�PATTERNrCrr�FileInputFixrgxs������+�G�G�Grrjc��eZdZdZdS)�=TestRefactoringTool.test_get_headnode_dict.<locals>.SimpleFixz'name'NrhrCrr�	SimpleFixrl{s�������G�G�Grrm)r�BaseFixr�_get_headnode_dictrr�python_symbols�
file_inputrKr�NAME�values)rrerjrm�no_head�	with_head�simple�d�	top_fixes�
name_fixes�fixess           r�test_get_headnode_dictz*TestRefactoringTool.test_get_headnode_dicttso��	�	�	�	�	�j�(�	�	�	�	,�	,�	,�	,�	,�:�-�	,�	,�	,�	�	�	�	�	�
�*�	�	�	��'�"�b�/�/�� �L��R�(�(�	���2�r�"�"���'��)�V�(D�E�E���E�E�&�/�:�;�;�	�����Y��$8�9�9�9��U�U�5�:�&�&�
�����f�g�%6�7�7�7��X�X�Z�Z�	/�	/�E����U�W�I�.�.�.�.�	/�	/rc���ddlm}ddlm}ddlm}ddlm}|���}|�	��\}}|�
||g��|�
||||g��dS)Nr)�FixFirst)�FixLast)�	FixParrot)�FixPreorder)�myfixes.fix_firstr}�myfixes.fix_lastr~�myfixes.fix_parrotr�myfixes.fix_preorderr�r(�
get_fixersr#)rr}r~rr�r(�pre�posts        r�test_fixer_loadingz&TestRefactoringTool.test_fixer_loading�s���.�.�.�.�.�.�,�,�,�,�,�,�0�0�0�0�0�0�4�4�4�4�4�4�
�W�W�Y�Y���M�M�O�O�	��T����S�;�-�0�0�0����T�H�i��#A�B�B�B�B�Brc���|�t|jdg���|�tj|jdg���|�tj|jdg���dS)N�not_here�r�no_fixer_cls�	bad_order)�assertRaises�ImportErrorr(r�
FixerErrorrs r�test_naughty_fixersz'TestRefactoringTool.test_naughty_fixers�sl�����+�t�w�
�|��D�D�D����(�-�t�w��?O��P�P�P����(�-�t�w��}��M�M�M�M�Mrc��|���}d}|�|d��}|�t|��|��d}|�|d��}|�t|��|��dS)N�def parrot(): pass

�<test>zdef f(): pass

)r(�refactor_string�assertNotEqual�strrK)rr(�input�trees    r�test_refactor_stringz(TestRefactoringTool.test_refactor_string�s���
�W�W�Y�Y��(���!�!�%��2�2�����C��I�I�u�-�-�-�#���!�!�%��2�2������T���E�*�*�*�*�*rc�N��G�fd�dtj��}g�|t��}tj}tjd��t_	|���|t_n#|t_wxYwgd�}|��|��dS)Nc���eZdZ�fd�ZdS)�5TestRefactoringTool.test_refactor_stdin.<locals>.MyRTc�:����||||g��dSr)�extend)r�old_text�new_text�filename�equal�resultss     �r�print_outputzBTestRefactoringTool.test_refactor_stdin.<locals>.MyRT.print_output�s$�������(�H�e�D�E�E�E�E�ErN)rbrcrdr�)r�s�r�MyRTr��s5�������
F�
F�
F�
F�
F�
F�
Frr�r�)r�zdef cheese(): pass

z<stdin>F)	rr%�_DEFAULT_FIXERSr�stdin�io�StringIO�refactor_stdinrK)rr�r(�save�expectedr�s     @r�test_refactor_stdinz'TestRefactoringTool.test_refactor_stdin�s����	F�	F�	F�	F�	F�	F�	F�8�+�	F�	F�	F�
��
�T�/�
"�
"���y���K� 8�9�9��	�	��������C�I�I���C�I�����&�&�&��	
����(�+�+�+�+�+s�A:�:BTc��|�|��}|�|��}|�||���}|r||_|�|��|�||�|����|sdS|�|d��|�|��}|�||��|S)N)rr&T)�init_test_file�	read_filer(�	log_debug�
refactor_filerKr�)	r�	test_filerr&�mock_log_debug�actually_write�old_contentsr(�new_contentss	         r�check_file_refactoringz*TestRefactoringTool.check_file_refactoring�s����'�'�	�2�2�	��~�~�i�0�0��
�W�W�F�G�W�
4�
4���	*�)�B�L�
����#�#�#�����t�~�~�i�'@�'@�A�A�A��	��F�
����D�)�)�)��~�~�i�0�0�����L�,�7�7�7��rc�>�tjd���}|�tj|��tj||��tj�|tj�	|����}t
j
|d��|S)N�2to3-test_refactor��prefixi�)�tempfile�mkdtemp�
addCleanup�shutil�rmtree�copy�osr�join�basename�chmod)rr��tmpdirs   rr�z"TestRefactoringTool.init_test_file�s{���!�)=�>�>�>������
�v�.�.�.���I�v�&�&�&��G�L�L����)9�)9�)�)D�)D�E�E�	�
���E�"�"�"��rc�~�t|d��5}|���cddd��S#1swxYwYdS)N�rb)�open�read)rr��fps   rr�zTestRefactoringTool.read_file�s~��
�)�T�
"�
"�	�b��7�7�9�9�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s�2�6�6c���|�|��}|�|��}|�|���}|�|d��|�|��}||fS)Nr�T)r�r�r(r�)rr�rr�r(r�s      rr�z!TestRefactoringTool.refactor_file�sk���'�'�	�2�2�	��~�~�i�0�0��
�W�W�F�W�
#�
#��
����D�)�)�)��~�~�i�0�0���\�)�)rc��tj�td��}|�|t
��dS)N�parrot_example.py)r�rr�rr�r�)rr�s  r�test_refactor_filez&TestRefactoringTool.test_refactor_file�s4���G�L�L��,?�@�@�	��#�#�I��?�?�?�?�?rc���tj�td��}g��fd�}|�|dddi|d���dtjtjtj�|��z��z}�D]}d	|vr|�	||��dS� |�
|�d
�����dS)Nr�c�8����||z��dSr�r)�msg�args�debug_messagess  �r�recording_log_debugzXTestRefactoringTool.test_refactor_file_write_unchanged_file.<locals>.recording_log_debug�s!����!�!�#��*�-�-�-�-�-rrCr8TF)rr&r�r�zNot writing changes to .*%szNot writing changesz not matched in )r�rr�rr��re�escape�sepr��assertRegexr)rr�r��
message_regex�messager�s     @r�'test_refactor_file_write_unchanged_filez;TestRefactoringTool.test_refactor_file_write_unchanged_file�s�����G�L�L��,?�@�@�	���	.�	.�	.�	.�	.��#�#�I�b�-D�d�,K�3F�38�	$�	:�	:�	:�7��	�"�&�2�7�#3�#3�I�#>�#>�>�?�?�@�
�%�	P�	P�G�$��/�/�� � ��-�8�8�8����0�
�I�I�
�
�
�~�~�N�O�O�O�O�Orc����fd�}|gg��gd�}dg}|||��dtj�dd��g}|||��dS)Nc������fd�}tjj}|tj_����}g�t	jd����	t
jtj�	�d����|D]B}ttj�	�|��d������C|����|tj_tj���n*#|tj_tj���wxYw����fd�|D����dS)Nc�2����|��dSrr�)r�fr��gots   �r�mock_refactor_filezPTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.mock_refactor_file�s����
�
�1�
�
�
�
�
rr�r��a_dir�wbc�P��g|]"}tj��|����#SrC�r�rr�)rEr�dirs  �rrGzHTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.<listcomp>	s)���K�K�K�$�b�g�l�l�3��5�5�K�K�Kr)rr%r�r(r�r�r��mkdirrr�r��close�refactor_dirr�r�rK)	�	structurer�r��	save_funcr(�fnr�r�rs	      @@�r�checkz4TestRefactoringTool.test_refactor_dir.<locals>.check�sR�����
�
�
�
�
� �0�>�I�5G�H�$�2������B��C��"�*>�?�?�?�C�
#�������c�7�3�3�4�4�4�#�>�>�B������c�2�.�.��5�5�;�;�=�=�=�=�����$�$�$�9B��(�6��
�c�"�"�"�"��:C��(�6��
�c�"�"�"�"�������S�K�K�K�K�(�K�K�K�
M�
M�
M�
M�
Ms
�BD	�	'D0)�nothing�hi.pyz.dumbz	.after.pyz	notpy.npy�sappyr�r�zstuff.pyr�)rr�r�r�s`   r�test_refactor_dirz%TestRefactoringTool.test_refactor_dir�s����	M�	M�	M�	M�	M�$	��b�"�
�
�
������9��
��d�H���������W�j�1�1�3��
��d�D�����rc�z�tj�td��}|�|��dS)Nzdifferent_encoding.py�r�rr��
TEST_DATA_DIRr�)rr�s  r�test_file_encodingz&TestRefactoringTool.test_file_encodings2��
�W�\�\�-�)@�
A�
A���#�#�B�'�'�'�'�'rc�z�tj�td��}|�|��}dS)Nzfalse_encoding.pyr��rr�rs   r�test_false_file_encodingz,TestRefactoringTool.test_false_file_encodings/��
�W�\�\�-�)<�
=�
=���*�*�2�.�.���rc���tj�td��}|�|��}|�|�tj����dS)Nzbom.py)	r�rr�r�r�r:�
startswith�codecs�BOM_UTF8r�s   r�test_bomzTestRefactoringTool.test_bomsP��
�W�\�\�-��
2�
2���*�*�2�.�.����������8�8�9�9�9�9�9rc��tj}dt_	tj�td��}tjd��}|�||��|t_dS#|t_wxYw)Nz
�crlf.pyr
)r��lineseprr�r�rrJr�)r�old_sepr�rzs    r�test_crlf_newlinesz&TestRefactoringTool.test_crlf_newlines$sn���*����
�	!�����m�Y�7�7�B��4�_�E�E�E��'�'��E�2�2�2� �B�J�J�J���B�J� � � � s�AA7�7Bc��tj�td��}|�|��\}}|�d|��|�d|��|�d|��dS)Nrs
s

)r�rr�r�r��assertInr-)rr��old�news    r�test_crlf_unchangedz'TestRefactoringTool.test_crlf_unchanged.sr��
�W�\�\�-��
3�
3���%�%�b�)�)���S��
�
�g�s�#�#�#��
�
�g�s�#�#�#�����C�(�(�(�(�(rc���|���}d}|�|d��}|�||��d}|�|d��}|�||��dS)Nz
>>> example()
42
r�z&
>>> def parrot():
...      return 43
)r(�refactor_docstringrKr�)rr(�doc�outs    r�test_refactor_docstringz+TestRefactoringTool.test_refactor_docstring5s}��
�W�W�Y�Y�����#�#�C��2�2������c�"�"�"����#�#�C��2�2�����C��%�%�%�%�%rc�"�ddlm}|�dg���}|�t	|j��d��|�dg���}|jD]}t
||��rdS�|�d��dS)Nr)�FixExplicitzmyfixes.fix_explicitr�)r'zexplicit fixer not loaded)�myfixes.fix_explicitrr(rK�len�
post_orderrr)rrr(�fixs    r�
test_explicitz!TestRefactoringTool.test_explicitFs���4�4�4�4�4�4�
�W�W�3�4�W�
5�
5������R�]�+�+�Q�/�/�/�
�W�W�5�6�W�
7�
7���=�	3�	3�C��#�{�+�+�
����
�
�I�I�1�2�2�2�2�2r)!rbrcrdrrr#r�r(r2r6r;rPr^r{r�r�r�r��_2TO3_FIXERSr�r�r�r�r�r�r�r�r�rrrrrrCrrrrs�������#�#�#����M�M�M�
�o��C�C�C�C�>�>�>�
=�=�=�
2�2�2�G�G�G�+*�+*�+*�Z/�/�/�*
C�
C�
C�N�N�N�
+�+�+�,�,�,�(8D�'+�D�.2�����&������/;�*�*�*�*�@�@�@�P�P�P�(���@(�(�(�/�/�/�:�:�:�
!�!�!�)�)�)�&�&�&�"3�3�3�3�3rr)�__doc__rr�r�r�r�r�r��unittest�lib2to3rrr�
lib2to3.pgen2rrr��dirname�__file__r�rrrJr�rr�TestCaserrCrr�<module>r sf�����
�
�
�	�	�	�	�
�
�
�
�	�	�	�	�	�	�	�	�����
�
�
�
�����0�0�0�0�0�0�0�0�0�0�����������R�W�_�_�X�6�6��?�?�
��G�L�L���1�1�	�����	�����6�h�6�y�A�A�O��H�L�L�N�N�N�N��C�H�L�L�N�N�N�N����/�x�/��@�@��t3�t3�t3�t3�t3�(�+�t3�t3�t3�t3�t3s�C�C!