HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/lib2to3/tests/__pycache__/test_refactor.cpython-310.opt-1.pyc
o

�i*1�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZddl
mZej�ej�e�d�Zej�ed�Zej�e�ze
�d�ZWej��nej��we
�d�ZGd	d
�d
ej�ZdS)z
Unit tests for refactor.py.
�N)�refactor�pygram�
fixer_base)�token�data�fixers�myfixes�
lib2to3.fixesc@seZdZdd�Zdd�Zdd�Zdedfdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zedddfdd �Zd!d"�Zd#d$�Zefd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Z dS);�TestRefactoringToolcCstj�t�dS�N)�sys�path�append�	FIXER_DIR��self�r�8/usr/local/lib/python3.10/lib2to3/tests/test_refactor.py�setUpszTestRefactoringTool.setUpcCstj��dSr)rr
�poprrrr�tearDown"�zTestRefactoringTool.tearDowncCs2t||�D]\}}t||�s|�d||�qdS)Nz%s are not instances of %s)�zip�
isinstance�fail)rZ	instancesZclasses�inst�clsrrr�check_instances%s

��z#TestRefactoringTool.check_instancesNcCst�|||�Sr)r�RefactoringTool)r�optionsr�explicitrrr�rt*rzTestRefactoringTool.rtcC�4|�ddi�}|�d|jj�|�d|jjj�dS)N�print_functionT�print�r!�assertNotInZgrammar�keywordsZdriver�rr!rrr�test_print_function_option-�z.TestRefactoringTool.test_print_function_optioncCr")NZ
exec_functionT�execr%r(rrr�test_exec_function_option2r*z-TestRefactoringTool.test_exec_function_optioncCs2|��}|�|j�|�ddi�}|�|j�dS)N�write_unchanged_filesT)r!ZassertFalser-�
assertTruer(rrr�!test_write_unchanged_files_option7sz5TestRefactoringTool.test_write_unchanged_files_optioncCsdgd�}t�d�}t�dd�}t�d�}|�|dd�|D��|�||�|�|dd�|D��dS)N)r �firstZlastZparrotZpreorderrFcS�g|]}d|�qS)Zfix_r��.0�namerrr�
<listcomp>B�zBTestRefactoringTool.test_fixer_loading_helpers.<locals>.<listcomp>cSr1)zmyfixes.fix_rr2rrrr5Er6)rZget_all_fix_names�get_fixers_from_package�assertEqual)r�contentsZnon_prefixedZprefixedZ
full_namesrrr�test_fixer_loading_helpers=s

�z.TestRefactoringTool.test_fixer_loading_helperscCs~tj}t}|�}|�|d�|�|�|d�|d��|�|d�|d��|�|d�|d��d}|�||�|d	��d
}|�||�|d��d}|�||�|d��d
}|�||�|d	��d}|�||�|d��d}|�||�|d	��d}|D]
}|�||�|�qzd}|�||�|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)r<Zfeaturez1from __future__ import generators, print_function)r<r#z1from __future__ import print_function, generators)r#r<z(from __future__ import (print_function,)z3from __future__ import (generators, print_function)z2from __future__ import (generators, nested_scopes))r<Z
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)rZ_detect_future_features�	frozensetr8)r�run�fs�empty�inp�invalidrrr�test_detect_future_featuresGsL
�
�
�z/TestRefactoringTool.test_detect_future_featurescCs�Gdd�dtj�}Gdd�dtj�}Gdd�dtj�}|ig�}|ig�}|ig�}t�|||g�}|�tjj�}|�|||g�|�t	j
�}	|�|	||g�|��D]	}
|�|
|g�qSdS)Nc@seZdZdS)z;TestRefactoringTool.test_get_headnode_dict.<locals>.NoneFixN)�__name__�
__module__�__qualname__rrrr�NoneFixusrHc@�eZdZdZdS)z@TestRefactoringTool.test_get_headnode_dict.<locals>.FileInputFixzfile_input< any * >N�rErFrGZPATTERNrrrr�FileInputFixx�rKc@rI)z=TestRefactoringTool.test_get_headnode_dict.<locals>.SimpleFixz'name'NrJrrrr�	SimpleFix{rLrM)rZBaseFixrZ_get_headnode_dictrrZpython_symbolsZ
file_inputr8r�NAME�values)rrHrKrMZno_headZ	with_head�simple�dZ	top_fixesZ
name_fixes�fixesrrr�test_get_headnode_dictts


�z*TestRefactoringTool.test_get_headnode_dictcCshddlm}ddlm}ddlm}ddlm}|��}|�	�\}}|�
||g�|�
||||g�dS)Nr)�FixFirst)�FixLast)�	FixParrot)�FixPreorder)Zmyfixes.fix_firstrTZmyfixes.fix_lastrUZmyfixes.fix_parrotrVZmyfixes.fix_preorderrWr!Z
get_fixersr)rrTrUrVrWr!�preZpostrrr�test_fixer_loading�sz&TestRefactoringTool.test_fixer_loadingcCsD|jt|jdgd�|jtj|jdgd�|jtj|jdgd�dS)NZnot_here�rZno_fixer_clsZ	bad_order)ZassertRaises�ImportErrorr!rZ
FixerErrorrrrr�test_naughty_fixers�sz'TestRefactoringTool.test_naughty_fixerscCsL|��}d}|�|d�}|�t|�|�d}|�|d�}|�t|�|�dS)N�def parrot(): pass

�<test>zdef f(): pass

)r!Zrefactor_string�assertNotEqual�strr8)rr!�input�treerrr�test_refactor_string�sz(TestRefactoringTool.test_refactor_stringcshG�fdd�dtj�}g�|t�}tj}t�d�t_z	|��W|t_n|t_wgd�}|��|�dS)NcseZdZ�fdd�ZdS)z5TestRefactoringTool.test_refactor_stdin.<locals>.MyRTcs��||||g�dSr)�extend)rZold_textZnew_text�filenameZequal��resultsrr�print_output�szBTestRefactoringTool.test_refactor_stdin.<locals>.MyRT.print_outputN)rErFrGrhrrfrr�MyRT�srir])r]zdef cheese(): pass

z<stdin>F)	rr�_DEFAULT_FIXERSr�stdin�io�StringIOZrefactor_stdinr8)rrir!�save�expectedrrfr�test_refactor_stdin�s
z'TestRefactoringTool.test_refactor_stdinTc	Csv|�|�}|�|�}|j||d�}|r||_|�|�|�||�|��|s(dS|�|d�|�|�}|�||�|S)N)rrT)�init_test_file�	read_filer!Z	log_debug�
refactor_filer8r_)	r�	test_filerr�mock_log_debug�actually_write�old_contentsr!�new_contentsrrr�check_file_refactoring�s



z*TestRefactoringTool.check_file_refactoringcCsLtjdd�}|�tj|�t�||�tj�|tj�	|��}t�
|d�|S)N�2to3-test_refactor��prefixi�)�tempfile�mkdtempZ
addCleanup�shutil�rmtree�copy�osr
�join�basename�chmod)rrtZtmpdirrrrrq�sz"TestRefactoringTool.init_test_filecCs6t|d��}|��Wd�S1swYdS)N�rb)�open�read)rrt�fprrrrr�s$�zTestRefactoringTool.read_filecCs>|�|�}|�|�}|j|d�}|�|d�|�|�}||fS)NrZT)rqrrr!rs)rrtrrwr!rxrrrrs�s


z!TestRefactoringTool.refactor_filecCstj�td�}|�|t�dS)N�parrot_example.py)r�r
r�rryrj)rrtrrr�test_refactor_file�sz&TestRefactoringTool.test_refactor_filecs�tj�td�}g��fdd�}|j|dddi|dd�d	t�tjtj�|��}�D]}d
|vr:|�	||�dSq+|�
d|�f�dS)Nr�cs��||�dSr�r)�msg�args�Zdebug_messagesrr�recording_log_debug�szXTestRefactoringTool.test_refactor_file_write_unchanged_file.<locals>.recording_log_debugrr-TF)rrrurvzNot writing changes to .*%szNot writing changesz%r not matched in %r)r�r
r�rry�re�escape�sepr�ZassertRegexr)rrtr�Z
message_regex�messagerr�r�'test_refactor_file_write_unchanged_file�s"���z;TestRefactoringTool.test_refactor_file_write_unchanged_filecsN�fdd�}|gg�gd�}dg}|||�dtj�dd�g}|||�dS)Nc	s��fdd�}tjj}|tj_���}g�tjdd��z+t�tj�	�d��|D]}t
tj�	�|�d���q'|���W|tj_t
���n
|tj_t
���w����fdd�|D��dS)	Ncs��|�dSrr�)r�fr�)�gotrr�mock_refactor_file�rzPTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.mock_refactor_filerzr{�a_dir�wbcsg|]	}tj��|��qSr�r�r
r�)r3r
)�dirrrr5	szHTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.<listcomp>)rrrsr!r}r~r��mkdirr
r�r��closeZrefactor_dirrr�r8)Z	structureror�Z	save_funcr!�fnr)r�r�r�check�s$��z4TestRefactoringTool.test_refactor_dir.<locals>.check)Znothing�hi.pyz.dumbz	.after.pyz	notpy.npyZsappyr�r�zstuff.pyr�)rr�rbrorrr�test_refactor_dir�s

�z%TestRefactoringTool.test_refactor_dircCstj�td�}|�|�dS)Nzdifferent_encoding.py�r�r
r��
TEST_DATA_DIRry)rr�rrr�test_file_encoding�z&TestRefactoringTool.test_file_encodingcCstj�td�}|�|�}dS)Nzfalse_encoding.pyr��rr�rrrr�test_false_file_encodingr�z,TestRefactoringTool.test_false_file_encodingcCs.tj�td�}|�|�}|�|�tj��dS)Nzbom.py)	r�r
r�r�ryr.�
startswith�codecs�BOM_UTF8r�rrr�test_boms
zTestRefactoringTool.test_bomcCsFtj}dt_ztj�td�}t�d�}|�||�W|t_dS|t_w)Nz
�crlf.pyr	)r��linesepr
r�r�rr7ry)rZold_sepr�rRrrr�test_crlf_newlines$s
z&TestRefactoringTool.test_crlf_newlinescCsDtj�td�}|�|�\}}|�d|�|�d|�|�d|�dS)Nr�s
s

)r�r
r�r�rsZassertInr&)rr��old�newrrr�test_crlf_unchanged.s
z'TestRefactoringTool.test_crlf_unchangedcCsD|��}d}|�|d�}|�||�d}|�|d�}|�||�dS)Nz
>>> example()
42
r^z&
>>> def parrot():
...      return 43
)r!Zrefactor_docstringr8r_)rr!�doc�outrrr�test_refactor_docstring5sz+TestRefactoringTool.test_refactor_docstringcCsdddlm}|jdgd�}|�t|j�d�|jdgd�}|jD]
}t||�r*dSq |�d�dS)Nr)�FixExplicitzmyfixes.fix_explicitrZ)r zexplicit fixer not loaded)Zmyfixes.fix_explicitr�r!r8�lenZ
post_orderrr)rr�r!Zfixrrr�
test_explicitFs

�z!TestRefactoringTool.test_explicit)!rErFrGrrrrjr!r)r,r/r:rDrSrYr\rcrp�_2TO3_FIXERSryrqrrrsr�r�r�r�r�r�r�r�r�r�rrrrr
s@
-

� 
r
)�__doc__rr�r�rlr�r}rZunittestZlib2to3rrrZ
lib2to3.pgen2rr
r��dirname�__file__r�rrr7rjrr�ZTestCaser
rrrr�<module>s&