Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/test/test_lib2to3/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/test/test_lib2to3/__pycache__/test_refactor.cpython-312.pyc

�

)Μg*1��&�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZddl
mZejj!ejj#e�d�Zejj!ed�Zejj+e�	e
j,d�Zejj1�e
j,d�ZGd	�d
ej4�Zy#ejj1�wxYw)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 y)�TestRefactoringToolc�J�tjjt�y�N)�sys�path�append�	FIXER_DIR��selfs �</usr/local/lib/python3.12/test/test_lib2to3/test_refactor.py�setUpzTestRefactoringTool.setUps�������	�"�c�@�tjj�yr)rr�poprs r�tearDownzTestRefactoringTool.tearDown"s�������rc�p�t||�D]'\}}t||�r�|jd|z|��)y)Nz%s are not instances of %s)�zip�
isinstance�fail)r�	instances�classes�inst�clss     r�check_instancesz#TestRefactoringTool.check_instances%s5���Y��0�I�D�#��d�C�(��	�	�6��B�G�L�1rNc�0�tj|||�Sr)r�RefactoringTool)r�optionsr�explicits    r�rtzTestRefactoringTool.rt*s���'�'����B�Brc���|jddi�}|jd|jj�|jd|jjj�y)N�print_functionT�print�r(�assertNotIn�grammar�keywords�driver�rr(s  r�test_print_function_optionz.TestRefactoringTool.test_print_function_option-sP��
�W�W�&��.�
/������"�*�*�"5�"5�6�����"�)�)�"3�"3�"<�"<�=rc���|jddi�}|jd|jj�|jd|jjj�y)N�
exec_functionT�execr,r1s  r�test_exec_function_optionz-TestRefactoringTool.test_exec_function_option2sO��
�W�W�o��-�
.���������!4�!4�5��������!2�!2�!;�!;�<rc��|j�}|j|j�|jddi�}|j|j�y)N�write_unchanged_filesT)r(�assertFalser8�
assertTruer1s  r�!test_write_unchanged_files_optionz5TestRefactoringTool.test_write_unchanged_files_option7sG��
�W�W�Y������1�1�2�
�W�W�-��5�
6������0�0�1rc�P�gd�}tjd�}tjdd�}tjd�}|j||D�cgc]}d|z��	c}�|j||�|j||D�cgc]}d|z��	c}�ycc}wcc}w)N)r'�first�last�parrot�preorderr	F�fix_zmyfixes.fix_)r�get_all_fix_names�get_fixers_from_package�assertEqual)r�contents�non_prefixed�prefixed�
full_names�names      r�test_fixer_loading_helpersz.TestRefactoringTool.test_fixer_loading_helpers=s���F���1�1�)�<���-�-�i��?���5�5�i�@�
�����h�#G�h�d�F�T�M�h�#G�H�����x�0�����<D�E�H�D�.�4�/�H�E�	G��$H��Fs�B
�
B#
c��tj}t}|�}|j|d�|�|j|d�|d��|j|d�|d��|j|d�|d��d}|j||�|d	��d
}|j||�|d��d}|j||�|d��d
}|j||�|d	��d}|j||�|d��d}|j||�|d	��d}|D]}|j||�|��d}|j||�|d��d}|j||�|�d}|j||�|d��d}|j||�|d��d}|j||�|�y)N�z%from __future__ import print_function)r*z!from __future__ import generators)�
generatorsz*from __future__ import generators, feature)rM�featurez1from __future__ import generators, print_function)rMr*z1from __future__ import print_function, generators)r*rMz(from __future__ import (print_function,)z3from __future__ import (generators, print_function)z2from __future__ import (generators, nested_scopes))rM�
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�	frozensetrD)r�run�fs�empty�inp�invalids      r�test_detect_future_featuresz/TestRefactoringTool.test_detect_future_featuresGs����.�.��
���������R��%�(�����D�E��/�0�	2�����@�A��O�,�	.�����I�J��5�6�	8�A������S��2�&F�#G�H�
@������S��2�&F�#G�H�8������S��2�&9�#:�;�C������S��2�&F�#G�H�B������S��2�&E�#F�G�)������S��2�&F�#G�H����C����S��X�u�-��B������S��2�&9�#:�;�K������S��5�)�@������S��2�&9�#:�;�G������S��2�&9�#:�;�D������S��5�)rc�0�Gd�dtj�}Gd�dtj�}Gd�dtj�}|ig�}|ig�}|ig�}tj|||g�}|j	t
jj�}|j|||g�|j	tj�}	|j|	||g�|j�D]}
|j|
|g��y)Nc��eZdZy)�;TestRefactoringTool.test_get_headnode_dict.<locals>.NoneFixN)�__name__�
__module__�__qualname__�rr�NoneFixr[us��rr`c��eZdZdZy)�@TestRefactoringTool.test_get_headnode_dict.<locals>.FileInputFixzfile_input< any * >N�r\r]r^�PATTERNr_rr�FileInputFixrbxs��+�Grrec��eZdZdZy)�=TestRefactoringTool.test_get_headnode_dict.<locals>.SimpleFixz'name'Nrcr_rr�	SimpleFixrg{s���Grrh)r�BaseFixr�_get_headnode_dictrr�python_symbols�
file_inputrDr�NAME�values)rr`rerh�no_head�	with_head�simple�d�	top_fixes�
name_fixes�fixess           r�test_get_headnode_dictz*TestRefactoringTool.test_get_headnode_dictts���	�j�(�(�	�	,�:�-�-�	,�	�
�*�*�	��"�b�/�� ��R�(�	��2�r�"���'�'��)�V�(D�E���E�E�&�/�/�:�:�;�	�����Y��$8�9��U�U�5�:�:�&�
�����f�g�%6�7��X�X�Z�E����U�W�I�.� rc���ddlm}ddlm}ddlm}ddlm}|j�}|j�\}}|j||g�|j||||g�y)Nr)�FixFirst)�FixLast)�	FixParrot)�FixPreorder)�myfixes.fix_firstrx�myfixes.fix_lastry�myfixes.fix_parrotrz�myfixes.fix_preorderr{r(�
get_fixersr#)rrxryrzr{r(�pre�posts        r�test_fixer_loadingz&TestRefactoringTool.test_fixer_loading�sQ��.�,�0�4�
�W�W�Y���M�M�O�	��T����S�;�-�0����T�H�i��#A�Brc��|jt|jdg��|jtj|jdg��|jtj|jdg��y)N�not_here�r�no_fixer_cls�	bad_order)�assertRaises�ImportErrorr(r�
FixerErrorrs r�test_naughty_fixersz'TestRefactoringTool.test_naughty_fixers�s`�����+�t�w�w�
�|��D����(�-�-�t�w�w��?O��P����(�-�-�t�w�w��}��Mrc���|j�}d}|j|d�}|jt|�|�d}|j|d�}|j	t|�|�y)N�def parrot(): pass

�<test>zdef f(): pass

)r(�refactor_string�assertNotEqual�strrD)rr(�input�trees    r�test_refactor_stringz(TestRefactoringTool.test_refactor_string�sc��
�W�W�Y��(���!�!�%��2�����C��I�u�-�#���!�!�%��2������T��E�*rc�8��G�fd�dtj�}g�|t�}tj}tjd�t_	|j�|t_gd�}|j�|�y#|t_wxYw)Nc���eZdZ�fd�Zy)�5TestRefactoringTool.test_refactor_stdin.<locals>.MyRTc�0���j||||g�yr)�extend)r�old_text�new_text�filename�equal�resultss     �r�print_outputzBTestRefactoringTool.test_refactor_stdin.<locals>.MyRT.print_output�s�������(�H�e�D�ErN)r\r]r^r�)r�s�r�MyRTr��s	���
Frr�r�)r�zdef cheese(): pass

z<stdin>F)	rr%�_DEFAULT_FIXERSr�stdin�io�StringIO�refactor_stdinrD)rr�r(�save�expectedr�s     @r�test_refactor_stdinz'TestRefactoringTool.test_refactor_stdin�s~���	F�8�+�+�	F�
��
�/�
"���y�y���K�K� 8�9��	�	������C�I�&��	
����(�+��	�C�I�s�B�
BTc�V�|j|�}|j|�}|j||��}|r||_|j	|�|j||j|��|sy|j	|d�|j|�}|j
||�|S)N)rr&T)�init_test_file�	read_filer(�	log_debug�
refactor_filerDr�)	r�	test_filerr&�mock_log_debug�actually_write�old_contentsr(�new_contentss	         r�check_file_refactoringz*TestRefactoringTool.check_file_refactoring�s����'�'�	�2�	��~�~�i�0��
�W�W�F�G�W�
4���)�B�L�
����#�����t�~�~�i�'@�A���
����D�)��~�~�i�0�����L�,�7��rc�D�tjd��}|jtj|�tj
||�tjj|tjj|��}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�sj���!�!�)=�>������
�
�v�.����I�v�&��G�G�L�L�����)9�)9�)�)D�E�	�
����E�"��rc�f�t|d�5}|j�cddd�S#1swYyxYw)N�rb)�open�read)rr��fps   rr�zTestRefactoringTool.read_file�s#��
�)�T�
"�b��7�7�9�#�
"�
"�s�'�0c��|j|�}|j|�}|j|��}|j|d�|j|�}||fS)Nr�T)r�r�r(r�)rr�rr�r(r�s      rr�z!TestRefactoringTool.refactor_file�sY���'�'�	�2�	��~�~�i�0��
�W�W�F�W�
#��
����D�)��~�~�i�0���\�)�)rc�x�tjjtd�}|j	|t
�y)N�parrot_example.py)r�rr�rr�r�)rr�s  r�test_refactor_filez&TestRefactoringTool.test_refactor_file�s'���G�G�L�L��,?�@�	��#�#�I��?rc���tjjtd�}g��fd�}|j	|dddi|d��dtjtjtjj|�z�z}�D]}d	|vs�|j||�y|j|�d
����y)Nr�c�.���j||z�yr�r)�msg�args�debug_messagess  �r�recording_log_debugzXTestRefactoringTool.test_refactor_file_write_unchanged_file.<locals>.recording_log_debug�s����!�!�#��*�-rr_r8TF)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�G�L�L��,?�@�	���	.��#�#�I�b�-D�d�,K�3F�38�	$�	:�7��	�	�"�&�&�2�7�7�#3�#3�I�#>�>�?�@�
�%�G�$��/�� � ��-�8��&�

�I�I�
�~�N�Orc����fd�}|gg�gd�}dg}|||�dtjjdd�g}|||�y)Nc
�����fd�}tjj}|tj_�	j�}g�t	j
d��}	t
jtjj|d��|D]:}ttjj||�d�j��<|j|�|tj_tj|��	j�|D�cgc]"}tjj||���$c}�y#|tj_tj|�wxYwcc}w)Nc�(���j|�yrr�)r�fr��gots   �r�mock_refactor_filezPTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.mock_refactor_file�s����
�
�1�
rr�r��a_dir�wb)rr%r�r(r�r�r��mkdirrr�r��close�refactor_dirr�r�rD)
�	structurer�r��	save_funcr(�dir�fnrr�rs
        @�r�checkz4TestRefactoringTool.test_refactor_dir.<locals>.check�s
���
� �0�0�>�>�I�5G�H�$�$�2�����B��C��"�"�*>�?�C�
#���������c�7�3�4�#�B�������c�2�.��5�;�;�=�$�����$�9B��(�(�6��
�
�c�"����S�BJ�K�(�$�b�g�g�l�l�3��5�(�K�
M��:C��(�(�6��
�
�c�"��Ks� BE�'E;
�,E8)�nothing�hi.pyz.dumbz	.after.pyz	notpy.npy�sappyr�r�zstuff.py)r�rr�)rr�r�r�s`   r�test_refactor_dirz%TestRefactoringTool.test_refactor_dir�sT���	M�$	�b�"�
����9��
�d�H��������W�j�1�3��
�d�D�rc�n�tjjtd�}|j	|�y)Nzdifferent_encoding.py�r�rr��
TEST_DATA_DIRr�)rr�s  r�test_file_encodingz&TestRefactoringTool.test_file_encodings%��
�W�W�\�\�-�)@�
A���#�#�B�'rc�n�tjjtd�}|j	|�}y)Nzfalse_encoding.pyr��rr�rs   r�test_false_file_encodingz,TestRefactoringTool.test_false_file_encodings'��
�W�W�\�\�-�)<�
=���*�*�2�.�rc���tjjtd�}|j	|�}|j|j
tj��y)Nzbom.py)	r�rr�r�r�r:�
startswith�codecs�BOM_UTF8r�s   r�test_bomzTestRefactoringTool.test_boms?��
�W�W�\�\�-��
2���*�*�2�.�����������8�9rc��tj}dt_	tjjtd�}tjd�}|j||�|t_y#|t_wxYw)Nz
�crlf.pyr
)r��lineseprr�r�rrCr�)r�old_sepr�rus    r�test_crlf_newlinesz&TestRefactoringTool.test_crlf_newlines$sZ���*�*����
�	!������m�Y�7�B��4�4�_�E�E��'�'��E�2� �B�J���B�J�s�AA4�4
Bc���tjjtd�}|j	|�\}}|jd|�|jd|�|j
d|�y)Nr�s
s

)r�rr�r�r��assertInr-)rr��old�news    r�test_crlf_unchangedz'TestRefactoringTool.test_crlf_unchanged.sV��
�W�W�\�\�-��
3���%�%�b�)���S��
�
�g�s�#��
�
�g�s�#�����C�(rc��|j�}d}|j|d�}|j||�d}|j|d�}|j||�y)Nz
>>> example()
42
r�z&
>>> def parrot():
...      return 43
)r(�refactor_docstringrDr�)rr(�doc�outs    r�test_refactor_docstringz+TestRefactoringTool.test_refactor_docstring5sc��
�W�W�Y�����#�#�C��2������c�"����#�#�C��2�����C��%rc��ddlm}|jdg��}|jt	|j
�d�|jdg��}|j
D]}t
||�s�y|jd�y)Nr)�FixExplicitzmyfixes.fix_explicitr�)r'zexplicit fixer not loaded)�myfixes.fix_explicitrr(rD�len�
post_orderrr)rrr(�fixs    r�
test_explicitz!TestRefactoringTool.test_explicitFsp��4�
�W�W�3�4�W�
5������R�]�]�+�Q�/�
�W�W�5�6�W�
7���=�=�C��#�{�+��!�
�I�I�1�2r)!r\r]r^rrr#r�r(r2r6r;rJrXrvr�r�r�r��_2TO3_FIXERSr�r�r�r�r�r�r�r�r�r�r�rr	rr_rrrrs���#��M�
�o��C�>�
=�
2�G�+*�Z/�*
C�N�
+�,�(8D�'+�D�.2��&��/;�*�@�P�(�@(�/�:�
!�)�&�"3rr)�__doc__rr�r�r�r�r�r��unittest�lib2to3rrr�
lib2to3.pgen2rrr��dirname�__file__r�rrrCr�rr�TestCaserr_rr�<module>rs�����	�
�	�	��
��0�0�������R�W�W�_�_�X�6��?�
��G�G�L�L���1�	������	���6�h�6�6�y�A�O��H�H�L�L�N�/�x�/�/��@��t3�(�+�+�t3��	�H�H�L�L�N�s� C4�4D

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists