Your IP : 216.73.216.213


Current Path : /opt/alt/python36/lib64/python3.6/lib2to3/tests/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/lib2to3/tests/__pycache__/test_refactor.cpython-36.opt-2.pyc

3

��2a�-�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZddlm
Z
ejjejje�d�Zejjed�Zejje�ze	jd�ZWdejj�Xe	jd�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"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�ZdS)1�TestRefactoringToolcCstjjt�dS)N)�sys�path�append�	FIXER_DIR)�self�r�2/opt/alt/python36/lib64/python3.6/test_refactor.py�setUpszTestRefactoringTool.setUpcCstjj�dS)N)r
r�pop)rrrr�tearDown"szTestRefactoringTool.tearDowncCs6x0t||�D]"\}}t||�s|jd||�qWdS)Nz%s are not instances of %s)�zip�
isinstance�fail)rZ	instances�classesZinst�clsrrr�check_instances%s
z#TestRefactoringTool.check_instancesNcCstj|||�S)N)r�RefactoringTool)r�optionsr�explicitrrr�rt*szTestRefactoringTool.rtcCs4|jddi�}|j|jtj�|j|jjtj�dS)N�print_functionT)rZassertIsZgrammarrZ!python_grammar_no_print_statementZdriver)rrrrr�test_print_function_option-s
z.TestRefactoringTool.test_print_function_optioncCs2|j�}|j|j�|jddi�}|j|j�dS)N�write_unchanged_filesT)rZassertFalser �
assertTrue)rrrrr�!test_write_unchanged_files_option3sz5TestRefactoringTool.test_write_unchanged_files_optioncCsjdddddg}tjd�}tjdd�}tjd�}|j|dd	�|D��|j||�|j|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}|�}|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$}x|D]}|j||�|��q�Wd}|j||�|d%��d}|j||�|�d}|j||�|d&��d}|j||�|d'��d}|j||�|�dS)(N�z%from __future__ import print_functionrz!from __future__ import generators�
generatorsz*from __future__ import generators, feature�featurez1from __future__ import generators, print_functionz1from __future__ import print_function, generatorsz(from __future__ import (print_function,)z3from __future__ import (generators, print_function)z2from __future__ import (generators, nested_scopes)�
nested_scopeszGfrom __future__ import generators
from __future__ import print_function�from�from 4�from x�from x 5�	from x im�
from x import�from 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)r,)r,r-)r,r)rr,)r)r,r)r,r.)r,r)r/r0r1r2r3r4r5)r)r)r)rZ_detect_future_features�	frozensetr()rZrunZfs�emptyZinpZinvalidrrr�test_detect_future_featuresCsR






z/TestRefactoringTool.test_detect_future_featurescCs�Gdd�dtj�}Gdd�dtj�}Gdd�dtj�}|ig�}|ig�}|ig�}tj|||g�}|jtjj�}|j|||g�|jt	j
�}	|j|	||g�x|j�D]}
|j|
|g�q�WdS)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)r9r:r;�PATTERNrrrr�FileInputFixtsr>c@seZdZdZdS)z=TestRefactoringTool.test_get_headnode_dict.<locals>.SimpleFixz'name'N)r9r:r;r=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}|j�}|j	�\}}|j
||g�|j
||||g�dS)Nr)�FixFirst)�FixLast)�	FixParrot)�FixPreorder)Zmyfixes.fix_firstrEZmyfixes.fix_lastrFZmyfixes.fix_parrotrGZmyfixes.fix_preorderrHrZ
get_fixersr)rrErFrGrHrZpreZpostrrr�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|j�}d}|j|d�}|jt|�|�d}|j|d�}|jt|�|�dS)Nzdef parrot(): pass

z<test>zdef f(): pass

)rZrefactor_string�assertNotEqual�strr()rr�input�treerrr�test_refactor_string�sz(TestRefactoringTool.test_refactor_stringcsfG�fdd�dtj�}g�|t�}tj}tjd�t_z|j�Wd|t_Xddddg}|j�|�dS)NcseZdZ�fdd�ZdS)z5TestRefactoringTool.test_refactor_stdin.<locals>.MyRTcs�j||||g�dS)N)�extend)rZold_textZnew_text�filenameZequal)�resultsrr�print_output�szBTestRefactoringTool.test_refactor_stdin.<locals>.MyRT.print_outputN)r9r:r;rTr)rSrr�MyRT�srUzdef parrot(): pass

zdef cheese(): pass

z<stdin>F)	rr�_DEFAULT_FIXERSr
�stdin�io�StringIOZrefactor_stdinr()rrUrZsave�expectedr)rSr�test_refactor_stdin�sz'TestRefactoringTool.test_refactor_stdinTcs�tjdd�}|jtj|�tj�|�tjj|tjj	����tj
�d��fdd�}|�}|j||d�}	|rr||	_|	j
��|j||��|s�dS|	j
�d�|�}
|j||
�|
S)Nz2to3-test_refactor)�prefixi�c	st�d��
}|j�SQRXdS)N�rb)�open�read)�fp)�	test_filerr�	read_file�sz=TestRefactoringTool.check_file_refactoring.<locals>.read_file)rrT)�tempfile�mkdtempZ
addCleanup�shutil�rmtree�copy�osr�join�basename�chmodrZ	log_debug�
refactor_filer(rL)rrarr�mock_log_debug�actually_writeZtmpdirrbZold_contentsrZnew_contentsr)rar�check_file_refactoring�s$
z*TestRefactoringTool.check_file_refactoringcCstjjtd�}|j|t�dS)Nzparrot_example.py)rhrrir
rorV)rrarrr�test_refactor_file�sz&TestRefactoringTool.test_refactor_filecs�tjjtd�}g��fdd�}|j|fddi|dd�dtjtjtjj|��}x4�D]}d	|krX|j	||�PqXW|j
d
|�f�dS)Nzparrot_example.pycs�j||�dS)N)r)�msg�args)�debug_messagesrr�recording_log_debug�szXTestRefactoringTool.test_refactor_file_write_unchanged_file.<locals>.recording_log_debugr TF)rrrmrnzNot writing changes to .*%szNot writing changesz%r not matched in %r)rhrrir
ro�re�escape�seprjZassertRegexr)rrartZ
message_regex�messager)rsr�'test_refactor_file_write_unchanged_file�s
z;TestRefactoringTool.test_refactor_file_write_unchanged_filecsV�fdd�}|gg�ddddddg}dg}|||�dtjjd	d
�g}|||�dS)Nc
s��fdd�}tjj}|tj_�j�}g�tjdd��zHtjtjj	�d��x$|D]}t
tjj	�|�d�j�qPW|j��Wd|tj_t
j��X�j��fdd�|D��dS)	Ncs�j|�dS)N)r)r�frr)�gotrr�mock_refactor_file�szPTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.mock_refactor_filez2to3-test_refactor)r\�a_dir�wbcsg|]}tjj�|��qSr)rhrri)r$r)�dirrrr&�szHTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.<listcomp>)rrrlrrcrdrh�mkdirrrir^�closeZrefactor_dirrerfr()Z	structurerZr|Z	save_funcr�fn)r)rr{r�check�s
z4TestRefactoringTool.test_refactor_dir.<locals>.checkZnothingzhi.pyz.dumbz	.after.pyz	notpy.npyZsappyr}zstuff.py)rhrri)rr�rOrZr)rr�test_refactor_dir�s

z%TestRefactoringTool.test_refactor_dircCstjjtd�}|j|�dS)Nzdifferent_encoding.py)rhrri�
TEST_DATA_DIRro)rr�rrr�test_file_encoding	sz&TestRefactoringTool.test_file_encodingcCstjjtd�}|j|�}dS)Nzfalse_encoding.py)rhrrir�ro)rr�rrrr�test_false_file_encoding
sz,TestRefactoringTool.test_false_file_encodingcCs.tjjtd�}|j|�}|j|jtj��dS)Nzbom.py)	rhrrir�ror!�
startswith�codecs�BOM_UTF8)rr�rrrr�test_boms
zTestRefactoringTool.test_bomcCsBtj}dt_z(tjjtd�}tjd�}|j||�Wd|t_XdS)Nz
zcrlf.pyz
lib2to3.fixes)rh�lineseprrir�rr'ro)rZold_sepr�rCrrr�test_crlf_newliness
z&TestRefactoringTool.test_crlf_newlinescCsD|j�}d}|j|d�}|j||�d}|j|d�}|j||�dS)Nz
>>> example()
42
z<test>z&
>>> def parrot():
...      return 43
)rZrefactor_docstringr(rL)rr�doc�outrrr�test_refactor_docstring sz+TestRefactoringTool.test_refactor_docstringcCsdddlm}|jdgd�}|jt|j�d�|jdgd�}x$|jD]}t||�rBPqBW|jd�dS)Nr)�FixExplicitzmyfixes.fix_explicit)r)rzexplicit fixer not loaded)Zmyfixes.fix_explicitr�rr(�lenZ
post_orderrr)rr�rZfixrrr�
test_explicit1s
z!TestRefactoringTool.test_explicit)r9r:r;rrrrVrrr"r*r8rDrIrKrPr[�_2TO3_FIXERSrorpryr�r�r�r�r�r�r�rrrrr	s2
-
 
r	)r
rhr�rXrurcreZunittestZlib2to3rrrZ
lib2to3.pgen2rrri�dirname�__file__r�r
rr'rVrr�ZTestCaser	rrrr�<module>s"