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.7/lib2to3/tests/__pycache__/test_refactor.cpython-37.opt-2.pyc
B

 ��g�0�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZddlm
Z
ej�ej�e�d�Zej�ed�Zej�e�ze	�d�ZWdej��Xe	�d�ZGdd	�d	ej�ZdS)
�N)�refactor�pygram�
fixer_base)�token�data�fixers�myfixesz
lib2to3.fixesc@s�eZdZdd�Zdd�Zdd�Zdedfdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zedddfdd�Zdd �Zd!d"�Zefd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�ZdS)9�TestRefactoringToolcCstj�t�dS)N)�sys�path�append�	FIXER_DIR)�self�r�7/usr/local/lib/python3.7/lib2to3/tests/test_refactor.py�setUpszTestRefactoringTool.setUpcCstj��dS)N)r
r�pop)rrrr�tearDown"szTestRefactoringTool.tearDowncCs6x0t||�D]"\}}t||�s|�d||�qWdS)Nz%s are not instances of %s)�zip�
isinstance�fail)rZ	instances�classes�inst�clsrrr�check_instances%s
z#TestRefactoringTool.check_instancesNcCst�|||�S)N)r�RefactoringTool)r�optionsr�explicitrrr�rt*szTestRefactoringTool.rtcCs4|�ddi�}|�|jtj�|�|jjtj�dS)N�print_functionT)rZassertIsZgrammarrZ!python_grammar_no_print_statementZdriver)rrrrr�test_print_function_option-s
z.TestRefactoringTool.test_print_function_optioncCs2|��}|�|j�|�ddi�}|�|j�dS)N�write_unchanged_filesT)rZassertFalser!�
assertTrue)rrrrr�!test_write_unchanged_files_option3sz5TestRefactoringTool.test_write_unchanged_files_optioncCsjdddddg}t�d�}t�dd�}t�d�}|�|dd	�|D��|�||�|�|d
d	�|D��dS)Nr�firstZlastZparrotZpreorderrFcSsg|]}d|�qS)Zfix_r)�.0�namerrr�
<listcomp>>szBTestRefactoringTool.test_fixer_loading_helpers.<locals>.<listcomp>cSsg|]}d|�qS)zmyfixes.fix_r)r%r&rrrr'As)rZget_all_fix_names�get_fixers_from_package�assertEqual)r�contentsZnon_prefixedZprefixedZ
full_namesrrr�test_fixer_loading_helpers9s

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}x|D]}|�||�|�q�Wd}|�||�|d��d}|�||�|�d}|�||�|d��d}|�||�|d��d}|�||�|�dS)N�z%from __future__ import print_function)rz!from __future__ import generators)�
generatorsz*from __future__ import generators, feature)r-Zfeaturez1from __future__ import generators, print_function)r-rz1from __future__ import print_function, generators)rr-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�	frozensetr))r�runZfs�emptyZinpZinvalidrrr�test_detect_future_featuresCsF






z/TestRefactoringTool.test_detect_future_featurescCs�Gdd�dtj�}Gdd�dtj�}Gdd�dtj�}|ig�}|ig�}|ig�}t�|||g�}|�tjj�}|�|||g�|�t	j
�}	|�|	||g�x|��D]}
|�|
|g�q�WdS)Nc@seZdZdS)z;TestRefactoringTool.test_get_headnode_dict.<locals>.NoneFixN)�__name__�
__module__�__qualname__rrrr�NoneFixqsr6c@seZdZdZdS)z@TestRefactoringTool.test_get_headnode_dict.<locals>.FileInputFixzfile_input< any * >N)r3r4r5�PATTERNrrrr�FileInputFixtsr8c@seZdZdZdS)z=TestRefactoringTool.test_get_headnode_dict.<locals>.SimpleFixz'name'N)r3r4r5r7rrrr�	SimpleFixwsr9)rZBaseFixrZ_get_headnode_dictrrZpython_symbolsZ
file_inputr)r�NAME�values)rr6r8r9Zno_headZ	with_headZsimple�dZ	top_fixesZ
name_fixes�fixesrrr�test_get_headnode_dictps


z*TestRefactoringTool.test_get_headnode_dictcCshddlm}ddlm}ddlm}ddlm}|��}|�	�\}}|�
||g�|�
||||g�dS)Nr)�FixFirst)�FixLast)�	FixParrot)�FixPreorder)Zmyfixes.fix_firstr?Zmyfixes.fix_lastr@Zmyfixes.fix_parrotrAZmyfixes.fix_preorderrBrZ
get_fixersr)rr?r@rArBrZpreZpostrrr�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�ImportErrorrrZ
FixerError)rrrr�test_naughty_fixers�sz'TestRefactoringTool.test_naughty_fixerscCsL|��}d}|�|d�}|�t|�|�d}|�|d�}|�t|�|�dS)Nzdef parrot(): pass

z<test>zdef f(): pass

)rZrefactor_string�assertNotEqual�strr))rr�input�treerrr�test_refactor_string�sz(TestRefactoringTool.test_refactor_stringcsfG�fdd�dtj�}g�|t�}tj}t�d�t_z|��Wd|t_Xddddg}|��|�dS)NcseZdZ�fdd�ZdS)z5TestRefactoringTool.test_refactor_stdin.<locals>.MyRTcs��||||g�dS)N)�extend)rZold_textZnew_text�filenameZequal)�resultsrr�print_output�szBTestRefactoringTool.test_refactor_stdin.<locals>.MyRT.print_outputN)r3r4r5rNr)rMrr�MyRT�srOzdef parrot(): pass

zdef cheese(): pass

z<stdin>F)	rr�_DEFAULT_FIXERSr
�stdin�io�StringIOZrefactor_stdinr))rrOrZsave�expectedr)rMr�test_refactor_stdin�sz'TestRefactoringTool.test_refactor_stdinTc	Csv|�|�}|�|�}|j||d�}|r,||_|�|�|�||�|��|sPdS|�|d�|�|�}|�||�|S)N)rrT)�init_test_file�	read_filerZ	log_debug�
refactor_filer)rF)	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)Nz2to3-test_refactor)�prefixi�)�tempfile�mkdtempZ
addCleanup�shutil�rmtree�copy�osr�join�basename�chmod)rrYZtmpdirrrrrV�sz"TestRefactoringTool.init_test_filec	Cst|d��
}|��SQRXdS)N�rb)�open�read)rrY�fprrrrW�szTestRefactoringTool.read_filecCs>|�|�}|�|�}|j|d�}|�|d�|�|�}||fS)N)rT)rVrWrrX)rrYrr\rr]rrrrX�s


z!TestRefactoringTool.refactor_filecCstj�td�}|�|t�dS)Nzparrot_example.py)rerrfr
r^rP)rrYrrr�test_refactor_file�sz&TestRefactoringTool.test_refactor_filecs�tj�td�}g��fdd�}|j|dddi|dd�d	t�tjtj�|��}x4�D]}d
|krX|�	||�PqXW|�
d|�f�dS)Nzparrot_example.pycs��||�dS)N)r)�msg�args)�debug_messagesrr�recording_log_debug�szXTestRefactoringTool.test_refactor_file_write_unchanged_file.<locals>.recording_log_debugrr!TF)rrrZr[zNot writing changes to .*%szNot writing changesz%r not matched in %r)rerrfr
r^�re�escape�seprgZassertRegexr)rrYrqZ
message_regex�messager)rpr�'test_refactor_file_write_unchanged_file�s
z;TestRefactoringTool.test_refactor_file_write_unchanged_filecsV�fdd�}|gg�ddddddg}dg}|||�dtj�d	d
�g}|||�dS)Nc	s��fdd�}tjj}|tj_���}g�tjdd��zHt�tj�	�d��x$|D]}t
tj�	�|�d���qPW|���Wd|tj_t
���X����fdd�|D��dS)	Ncs��|�dS)N)r)r�fro)�gotrr�mock_refactor_file�szPTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.mock_refactor_filez2to3-test_refactor)r_�a_dir�wbcsg|]}tj��|��qSr)rerrf)r%r)�dirrrr'szHTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.<listcomp>)rrrXrr`rare�mkdirrrfrj�closeZrefactor_dirrbrcr))Z	structurerTryZ	save_funcr�fn)r)r|rxr�check�s
z4TestRefactoringTool.test_refactor_dir.<locals>.checkZnothingzhi.pyz.dumbz	.after.pyz	notpy.npyZsappyrzzstuff.py)rerrf)rr�rIrTr)rr�test_refactor_dir�s

z%TestRefactoringTool.test_refactor_dircCstj�td�}|�|�dS)Nzdifferent_encoding.py)rerrf�
TEST_DATA_DIRr^)rrrrr�test_file_encodingsz&TestRefactoringTool.test_file_encodingcCstj�td�}|�|�}dS)Nzfalse_encoding.py)rerrfr�r^)rrrrrr�test_false_file_encodingsz,TestRefactoringTool.test_false_file_encodingcCs.tj�td�}|�|�}|�|�tj��dS)Nzbom.py)	rerrfr�r^r"�
startswith�codecs�BOM_UTF8)rrrrrr�test_boms
zTestRefactoringTool.test_bomcCsBtj}dt_z(tj�td�}t�d�}|�||�Wd|t_XdS)Nz
zcrlf.pyz
lib2to3.fixes)re�lineseprrfr�rr(r^)rZold_seprr=rrr�test_crlf_newlines s
z&TestRefactoringTool.test_crlf_newlinescCsDtj�td�}|�|�\}}|�d|�|�d|�|�d|�dS)Nzcrlf.pys
s

)rerrfr�rXZassertInZassertNotIn)rr�old�newrrr�test_crlf_unchanged*s
z'TestRefactoringTool.test_crlf_unchangedcCsD|��}d}|�|d�}|�||�d}|�|d�}|�||�dS)Nz
>>> example()
42
z<test>z&
>>> def parrot():
...      return 43
)rZrefactor_docstringr)rF)rr�doc�outrrr�test_refactor_docstring1sz+TestRefactoringTool.test_refactor_docstringcCsdddlm}|jdgd�}|�t|j�d�|jdgd�}x$|jD]}t||�rBPqBW|�d�dS)Nr)�FixExplicitzmyfixes.fix_explicit)r)rzexplicit fixer not loaded)Zmyfixes.fix_explicitr�rr)�lenZ
post_orderrr)rr�rZfixrrr�
test_explicitBs
z!TestRefactoringTool.test_explicit) r3r4r5rrrrPrr r#r+r2r>rCrErJrU�_2TO3_FIXERSr^rVrWrXrmrvr�r�r�r�r�r�r�r�rrrrr	s:
-
 
r	)r
rer�rRrrr`rbZunittestZlib2to3rrrZ
lib2to3.pgen2rrrf�dirname�__file__r�r
rr(rPrr�ZTestCaser	rrrr�<module>s"