Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/lib2to3/tests/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/lib2to3/tests/__pycache__/test_refactor.cpython-38.pyc
U

?��g�0�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZddl
mZej�ej�e�d�Zej�ed�Zej�e�ze
�d�ZW5ej��Xe
�d�ZGd	d
�d
ej�ZdS)z
Unit tests for refactor.py.
�N)�refactor�pygram�
fixer_base)�token�data�fixers�myfixes�
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�:/opt/cppython/lib/python3.8/lib2to3/tests/test_refactor.py�setUpszTestRefactoringTool.setUpcCstj��dSr)rr
�poprrrr�tearDown"szTestRefactoringTool.tearDowncCs2t||�D]"\}}t||�s
|�d||�q
dS)Nz%s are not instances of %s)�zip�
isinstance�fail)rZ	instances�classes�inst�clsrrr�check_instances%s
z#TestRefactoringTool.check_instancesNcCst�|||�Sr)r�RefactoringTool)r�optionsr�explicitrrr�rt*szTestRefactoringTool.rtcCs4|�ddi�}|�|jtj�|�|jjtj�dS)N�print_functionT)r!ZassertIsZgrammarrZ!python_grammar_no_print_statementZdriver�rr!rrr�test_print_function_option-s

�z.TestRefactoringTool.test_print_function_optioncCs2|��}|�|j�|�ddi�}|�|j�dS)N�write_unchanged_filesT)r!ZassertFalser%�
assertTruer#rrr�!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_rr)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}|D]}|�||�|�q�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)r2Zfeaturez1from __future__ import generators, print_function)r2r"z1from __future__ import print_function, generators)r"r2z(from __future__ import (print_function,)z3from __future__ import (generators, print_function)z2from __future__ import (generators, nested_scopes))r2Z
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�run�fs�emptyZinp�invalidrrr�test_detect_future_featuresCsL
�
�
�z/TestRefactoringTool.test_detect_future_featurescCs�Gdd�dtj�}Gdd�dtj�}Gdd�dtj�}|ig�}|ig�}|ig�}t�|||g�}|�tjj�}|�|||g�|�t	j
�}	|�|	||g�|��D]}
|�|
|g�q�dS)Nc@seZdZdS)z;TestRefactoringTool.test_get_headnode_dict.<locals>.NoneFixN)�__name__�
__module__�__qualname__rrrr�NoneFixqsr=c@seZdZdZdS)z@TestRefactoringTool.test_get_headnode_dict.<locals>.FileInputFixzfile_input< any * >N�r:r;r<ZPATTERNrrrr�FileInputFixtsr?c@seZdZdZdS)z=TestRefactoringTool.test_get_headnode_dict.<locals>.SimpleFixz'name'Nr>rrrr�	SimpleFixwsr@)rZBaseFixrZ_get_headnode_dictrrZpython_symbolsZ
file_inputr.r�NAME�values)rr=r?r@Zno_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_firstrFZmyfixes.fix_lastrGZmyfixes.fix_parrotrHZmyfixes.fix_preorderrIr!Z
get_fixersr)rrFrGrHrIr!�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�strr.)rr!�input�treerrr�test_refactor_string�sz(TestRefactoringTool.test_refactor_stringcsfG�fdd�dtj�}g�|t�}tj}t�d�t_z|��W5|t_Xddddg}|��|�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)r:r;r<rZrrXrr�MyRT�sr[rOzdef cheese(): pass

z<stdin>F)	rr�_DEFAULT_FIXERSr�stdin�io�StringIOZrefactor_stdinr.)rr[r!�save�expectedrrXr�test_refactor_stdin�s�z'TestRefactoringTool.test_refactor_stdinTc	Csv|�|�}|�|�}|j||d�}|r,||_|�|�|�||�|��|sPdS|�|d�|�|�}|�||�|S)N)rrT)�init_test_file�	read_filer!Z	log_debug�
refactor_filer.rQ)	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)rrfZtmpdirrrrrc�sz"TestRefactoringTool.init_test_filec
Cs*t|d��}|��W5QR�SQRXdS)N�rb)�open�read)rrf�fprrrrd�szTestRefactoringTool.read_filecCs>|�|�}|�|�}|j|d�}|�|d�|�|�}||fS)NrLT)rcrdr!re)rrfrrir!rjrrrre�s


z!TestRefactoringTool.refactor_filecCstj�td�}|�|t�dS)N�parrot_example.py)rtr
rurrkr\)rrfrrr�test_refactor_file�sz&TestRefactoringTool.test_refactor_filecs�tj�td�}g��fdd�}|j|dddi|dd�d	t�tjtj�|��}�D]}d
|krV|�	||�q�qV|�
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)rrrgrhzNot writing changes to .*%szNot writing changesz%r not matched in %r)rtr
rurrk�re�escape�seprvZassertRegexr)rrfr�Z
message_regex�messagerr�r�'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��zDt�	tj
��d��|D]}ttj
��|�d��
�qN|���W5|tj_t���X����fdd�|D��dS)	Ncs��|�dSrr~)r�fr�)�gotrr�mock_refactor_file�szPTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.mock_refactor_filerlrm�a_dir�wbcsg|]}tj��|��qSr�rtr
ru)r*r
)�dirrrr,szHTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.<listcomp>)rrrer!rorprqrrrt�mkdirr
rury�closeZrefactor_dirr.)Z	structurerar�Z	save_funcr!�fnr)r�r�r�check�s �z4TestRefactoringTool.test_refactor_dir.<locals>.checkZnothingzhi.pyz.dumbz	.after.pyz	notpy.npyZsappyr�zstuff.pyr�)rr�rTrarrr�test_refactor_dir�s
�
�z%TestRefactoringTool.test_refactor_dircCstj�td�}|�|�dS)Nzdifferent_encoding.py�rtr
ru�
TEST_DATA_DIRrk)rr�rrr�test_file_encodingsz&TestRefactoringTool.test_file_encodingcCstj�td�}|�|�}dS)Nzfalse_encoding.pyr��rr�rrrr�test_false_file_encodingsz,TestRefactoringTool.test_false_file_encodingcCs.tj�td�}|�|�}|�|�tj��dS)Nzbom.py)	rtr
rur�rkr&�
startswith�codecs�BOM_UTF8r�rrr�test_boms
zTestRefactoringTool.test_bomcCsBtj}dt_z(tj�td�}t�d�}|�||�W5|t_XdS)Nz
�crlf.pyr	)rt�linesepr
rur�rr-rk)rZold_sepr�rDrrr�test_crlf_newlines s
z&TestRefactoringTool.test_crlf_newlinescCsDtj�td�}|�|�\}}|�d|�|�d|�|�d|�dS)Nr�s
s

)rtr
rur�reZassertInZassertNotIn)rr��old�newrrr�test_crlf_unchanged*s
z'TestRefactoringTool.test_crlf_unchangedcCsD|��}d}|�|d�}|�||�d}|�|d�}|�||�dS)Nz
>>> example()
42
rPz&
>>> def parrot():
...      return 43
)r!Zrefactor_docstringr.rQ)rr!�doc�outrrr�test_refactor_docstring1sz+TestRefactoringTool.test_refactor_docstringcCsbddlm}|jdgd�}|�t|j�d�|jdgd�}|jD]}t||�r@q^q@|�d�dS)Nr)�FixExplicitzmyfixes.fix_explicitrL)r zexplicit fixer not loaded)Zmyfixes.fix_explicitr�r!r.�lenZ
post_orderrr)rr�r!Zfixrrr�
test_explicitBs

z!TestRefactoringTool.test_explicit) r:r;r<rrrr\r!r$r'r0r9rErKrNrUrb�_2TO3_FIXERSrkrcrdrer}r�r�r�r�r�r�r�r�r�rrrrr
s>
-
�
 
r
)�__doc__rrtr�r^r�rorqZunittestZlib2to3rrrZ
lib2to3.pgen2rr
ru�dirname�__file__r�rrrr-r\r�ZTestCaser
rrrr�<module>s$


F1le Man4ger