Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/lib2to3/tests/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/lib2to3/tests/__pycache__/test_refactor.cpython-34.pyc

�
j fG.�@sTdZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
mZmZddlmZddlmZejjejje�d�Zejjed	�Zejje�ze
jd
�ZWdejj�Xe
jd�ZGdd
�d
e
j�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/python34/lib64/python3.4/lib2to3/tests/test_refactor.py�setUp$szTestRefactoringTool.setUpcCstjj�dS)N)r
r�pop)rrrr�tearDown'szTestRefactoringTool.tearDowncCsJxCt||�D]2\}}t||�s|jd||�qqWdS)Nz%s are not instances of %s)�zip�
isinstance�fail)rZ	instancesZclassesZinst�clsrrr�check_instances*sz#TestRefactoringTool.check_instancesNcCstj|||�S)N)r�RefactoringTool)r�optionsr
�explicitrrr�rt/szTestRefactoringTool.rtcCsI|jidd6�}|j|jtj�|j|jjtj�dS)NT�print_function)rZassertIsZgrammarrZ!python_grammar_no_print_statementZdriver)rrrrr�test_print_function_option2sz.TestRefactoringTool.test_print_function_optioncCsF|j�}|j|j�|jidd6�}|j|j�dS)NT�write_unchanged_files)rZassertFalser"�
assertTrue)rrrrr�!test_write_unchanged_files_option8sz5TestRefactoringTool.test_write_unchanged_files_optioncCs�dddddg}tjd�}tjdd�}tjd�}|j|dd	�|D��|j||�|j|d
d	�|D��dS)Nr�first�lastZparrotZpreorderrFcSsg|]}d|�qS)Zfix_r)�.0�namerrr�
<listcomp>Cs	zBTestRefactoringTool.test_fixer_loading_helpers.<locals>.<listcomp>cSsg|]}d|�qS)zmyfixes.fix_r)r'r(rrrr)Fs	)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)�print_function)r/)r/r0)r/r9)r9r/)r9)r/r9)r/r1)r/r9)zfromr3r4r5r6r7r8)r9)r9)r9)rZ_detect_future_features�	frozensetr+)rZrunZfs�emptyZinpZinvalidrrr�test_detect_future_featuresHsR		



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�NoneFixvsr@c@seZdZdZdS)z@TestRefactoringTool.test_get_headnode_dict.<locals>.FileInputFixzfile_input< any * >N)r=r>r?�PATTERNrrrr�FileInputFixysrBc@seZdZdZdS)z=TestRefactoringTool.test_get_headnode_dict.<locals>.SimpleFixz'name'N)r=r>r?rArrrr�	SimpleFix|srC)rZBaseFixrZ_get_headnode_dictrrZpython_symbolsZ
file_inputr+r�NAME�values)rr@rBrCZno_headZ	with_headZsimple�dZ	top_fixesZ
name_fixes�fixesrrr�test_get_headnode_dictusz*TestRefactoringTool.test_get_headnode_dictcCs�ddlm}ddlm}ddlm}ddlm}|j�}|j	�\}}|j
||g�|j
||||g�dS)Nr)�FixFirst)�FixLast)�	FixParrot)�FixPreorder)Zmyfixes.fix_firstrIZmyfixes.fix_lastrJZmyfixes.fix_parrotrKZmyfixes.fix_preorderrLrZ
get_fixersr)rrIrJrKrLrZpreZpostrrr�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�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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?rXr)rWrr�MyRT�srYzdef parrot(): pass

zdef cheese(): pass

z<stdin>F)	rr�_DEFAULT_FIXERSr
�stdin�io�StringIOZrefactor_stdinr+)rrYrZsave�expectedr)rWr�test_refactor_stdin�s	
z'TestRefactoringTool.test_refactor_stdinTcstjdd�}|jtj|�tj�|�tjj|tjj	����tj
�d��fdd�}|�}|jd|d|�}	|r�||	_n|	j
��|j||��|s�dS|	j
�d�|�}
|j||
�|
S)	N�prefixz2to3-test_refactori�cs&t�d��}|j�SWdQXdS)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�chmodrZ	log_debug�
refactor_filer+rP)rrer
r�mock_log_debug�actually_writeZtmpdirrfZold_contentsrZnew_contentsr)rer�check_file_refactoring�s$!	
	z*TestRefactoringTool.check_file_refactoringcCs)tjjtd�}|j|t�dS)Nzparrot_example.py)rlrrmrrsrZ)rrerrr�test_refactor_file�sz&TestRefactoringTool.test_refactor_filec
s�tjjtd�}g��fdd�}|j|dfdidd6d|d	d
�dtjtjj|�f}xE�D]&}d|kr|j||�PqqW|jd
|�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
rTr"rqrrFzNot writing changes to .*%s%szNot writing changesz%r not matched in %r)	rlrrmrrs�seprnZassertRegexr)rrerxZ
message_regex�messager)rwr�'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�frv)�gotrr�mock_refactor_file�szPTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.mock_refactor_filer`z2to3-test_refactor�a_dir�wbcs%g|]}tjj�|��qSr)rlrrm)r'r)�dirrrr)s	zHTestRefactoringTool.test_refactor_dir.<locals>.check.<locals>.<listcomp>)rrrprrgrhrl�mkdirrrmrb�closeZrefactor_dirrirjr+)Z	structurer^r~Z	save_funcr�fn)r)r�r}r�check�s
&	z4TestRefactoringTool.test_refactor_dir.<locals>.checkZnothingzhi.pyz.dumbz	.after.pyz	notpy.npyZsappyrzstuff.py)rlrrm)rr�rSr^r)rr�test_refactor_dir�s
		
z%TestRefactoringTool.test_refactor_dircCs&tjjtd�}|j|�dS)Nzdifferent_encoding.py)rlrrm�
TEST_DATA_DIRrs)rr�rrr�test_file_encodingsz&TestRefactoringTool.test_file_encodingcCs(tjjtd�}|j|�}dS)Nzfalse_encoding.py)rlrrmr�rs)rr�r	rrr�test_false_file_encodingsz,TestRefactoringTool.test_false_file_encodingcCsAtjjtd�}|j|�}|j|jtj��dS)Nzbom.py)	rlrrmr�rsr#�
startswith�codecs�BOM_UTF8)rr�r	rrr�test_bomszTestRefactoringTool.test_bomcCs[tj}dt_z8tjjtd�}tjd�}|j||�Wd|t_XdS)Nz
zcrlf.pyz
lib2to3.fixes)rl�lineseprrmr�rr*rs)rZold_sepr�rGrrr�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
)rZrefactor_docstringr+rP)rr�doc�outrrr�test_refactor_docstring%sz+TestRefactoringTool.test_refactor_docstringcCs�ddlm}|jddg�}|jt|j�d�|jddg�}x1|jD]}t||�r]Pq]q]W|jd�dS)Nr)�FixExplicitr
zmyfixes.fix_explicitrzexplicit fixer not loaded)Zmyfixes.fix_explicitr�rr+�lenZ
post_orderrr)rr�rZfixrrr�
test_explicit6sz!TestRefactoringTool.test_explicit)r=r>r?rrrrZrr!r$r-r<rHrMrOrTr_�_2TO3_FIXERSrsrtr{r�r�r�r�r�r�r�rrrrr"s2
-
 
r)!�__doc__Z
__future__rr
rlr��operatorr\rgriZunittest�warningsZlib2to3rrrZ
lib2to3.pgen2rr.rrrm�dirname�__file__r�rrr*rZrr�ZTestCaserrrrr�<module>s*!