Your IP : 216.73.216.85


Current Path : /opt/alt/python35/lib64/python3.5/lib2to3/tests/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/lib2to3/tests/__pycache__/test_refactor.cpython-35.pyc



��YfZ.�@s`dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZmZmZddlmZddlmZejjejje�d�Zejjed	�Zejje�zejd
�ZWdejj�Xejd�ZGdd
�d
ej �Z!dS)z
Unit tests for refactor.py.
�)�with_statementN)�refactor�pygram�
fixer_base)�token�)�support�data�fixers�myfixesz
lib2to3.fixesc@s9eZdZdd�Zdd�Zdd�Zdeddd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zeddddd�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�@/opt/alt/python35/lib64/python3.5/lib2to3/tests/test_refactor.py�setUp%szTestRefactoringTool.setUpcCstjj�dS)N)r
r�pop)rrrr�tearDown(szTestRefactoringTool.tearDowncCsGx@t||�D]/\}}t||�s|jd||�qWdS)Nz%s are not instances of %s)�zip�
isinstance�fail)rZ	instances�classesZinst�clsrrr�check_instances+sz#TestRefactoringTool.check_instancesNcCstj|||�S)N)r�RefactoringTool)r�optionsr
�explicitrrr�rt0szTestRefactoringTool.rtcCsH|jddi�}|j|jtj�|j|jjtj�dS)N�print_functionT)r ZassertIsZgrammarrZ!python_grammar_no_print_statementZdriver)rr rrr�test_print_function_option3sz.TestRefactoringTool.test_print_function_optioncCsE|j�}|j|j�|jddi�}|j|j�dS)N�write_unchanged_filesT)r ZassertFalser#�
assertTrue)rr rrr�!test_write_unchanged_files_option9sz5TestRefactoringTool.test_write_unchanged_files_optioncCs�dddddg}tjd�}tjdd�}tjd�}|j|dd	�|D��|j||�|j|d
d	�|D��dS)Nr�firstZlastZparrotZpreorderrFcSsg|]}d|�qS)Zfix_r)�.0�namerrr�
<listcomp>Ds	zBTestRefactoringTool.test_fixer_loading_helpers.<locals>.<listcomp>cSsg|]}d|�qS)zmyfixes.fix_r)r'r(rrrr)Gs	)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_helperscCstj}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_functionr!z!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/r0)r/r!)r!r/)r!)r/r!)r/r1)r/r!)r2r3r4r5r6r7r8)r!)r!)r!)rZ_detect_future_features�	frozensetr+)rZrunZfs�emptyZinpZinvalidrrr�test_detect_future_featuresIsR		



z/TestRefactoringTool.test_detect_future_featurescCsGdd�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@seZdZdS)z;TestRefactoringTool.test_get_headnode_dict.<locals>.NoneFixN)�__name__�
__module__�__qualname__rrrr�NoneFixwsr?c@seZdZdZdS)z@TestRefactoringTool.test_get_headnode_dict.<locals>.FileInputFixzfile_input< any * >N)r<r=r>�PATTERNrrrr�FileInputFixzsrAc@seZdZdZdS)z=TestRefactoringTool.test_get_headnode_dict.<locals>.SimpleFixz'name'N)r<r=r>r@rrrr�	SimpleFix}srB)rZBaseFixrZ_get_headnode_dictrrZpython_symbolsZ
file_inputr+r�NAME�values)rr?rArBZno_headZ	with_headZsimple�dZ	top_fixesZ
name_fixes�fixesrrr�test_get_headnode_dictvsz*TestRefactoringTool.test_get_headnode_dictcCs�ddlm}ddlm}ddlm}ddlm}|j�}|j	�\}}|j
||g�|j
||||g�dS)Nr)�FixFirst)�FixLast)�	FixParrot)�FixPreorder)Zmyfixes.fix_firstrHZmyfixes.fix_lastrIZmyfixes.fix_parrotrJZmyfixes.fix_preorderrKr Z
get_fixersr)rrHrIrJrKr ZpreZpostrrr�test_fixer_loading�sz&TestRefactoringTool.test_fixer_loadingcCs^|jt|jddg�|jtj|jddg�|jtj|jddg�dS)Nr
Znot_hereZno_fixer_clsZ	bad_order)ZassertRaises�ImportErrorr rZ
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

)r Zrefactor_string�assertNotEqual�strr+)rr �input�treerrr�test_refactor_string�sz(TestRefactoringTool.test_refactor_stringcs�G�fdd�dtj�}g�|t�}tj}tjd�t_z|j�Wd|t_Xddddg}|j�|�dS)Ncs"eZdZ�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)r<r=r>rWr)rVrr�MyRT�srXzdef parrot(): pass

zdef cheese(): pass

z<stdin>F)	rr�_DEFAULT_FIXERSr
�stdin�io�StringIOZrefactor_stdinr+)rrXr Zsave�expectedr)rVr�test_refactor_stdin�s	
z'TestRefactoringTool.test_refactor_stdinTcs�tjdd�}|jtj|�tj�|�tjj|tjj	����tj
�d��fdd�}|�}|jd|d|�}	|r�||	_|	j
��|j||��|s�dS|	j
�d�|�}
|j||
�|
S)	N�prefixz2to3-test_refactori�c	s't�d��}|j�SWdQRXdS)N�rb)�open�read)�fp)�	test_filerr�	read_file�sz=TestRefactoringTool.check_file_refactoring.<locals>.read_filer
rT)�tempfile�mkdtempZ
addCleanup�shutil�rmtree�copy�osr�join�basename�chmodr Z	log_debug�
refactor_filer+rO)rrdr
r�mock_log_debug�actually_writeZtmpdirreZold_contentsr Znew_contentsr)rdr�check_file_refactoring�s$!		
	z*TestRefactoringTool.check_file_refactoringcCs)tjjtd�}|j|t�dS)Nzparrot_example.py)rkrrlrrrrY)rrdrrr�test_refactor_file�sz&TestRefactoringTool.test_refactor_filec
s�tjjtd�}g��fdd�}|j|dfdddid|d	d
�dtjtjtjj|��}xB�D]#}d|kr�|j	||�Pq�W|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
rr#TrprqFzNot writing changes to .*%szNot writing changesz%r not matched in %r)rkrrlrrr�re�escape�seprmZassertRegexr)rrdrwZ
message_regex�messager)rvr�'test_refactor_file_write_unchanged_file�s#
z;TestRefactoringTool.test_refactor_file_write_unchanged_filecsy�fdd�}|gg�ddddddg}dg}|||�dtjjd	d
�g}|||�dS)Nc
s��fdd�}tjj}|tj_�j�}g�tjdd��z`tjtjj	�d��x0|D](}t
tjj	�|�d�j�qtW|j��Wd|tj_t
j��X�j��fdd�|D��dS)	Ncs�j|�dS)N)r)r�fru)�gotrr�mock_refactor_file�szPTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.mock_refactor_filer_z2to3-test_refactor�a_dir�wbcs%g|]}tjj�|��qSr)rkrrl)r'r)�dirrrr)s	zHTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.<listcomp>)rrror rfrgrk�mkdirrrlra�closeZrefactor_dirrhrir+)Z	structurer]rZ	save_funcr �fn)r)r�r~r�check�s
&	z4TestRefactoringTool.test_refactor_dir.<locals>.checkZnothingzhi.pyz.dumbz	.after.pyz	notpy.npyZsappyr�zstuff.py)rkrrl)rr�rRr]r)rr�test_refactor_dir�s
		
z%TestRefactoringTool.test_refactor_dircCs&tjjtd�}|j|�dS)Nzdifferent_encoding.py)rkrrl�
TEST_DATA_DIRrr)rr�rrr�test_file_encodingsz&TestRefactoringTool.test_file_encodingcCs(tjjtd�}|j|�}dS)Nzfalse_encoding.py)rkrrlr�rr)rr�r	rrr�test_false_file_encodingsz,TestRefactoringTool.test_false_file_encodingcCsAtjjtd�}|j|�}|j|jtj��dS)Nzbom.py)	rkrrlr�rrr$�
startswith�codecs�BOM_UTF8)rr�r	rrr�test_bomszTestRefactoringTool.test_bomcCs[tj}dt_z8tjjtd�}tjd�}|j||�Wd|t_XdS)Nz
zcrlf.pyz
lib2to3.fixes)rk�lineseprrlr�rr*rr)rZold_sepr�rFrrr�test_crlf_newliness		z&TestRefactoringTool.test_crlf_newlinescCs`|j�}d}|j|d�}|j||�d}|j|d�}|j||�dS)Nz
>>> example()
42
z<test>z&
>>> def parrot():
...      return 43
)r Zrefactor_docstringr+rO)rr �doc�outrrr�test_refactor_docstring&sz+TestRefactoringTool.test_refactor_docstringcCs�ddlm}|jddg�}|jt|j�d�|jddg�}x.|jD]}t||�r]Pq]W|jd�dS)Nr)�FixExplicitr
zmyfixes.fix_explicitrzexplicit fixer not loaded)Zmyfixes.fix_explicitr�r r+�lenZ
post_orderrr)rr�r Zfixrrr�
test_explicit7sz!TestRefactoringTool.test_explicit)r<r=r>rrrrYr r"r%r-r;rGrLrNrSr^�_2TO3_FIXERSrrrsr|r�r�r�r�r�r�r�rrrrr#s2
-
 
r)"�__doc__Z
__future__rr
rkr��operatorr[rxrfrhZunittest�warningsZlib2to3rrrZ
lib2to3.pgen2rr.rrrl�dirname�__file__r�rrr*rYrr�ZTestCaserrrrr�<module>s,!