Your IP : 216.73.216.196


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_fixers.cpython-35.opt-1.pyc



��Yf���@s7dZddlZddlZddlmZddlmZddlmZm	Z	m
Z
mZddlm
Z
Gdd�de
j�ZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd �d e�ZGd!d"�d"e�ZGd#d$�d$e�ZGd%d&�d&e�ZGd'd(�d(e�ZGd)d*�d*e�Z Gd+d,�d,e�Z!Gd-d.�d.e�Z"Gd/d0�d0e�Z#Gd1d2�d2e�Z$Gd3d4�d4�Z%Gd5d6�d6ee%�Z&Gd7d8�d8ee%�Z'Gd9d:�d:ee%�Z(Gd;d<�d<e�Z)Gd=d>�d>e�Z*Gd?d@�d@e�Z+GdAdB�dBe�Z,GdCdD�dDe�Z-GdEdF�dFe�Z.GdGdH�dHe�Z/GdIdJ�dJe�Z0GdKdL�dLe�Z1GdMdN�dNe�Z2GdOdP�dPe�Z3GdQdR�dRe�Z4GdSdT�dTe�Z5GdUdV�dVe�Z6GdWdX�dXe�Z7GdYdZ�dZe�Z8Gd[d\�d\e�Z9Gd]d^�d^e�Z:Gd_d`�d`e�Z;Gdadb�dbe�Z<Gdcdd�dde�Z=Gdedf�dfe�Z>Gdgdh�dhe�Z?Gdidj�dje�Z@Gdkdl�dle�ZAGdmdn�dne�ZBGdodp�dpe�ZCGdqdr�dre�ZDGdsdt�dte�ZEdS)uz" Test suite for the fixer modules �N)�chain)�
itemgetter)�pygram�pytree�refactor�
fixer_util)�supportc@sveZdZddddd�Zdd�Zddd	�Zdd
d�Zdd
�Zddd�Zdd�Z	dS)�
FixerTestCaseN�lib2to3cCsx|dkr|jg}tj|||�|_g|_d|_x/t|jj|jj�D]}|j|_	q^WdS)Nz<string>)
�fixerr�get_refactorerr�	fixer_log�filenamerZ	pre_orderZ
post_order�log)�selfZfix_listZ	fixer_pkgZoptionsr�r�>/opt/alt/python35/lib64/python3.5/lib2to3/tests/test_fixers.py�setUps		zFixerTestCase.setUpcCsPtj|�}tj|�}|jj||j�}|j|t|��|S)N)rZreformatrZrefactor_stringr�assertEqual�str)r�before�after�treerrr�_checks
zFixerTestCase._checkFcCs?|j||�}|j|j�|s;|j|jg�dS)N)r�
assertTrue�was_changedrr
)rrr�ignore_warningsrrrr�check$szFixerTestCase.checkcCsH|j||�}|j|dj|j��|sD|j|j�dS)N�)rZassertIn�joinr
rr)rrr�message�	unchangedrrrr�warns*szFixerTestCase.warnscCs|j|||dd�dS)Nr!T)r")rrr rrr�warns_unchanged0szFixerTestCase.warns_unchangedcCs-|j||�|s)|j|jg�dS)N)rrr
)rrrrrrr!3szFixerTestCase.unchangedcGs�|jg}|j|�tjd|�}|j�\}}d|j}|rm|djjj|�rmdS|r�|d	jjj|�r�|r�dS|jddj	dd�||D��|f�dS)
Nr
Zfix_�z5Fixer run order (%s) is incorrect; %s should be last.z, cSsg|]}|jj�qSr)�	__class__�
__module__)�.0�xrrr�
<listcomp>Es	z3FixerTestCase.assert_runs_after.<locals>.<listcomp>���r*)
r�extendrrZ
get_fixersr%r&�endswithZfailr)r�names�fixes�rZpreZpost�nrrr�assert_runs_after8s

&	zFixerTestCase.assert_runs_after)
�__name__r&�__qualname__rrrr"r#r!r1rrrrr	sr	c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�Test_ne�necCs d}d}|j||�dS)Nzif x <> y:
            passzif x != y:
            pass)r)r�b�arrr�
test_basicJszTest_ne.test_basiccCs d}d}|j||�dS)Nzif x<>y:
            passzif x!=y:
            pass)r)rr6r7rrr�test_no_spacesRszTest_ne.test_no_spacescCs d}d}|j||�dS)Nzif x<>y<>z:
            passzif x!=y!=z:
            pass)r)rr6r7rrr�test_chainedZszTest_ne.test_chainedN)r2r&r3rr8r9r:rrrrr4Gsr4c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�Test_has_keyZhas_keycCs d}d}|j||�dS)Nz$x = d.has_key("x") or d.has_key("y")zx = "x" in d or "y" in d)r)rr6r7rrr�test_1eszTest_has_key.test_1cCs d}d}|j||�dS)Nzx = a.b.c.d.has_key("x") ** 3zx = ("x" in a.b.c.d) ** 3)r)rr6r7rrr�test_2jszTest_has_key.test_2cCs d}d}|j||�dS)Nz!x = a.b.has_key(1 + 2).__repr__()zx = (1 + 2 in a.b).__repr__())r)rr6r7rrr�test_3oszTest_has_key.test_3cCs d}d}|j||�dS)Nz,x = a.b.has_key(1 + 2).__repr__() ** -3 ** 4z(x = (1 + 2 in a.b).__repr__() ** -3 ** 4)r)rr6r7rrr�test_4tszTest_has_key.test_4cCs d}d}|j||�dS)Nzx = a.has_key(f or g)zx = (f or g) in a)r)rr6r7rrr�test_5yszTest_has_key.test_5cCs d}d}|j||�dS)Nzx = a + b.has_key(c)zx = a + (c in b))r)rr6r7rrr�test_6~szTest_has_key.test_6cCs d}d}|j||�dS)Nzx = a.has_key(lambda: 12)zx = (lambda: 12) in a)r)rr6r7rrr�test_7�szTest_has_key.test_7cCs d}d}|j||�dS)Nzx = a.has_key(a for a in b)zx = (a for a in b) in a)r)rr6r7rrr�test_8�szTest_has_key.test_8cCs d}d}|j||�dS)Nzif not a.has_key(b): passzif b not in a: pass)r)rr6r7rrr�test_9�szTest_has_key.test_9cCs d}d}|j||�dS)Nz$if not a.has_key(b).__repr__(): passz if not (b in a).__repr__(): pass)r)rr6r7rrr�test_10�szTest_has_key.test_10cCs d}d}|j||�dS)Nzif not a.has_key(b) ** 2: passzif not (b in a) ** 2: pass)r)rr6r7rrr�test_11�szTest_has_key.test_11N)r2r&r3rr<r=r>r?r@rArBrCrDrErFrrrrr;bsr;c@sNeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6S)7�
Test_applyZapplycCs d}d}|j||�dS)Nzx = apply(f, g + h)z
x = f(*g + h))r)rr6r7rrrr<�szTest_apply.test_1cCs d}d}|j||�dS)Nzy = apply(f, g, h)zy = f(*g, **h))r)rr6r7rrrr=�szTest_apply.test_2cCs d}d}|j||�dS)Nz z = apply(fs[0], g or h, h or g)zz = fs[0](*g or h, **h or g))r)rr6r7rrrr>�szTest_apply.test_3cCs d}d}|j||�dS)Nzapply(f, (x, y) + t)zf(*(x, y) + t))r)rr6r7rrrr?�szTest_apply.test_4cCs d}d}|j||�dS)Nzapply(f, args,)zf(*args))r)rr6r7rrrr@�szTest_apply.test_5cCs d}d}|j||�dS)Nzapply(f, args, kwds,)zf(*args, **kwds))r)rr6r7rrrrA�szTest_apply.test_6cCs d}d}|j||�dS)Nzx = apply(f+g, args)zx = (f+g)(*args))r)rr6r7rrr�test_complex_1�szTest_apply.test_complex_1cCs d}d}|j||�dS)Nzx = apply(f*g, args)zx = (f*g)(*args))r)rr6r7rrr�test_complex_2�szTest_apply.test_complex_2cCs d}d}|j||�dS)Nzx = apply(f**g, args)zx = (f**g)(*args))r)rr6r7rrr�test_complex_3�szTest_apply.test_complex_3cCs d}d}|j||�dS)Nzx = apply(f.g, args)zx = f.g(*args))r)rr6r7rrr�test_dotted_name�szTest_apply.test_dotted_namecCs d}d}|j||�dS)Nzx = apply(f[x], args)zx = f[x](*args))r)rr6r7rrr�test_subscript�szTest_apply.test_subscriptcCs d}d}|j||�dS)Nzx = apply(f(), args)zx = f()(*args))r)rr6r7rrr�	test_call�szTest_apply.test_callcCs d}d}|j||�dS)Nz"x = apply(a.b.c.d.e.f, args, kwds)zx = a.b.c.d.e.f(*args, **kwds))r)rr6r7rrr�test_extreme�szTest_apply.test_extremecCs d}d}|j||�dS)Nz1apply(   # foo
          f, # bar
          args)zf(*args))r)rr6r7rrr�test_weird_comments�szTest_apply.test_weird_commentscCsd}|j|�dS)Nzapply())r!)r�srrr�test_unchanged_1�szTest_apply.test_unchanged_1cCsd}|j|�dS)Nzapply(f))r!)rrPrrr�test_unchanged_2�szTest_apply.test_unchanged_2cCsd}|j|�dS)Nz	apply(f,))r!)rrPrrr�test_unchanged_3�szTest_apply.test_unchanged_3cCsd}|j|�dS)Nzapply(f, args, kwds, extras))r!)rrPrrr�test_unchanged_4�szTest_apply.test_unchanged_4cCsd}|j|�dS)Nzapply(f, *args, **kwds))r!)rrPrrr�test_unchanged_5�szTest_apply.test_unchanged_5cCsd}|j|�dS)Nzapply(f, *args))r!)rrPrrr�test_unchanged_6szTest_apply.test_unchanged_6cCsd}|j|�dS)Nzapply(f, **kwds))r!)rrPrrr�test_unchanged_6bszTest_apply.test_unchanged_6bcCsd}|j|�dS)Nz#apply(func=f, args=args, kwds=kwds))r!)rrPrrr�test_unchanged_7szTest_apply.test_unchanged_7cCsd}|j|�dS)Nzapply(f, args=args, kwds=kwds))r!)rrPrrr�test_unchanged_8szTest_apply.test_unchanged_8cCsd}|j|�dS)Nzapply(f, args, kwds=kwds))r!)rrPrrr�test_unchanged_9szTest_apply.test_unchanged_9cCs d}d}|j||�dS)Nzapply(  f,  args,   kwds)zf(*args, **kwds))r)rr7r6rrr�test_space_1szTest_apply.test_space_1cCs d}d}|j||�dS)Nzapply(  f  ,args,kwds   )zf(*args, **kwds))r)rr7r6rrr�test_space_2szTest_apply.test_space_2N)r2r&r3rr<r=r>r?r@rArHrIrJrKrLrMrNrOrQrRrSrTrUrVrWrXrYrZr[r\rrrrrG�s6	rGc@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Test_reload�reloadcCs d}d}|j||�dS)Nz	reload(a)zimport imp
imp.reload(a))r)rr6r7rrr�test$szTest_reload.testcCs<d}d}|j||�d}d}|j||�dS)Nzreload( a ) # commentz$import imp
imp.reload( a ) # commentzreload( a )  # commentz%import imp
imp.reload( a )  # comment)r)rr6r7rrr�test_comment)szTest_reload.test_commentcCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nzreload( a )zimport imp
imp.reload( a )z
reload( a)zimport imp
imp.reload( a)z
reload(a )zimport imp
imp.reload(a ))r)rr6r7rrr�
test_space3szTest_reload.test_spacecCs�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d	}|j|�dS)
Nzreload(a=1)zreload(f, g)z
reload(f, *h)zreload(f, *h, **i)zreload(f, **i)zreload(*h, **i)z
reload(*h)zreload(**i)zreload())r!)rrPrrr�test_unchanged@s$







zTest_reload.test_unchangedN)r2r&r3rr_r`rarbrrrrr]!s


r]c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�Test_intern�interncCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nzx =   intern(  a  )z"import sys
x =   sys.intern(  a  )z%y = intern("b" # test
              )z4import sys
y = sys.intern("b" # test
              )zz = intern(a+b+c.d,   )z&import sys
z = sys.intern(a+b+c.d,   ))r)rr6r7rrr�test_prefix_preservation_sz$Test_intern.test_prefix_preservationcCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nz
x = intern(a)zimport sys
x = sys.intern(a)zz = intern(a+b+c.d,)z#import sys
z = sys.intern(a+b+c.d,)z"intern("y%s" % 5).replace("y", "")z1import sys
sys.intern("y%s" % 5).replace("y", ""))r)rr6r7rrrr_nszTest_intern.testcCscd}|j|�d}|j|�d}|j|�d}|j|�d}|j|�dS)Nzintern(a=1)zintern(f, g)z
intern(*h)zintern(**i)zintern())r!)rrPrrrrb}s



zTest_intern.test_unchangedN)r2r&r3rrer_rbrrrrrc\srcc@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Test_reduce�reducecCs d}d}|j||�dS)Nzreduce(a, b, c)z,from functools import reduce
reduce(a, b, c))r)rr6r7rrr�test_simple_call�szTest_reduce.test_simple_callcCs d}d}|j||�dS)Nzdef x(arg): reduce(sum, [])z8from functools import reduce
def x(arg): reduce(sum, []))r)rr6r7rrr�
test_bug_7253�szTest_reduce.test_bug_7253cCs d}d}|j||�dS)Nzreduce(lambda x, y: x + y, seq)z<from functools import reduce
reduce(lambda x, y: x + y, seq))r)rr6r7rrr�test_call_with_lambda�sz!Test_reduce.test_call_with_lambdacCscd}|j|�d}|j|�d}|j|�d}|j|�d}|j|�dS)Nz	reduce(a)zreduce(a, b=42)zreduce(a, b, c, d)zreduce(**c)zreduce())r!)rrPrrrrb�s



zTest_reduce.test_unchangedN)r2r&r3rrhrirjrbrrrrrf�s
rfc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$S)%�
Test_print�printcCs d}d}|j||�dS)Nzprint 1,   1+1,   1+1+1zprint(1,   1+1,   1+1+1))r)rr6r7rrrre�sz#Test_print.test_prefix_preservationcCs*d}|j|�d}|j|�dS)Nzprint()z	print(''))r!)rrPrrr�test_idempotency�s
zTest_print.test_idempotencycCsOtj|jj_d}|j|�d}|j|�d}|j|�dS)Nzprint(1, 1+1, 1+1+1)zprint()z	print(''))rZ!python_grammar_no_print_statementrZdriverZgrammarr!)rrPrrr�"test_idempotency_print_as_function�s

z-Test_print.test_idempotency_print_as_functioncCs d}d}|j||�dS)Nzprint 1, 1+1, 1+1+1zprint(1, 1+1, 1+1+1))r)rr6r7rrrr<�szTest_print.test_1cCs d}d}|j||�dS)Nz
print 1, 2zprint(1, 2))r)rr6r7rrrr=�szTest_print.test_2cCs d}d}|j||�dS)Nrlzprint())r)rr6r7rrrr>�szTest_print.test_3cCs d}d}|j||�dS)Nzprint whatever; printzprint(whatever); print())r)rr6r7rrrr?�szTest_print.test_4cCs d}d}|j||�dS)Nzprint; print whatever;zprint(); print(whatever);)r)rr6r7rrrr@�szTest_print.test_5cCs d}d}|j||�dS)Nzprint (a, b, c)zprint((a, b, c)))r)rr6r7rrr�
test_tuple�szTest_print.test_tuplecCs d}d}|j||�dS)Nzprint 1, 2, 3,zprint(1, 2, 3, end=' '))r)rr6r7rrr�test_trailing_comma_1�sz Test_print.test_trailing_comma_1cCs d}d}|j||�dS)Nzprint 1, 2,zprint(1, 2, end=' '))r)rr6r7rrr�test_trailing_comma_2�sz Test_print.test_trailing_comma_2cCs d}d}|j||�dS)Nzprint 1,zprint(1, end=' '))r)rr6r7rrr�test_trailing_comma_3�sz Test_print.test_trailing_comma_3cCs d}d}|j||�dS)Nzprint >>sys.stderr, 1, 2, 3zprint(1, 2, 3, file=sys.stderr))r)rr6r7rrr�!test_vargs_without_trailing_comma�sz,Test_print.test_vargs_without_trailing_commacCs d}d}|j||�dS)Nzprint >>sys.stderr, 1, 2,z%print(1, 2, end=' ', file=sys.stderr))r)rr6r7rrr�test_with_trailing_commasz#Test_print.test_with_trailing_commacCs d}d}|j||�dS)Nzprint >>sys.stderr, 1+1zprint(1+1, file=sys.stderr))r)rr6r7rrr�test_no_trailing_commasz!Test_print.test_no_trailing_commacCs d}d}|j||�dS)Nzprint >>  sys.stderrzprint(file=sys.stderr))r)rr6r7rrr�test_spaces_before_filesz"Test_print.test_spaces_before_filecCs3d}|j|�d}d}|j||�dS)Nz<from __future__ import print_function
print('Hai!', end=' ')zprint 'Hello, world!'zprint('Hello, world!'))r!r)rrPr6r7rrr�test_with_future_print_functions

z*Test_print.test_with_future_print_functionN)r2r&r3rrermrnr<r=r>r?r@rorprqrrrsrtrurvrwrrrrrk�s$rkc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�	Test_exec�execcCs d}d}|j||�dS)Nz  exec code in ns1,   ns2z  exec(code, ns1,   ns2))r)rr6r7rrrresz"Test_exec.test_prefix_preservationcCs d}d}|j||�dS)Nz	exec codez
exec(code))r)rr6r7rrrr8"szTest_exec.test_basiccCs d}d}|j||�dS)Nzexec code in nszexec(code, ns))r)rr6r7rrr�test_with_globals'szTest_exec.test_with_globalscCs d}d}|j||�dS)Nzexec code in ns1, ns2zexec(code, ns1, ns2))r)rr6r7rrr�test_with_globals_locals,sz"Test_exec.test_with_globals_localscCs d}d}|j||�dS)Nzexec (a.b()) in nszexec((a.b()), ns))r)rr6r7rrrrH1szTest_exec.test_complex_1cCs d}d}|j||�dS)Nzexec a.b() + c in nszexec(a.b() + c, ns))r)rr6r7rrrrI6szTest_exec.test_complex_2cCsd}|j|�dS)Nz
exec(code))r!)rrPrrrrQ=szTest_exec.test_unchanged_1cCsd}|j|�dS)Nzexec (code))r!)rrPrrrrRAszTest_exec.test_unchanged_2cCsd}|j|�dS)Nzexec(code, ns))r!)rrPrrrrSEszTest_exec.test_unchanged_3cCsd}|j|�dS)Nzexec(code, ns1, ns2))r!)rrPrrrrTIszTest_exec.test_unchanged_4N)r2r&r3rrer8rzr{rHrIrQrRrSrTrrrrrxsrxc@sjeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�	Test_repr�reprcCs d}d}|j||�dS)Nz
x =   `1 + 2`zx =   repr(1 + 2))r)rr6r7rrrrePsz"Test_repr.test_prefix_preservationcCs d}d}|j||�dS)Nzx = `1 + 2`zx = repr(1 + 2))r)rr6r7rrr�
test_simple_1UszTest_repr.test_simple_1cCs d}d}|j||�dS)Nzy = `x`zy = repr(x))r)rr6r7rrr�
test_simple_2ZszTest_repr.test_simple_2cCs d}d}|j||�dS)Nzz = `y`.__repr__()zz = repr(y).__repr__())r)rr6r7rrr�test_complex_szTest_repr.test_complexcCs d}d}|j||�dS)Nz
x = `1, 2, 3`zx = repr((1, 2, 3)))r)rr6r7rrrrodszTest_repr.test_tuplecCs d}d}|j||�dS)Nz
x = `1 + `2``zx = repr(1 + repr(2)))r)rr6r7rrr�test_nestediszTest_repr.test_nestedcCs d}d}|j||�dS)Nzx = `1, 2 + `3, 4``zx = repr((1, 2 + repr((3, 4)))))r)rr6r7rrr�test_nested_tuplesnszTest_repr.test_nested_tuplesN)r2r&r3rrer~rr�ror�r�rrrrr|Msr|c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"S)#�Test_except�exceptcCs d}d}|j||�dS)Nzq
            try:
                pass
            except (RuntimeError, ImportError),    e:
                passzs
            try:
                pass
            except (RuntimeError, ImportError) as    e:
                pass)r)rr6r7rrrrevsz$Test_except.test_prefix_preservationcCs d}d}|j||�dS)NzV
            try:
                pass
            except Foo, e:
                passzX
            try:
                pass
            except Foo as e:
                pass)r)rr6r7rrr�test_simple�szTest_except.test_simplecCs d}d}|j||�dS)NzU
            try:
                pass
            except Foo,e:
                passzX
            try:
                pass
            except Foo as e:
                pass)r)rr6r7rrr�"test_simple_no_space_before_target�sz.Test_except.test_simple_no_space_before_targetcCs d}d}|j||�dS)Nz�
            def foo():
                try:
                    pass
                except Exception, (f, e):
                    pass
                except ImportError, e:
                    passa
            def foo():
                try:
                    pass
                except Exception as xxx_todo_changeme:
                    (f, e) = xxx_todo_changeme.args
                    pass
                except ImportError as e:
                    pass)r)rr6r7rrr�test_tuple_unpack�s
zTest_except.test_tuple_unpackcCs d}d}|j||�dS)Nzn
            try:
                pass
            except (RuntimeError, ImportError), e:
                passzp
            try:
                pass
            except (RuntimeError, ImportError) as e:
                pass)r)rr6r7rrr�test_multi_class�szTest_except.test_multi_classcCs d}d}|j||�dS)Nza
            try:
                pass
            except Exception, [a, b]:
                passz�
            try:
                pass
            except Exception as xxx_todo_changeme:
                [a, b] = xxx_todo_changeme.args
                pass)r)rr6r7rrr�test_list_unpack�szTest_except.test_list_unpackcCs d}d}|j||�dS)Nz_
            try:
                pass
            except Exception, d[5]:
                passz�
            try:
                pass
            except Exception as xxx_todo_changeme:
                d[5] = xxx_todo_changeme
                pass)r)rr6r7rrr�test_weird_target_1�szTest_except.test_weird_target_1cCs d}d}|j||�dS)Nz`
            try:
                pass
            except Exception, a.foo:
                passz�
            try:
                pass
            except Exception as xxx_todo_changeme:
                a.foo = xxx_todo_changeme
                pass)r)rr6r7rrr�test_weird_target_2�szTest_except.test_weird_target_2cCs d}d}|j||�dS)Nzb
            try:
                pass
            except Exception, a().foo:
                passz�
            try:
                pass
            except Exception as xxx_todo_changeme:
                a().foo = xxx_todo_changeme
                pass)r)rr6r7rrr�test_weird_target_3�szTest_except.test_weird_target_3cCs d}d}|j||�dS)Nz�
            try:
                pass
            except Exception, a:
                pass
            except:
                passz�
            try:
                pass
            except Exception as a:
                pass
            except:
                pass)r)rr6r7rrr�test_bare_except�szTest_except.test_bare_exceptcCs d}d}|j||�dS)Nz�
            try:
                pass
            except Exception, a:
                pass
            except:
                pass
            else:
                pass
            finally:
                passz�
            try:
                pass
            except Exception as a:
                pass
            except:
                pass
            else:
                pass
            finally:
                pass)r)rr6r7rrr�!test_bare_except_and_else_finallysz-Test_except.test_bare_except_and_else_finallycCs d}d}|j||�dS)Nz�
            try:
                pass
            except TypeError, b:
                pass
            except Exception, a:
                pass
            except:
                passz�
            try:
                pass
            except TypeError as b:
                pass
            except Exception as a:
                pass
            except:
                pass)r)rr6r7rrr�+test_multi_fixed_excepts_before_bare_except(s	
z7Test_except.test_multi_fixed_excepts_before_bare_exceptcCstd}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�dS)	Nzd
            try: raise TypeError
            except TypeError, e:
                pass
            zf
            try: raise TypeError
            except TypeError as e:
                pass
            zd
            try:
                raise TypeError
            except TypeError, e: pass
            zf
            try:
                raise TypeError
            except TypeError as e: pass
            zT
            try: raise TypeError
            except TypeError, e: pass
            zV
            try: raise TypeError
            except TypeError as e: pass
            z�
            try: raise TypeError
            except TypeError, e: pass
            else: function()
            finally: done()
            z�
            try: raise TypeError
            except TypeError as e: pass
            else: function()
            finally: done()
            )r)rr6r7rrr�test_one_line_suites>sz Test_except.test_one_line_suitescCsd}|j|�dS)NzO
            try:
                pass
            except:
                pass)r!)rrPrrrrQnszTest_except.test_unchanged_1cCsd}|j|�dS)NzY
            try:
                pass
            except Exception:
                pass)r!)rrPrrrrRvszTest_except.test_unchanged_2cCsd}|j|�dS)Nzg
            try:
                pass
            except (Exception, SystemExit):
                pass)r!)rrPrrrrS~szTest_except.test_unchanged_3N)r2r&r3rrer�r�r�r�r�r�r�r�r�r�r�r�rQrRrSrrrrr�ss"


0r�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$S)%�
Test_raise�raisecCs d}d}|j||�dS)Nzraise Exception, 5zraise Exception(5))r)rr6r7rrrr8�szTest_raise.test_basiccCs<d}d}|j||�d}d}|j||�dS)Nzraise Exception,5zraise Exception(5)zraise   Exception,    5zraise   Exception(5))r)rr6r7rrrre�sz#Test_raise.test_prefix_preservationcCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nzraise Exception, 5 # foozraise Exception(5) # foozraise E, (5, 6) % (a, b) # foozraise E((5, 6) % (a, b)) # fooz:def foo():
                    raise Exception, 5, 6 # foozIdef foo():
                    raise Exception(5).with_traceback(6) # foo)r)rr6r7rrr�test_with_comments�szTest_raise.test_with_commentscCs d}d}|j||�dS)Nzraise Exception(5), None, tbz%raise Exception(5).with_traceback(tb))r)rr6r7rrr�test_None_value�szTest_raise.test_None_valuecCs d}d}|j||�dS)Nzraise Exception, (5, 6, 7)zraise Exception(5, 6, 7))r)rr6r7rrr�test_tuple_value�szTest_raise.test_tuple_valuecCs d}d}|j||�dS)Nzraise E, (5, 6) % (a, b)zraise E((5, 6) % (a, b)))r)rr6r7rrr�test_tuple_detection�szTest_raise.test_tuple_detectioncCs d}d}|j||�dS)Nzraise (((E1, E2), E3), E4), Vzraise E1(V))r)rr6r7rrr�test_tuple_exc_1�szTest_raise.test_tuple_exc_1cCs d}d}|j||�dS)Nzraise (E1, (E2, E3), E4), Vzraise E1(V))r)rr6r7rrr�test_tuple_exc_2�szTest_raise.test_tuple_exc_2cCsd}|j|d�dS)Nzraise 'foo'z+Python 3 does not support string exceptions)r#)rrPrrr�test_string_exc�szTest_raise.test_string_exccCsd}|j|d�dS)Nzraise "foo", 5z+Python 3 does not support string exceptions)r#)rrPrrr�test_string_exc_val�szTest_raise.test_string_exc_valcCsd}|j|d�dS)Nzraise "foo", 5, 6z+Python 3 does not support string exceptions)r#)rrPrrr�test_string_exc_val_tb�sz!Test_raise.test_string_exc_val_tbcCs d}d}|j||�dS)Nz4def foo():
                    raise Exception, 5, 6zCdef foo():
                    raise Exception(5).with_traceback(6))r)rr6r7rrr�	test_tb_1�szTest_raise.test_tb_1cCs d}d}|j||�dS)Nzhdef foo():
                    a = 5
                    raise Exception, 5, 6
                    b = 6zwdef foo():
                    a = 5
                    raise Exception(5).with_traceback(6)
                    b = 6)r)rr6r7rrr�	test_tb_2�szTest_raise.test_tb_2cCs d}d}|j||�dS)Nz2def foo():
                    raise Exception,5,6zCdef foo():
                    raise Exception(5).with_traceback(6))r)rr6r7rrr�	test_tb_3�szTest_raise.test_tb_3cCs d}d}|j||�dS)Nzfdef foo():
                    a = 5
                    raise Exception,5,6
                    b = 6zwdef foo():
                    a = 5
                    raise Exception(5).with_traceback(6)
                    b = 6)r)rr6r7rrr�	test_tb_4�szTest_raise.test_tb_4cCs d}d}|j||�dS)Nz<def foo():
                    raise Exception, (5, 6, 7), 6zIdef foo():
                    raise Exception(5, 6, 7).with_traceback(6))r)rr6r7rrr�	test_tb_5�szTest_raise.test_tb_5cCs d}d}|j||�dS)Nzpdef foo():
                    a = 5
                    raise Exception, (5, 6, 7), 6
                    b = 6z}def foo():
                    a = 5
                    raise Exception(5, 6, 7).with_traceback(6)
                    b = 6)r)rr6r7rrr�	test_tb_6�szTest_raise.test_tb_6N)r2r&r3rr8rer�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��s$	r�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&S)'�
Test_throw�throwcCs d}d}|j||�dS)Nzg.throw(Exception, 5)zg.throw(Exception(5)))r)rr6r7rrrr<szTest_throw.test_1cCs d}d}|j||�dS)Nzg.throw(Exception,5)zg.throw(Exception(5)))r)rr6r7rrrr=
szTest_throw.test_2cCs d}d}|j||�dS)Nzg.throw(Exception, (5, 6, 7))zg.throw(Exception(5, 6, 7)))r)rr6r7rrrr>szTest_throw.test_3cCs d}d}|j||�dS)Nz5 + g.throw(Exception, 5)z5 + g.throw(Exception(5)))r)rr6r7rrrr?szTest_throw.test_4cCsd}|j|d�dS)Nzg.throw("foo")z+Python 3 does not support string exceptions)r#)rrPrrr�test_warn_1szTest_throw.test_warn_1cCsd}|j|d�dS)Nzg.throw("foo", 5)z+Python 3 does not support string exceptions)r#)rrPrrr�test_warn_2"szTest_throw.test_warn_2cCsd}|j|d�dS)Nzg.throw("foo", 5, 6)z+Python 3 does not support string exceptions)r#)rrPrrr�test_warn_3&szTest_throw.test_warn_3cCsd}|j|�dS)Nzg.throw(Exception))r!)rrPrrr�test_untouched_1,szTest_throw.test_untouched_1cCsd}|j|�dS)Nzg.throw(Exception(5, 6)))r!)rrPrrr�test_untouched_20szTest_throw.test_untouched_2cCsd}|j|�dS)Nz5 + g.throw(Exception(5, 6)))r!)rrPrrr�test_untouched_34szTest_throw.test_untouched_3cCs d}d}|j||�dS)Nz7def foo():
                    g.throw(Exception, 5, 6)zFdef foo():
                    g.throw(Exception(5).with_traceback(6)))r)rr6r7rrrr�:szTest_throw.test_tb_1cCs d}d}|j||�dS)Nzkdef foo():
                    a = 5
                    g.throw(Exception, 5, 6)
                    b = 6zzdef foo():
                    a = 5
                    g.throw(Exception(5).with_traceback(6))
                    b = 6)r)rr6r7rrrr�AszTest_throw.test_tb_2cCs d}d}|j||�dS)Nz5def foo():
                    g.throw(Exception,5,6)zFdef foo():
                    g.throw(Exception(5).with_traceback(6)))r)rr6r7rrrr�LszTest_throw.test_tb_3cCs d}d}|j||�dS)Nzidef foo():
                    a = 5
                    g.throw(Exception,5,6)
                    b = 6zzdef foo():
                    a = 5
                    g.throw(Exception(5).with_traceback(6))
                    b = 6)r)rr6r7rrrr�SszTest_throw.test_tb_4cCs d}d}|j||�dS)Nz?def foo():
                    g.throw(Exception, (5, 6, 7), 6)zLdef foo():
                    g.throw(Exception(5, 6, 7).with_traceback(6)))r)rr6r7rrrr�^szTest_throw.test_tb_5cCs d}d}|j||�dS)Nzsdef foo():
                    a = 5
                    g.throw(Exception, (5, 6, 7), 6)
                    b = 6z�def foo():
                    a = 5
                    g.throw(Exception(5, 6, 7).with_traceback(6))
                    b = 6)r)rr6r7rrrr�eszTest_throw.test_tb_6cCs d}d}|j||�dS)Nz;def foo():
                    a + g.throw(Exception, 5, 6)zJdef foo():
                    a + g.throw(Exception(5).with_traceback(6)))r)rr6r7rrr�	test_tb_7pszTest_throw.test_tb_7cCs d}d}|j||�dS)Nzodef foo():
                    a = 5
                    a + g.throw(Exception, 5, 6)
                    b = 6z~def foo():
                    a = 5
                    a + g.throw(Exception(5).with_traceback(6))
                    b = 6)r)rr6r7rrr�	test_tb_8wszTest_throw.test_tb_8N)r2r&r3rr<r=r>r?r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�s&r�c@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�	Test_longZlongcCs d}d}|j||�dS)Nzx = long(x)z
x = int(x))r)rr6r7rrrr<�szTest_long.test_1cCs d}d}|j||�dS)Nzy = isinstance(x, long)zy = isinstance(x, int))r)rr6r7rrrr=�szTest_long.test_2cCs d}d}|j||�dS)Nzz = type(x) in (int, long)zz = type(x) in (int, int))r)rr6r7rrrr>�szTest_long.test_3cCs�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�dS)Nzlong = Truez
s.long = Truezdef long(): passzclass long(): passzdef f(long): passzdef f(g, long): passzdef f(x, long=True): pass)r!)rrPrrrrb�s





zTest_long.test_unchangedcCs d}d}|j||�dS)Nzx =   long(  x  )zx =   int(  x  ))r)rr6r7rrrre�sz"Test_long.test_prefix_preservationN)	r2r&r3rr<r=r>rbrerrrrr��sr�c@s.eZdZdZdd�Zdd�ZdS)�
Test_execfileZexecfilecCs�d}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�d	}d
}|j||�d}d}|j||�dS)
Nzexecfile("fn")z.exec(compile(open("fn").read(), "fn", 'exec'))zexecfile("fn", glob)z4exec(compile(open("fn").read(), "fn", 'exec'), glob)zexecfile("fn", glob, loc)z9exec(compile(open("fn").read(), "fn", 'exec'), glob, loc)zexecfile("fn", globals=glob)z<exec(compile(open("fn").read(), "fn", 'exec'), globals=glob)zexecfile("fn", locals=loc)z:exec(compile(open("fn").read(), "fn", 'exec'), locals=loc)z(execfile("fn", globals=glob, locals=loc)zHexec(compile(open("fn").read(), "fn", 'exec'), globals=glob, locals=loc))r)rr6r7rrr�test_conversion�s$zTest_execfile.test_conversioncCs<d}d}|j||�d}d}|j||�dS)Nzexecfile( "fn" )z0exec(compile(open( "fn" ).read(), "fn", 'exec'))zexecfile("fn",  globals = glob)z?exec(compile(open("fn").read(), "fn", 'exec'),  globals = glob))r)rr6r7rrr�test_spacing�szTest_execfile.test_spacingN)r2r&r3rr�r�rrrrr��sr�c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�Test_isinstance�
isinstancecCstd}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�dS)	Nzisinstance(x, (int, int, int))zisinstance(x, int)z,isinstance(x, (int, float, int, int, float))zisinstance(x, (int, float))z1isinstance(x, (int, float, int, int, float, str))z isinstance(x, (int, float, str))z4isinstance(foo() + bar(), (x(), y(), x(), int, int))z/isinstance(foo() + bar(), (x(), y(), x(), int)))r)rr6r7rrr�test_remove_multiple_items�sz*Test_isinstance.test_remove_multiple_itemscCs d}d}|j||�dS)Nz4if    isinstance(  foo(), (  bar, bar, baz )) : passz/if    isinstance(  foo(), (  bar, baz )) : pass)r)rr6r7rrrre�sz(Test_isinstance.test_prefix_preservationcCs|jd�dS)Nzisinstance(x, (str, int)))r!)rrrrrb�szTest_isinstance.test_unchangedN)r2r&r3rr�rerbrrrrr��sr�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHS)I�	Test_dict�dictcCs�d}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�d	}d
}|j||�d}d}|j||�dS)Nzif   d. keys  (  )  : passz if   list(d. keys  (  ))  : passzif   d. items  (  )  : passz!if   list(d. items  (  ))  : passzif   d. iterkeys  ( )  : passzif   iter(d. keys  ( ))  : passz"[i for i in    d.  iterkeys(  )  ]z[i for i in    d.  keys(  )  ]zif   d. viewkeys  ( )  : passzif   d. keys  ( )  : passz"[i for i in    d.  viewkeys(  )  ])r)rr6r7rrrre�s$z"Test_dict.test_prefix_preservationcCs�d}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�d	}d}|j||�dS)
Nzd.keys() # foozlist(d.keys()) # foozd.items()  # foozlist(d.items())  # foozd.iterkeys()  # fooziter(d.keys())  # fooz/[i for i in d.iterkeys() # foo
               ]z+[i for i in d.keys() # foo
               ]zd.viewitems()  # foo)r)rr6r7rrr�test_trailing_comments$zTest_dict.test_trailing_commentcCs]xVtjD]K}d|}|j|�d|}|j|�d|}|j|�q
WdS)Nzs = %s(d.keys())zs = %s(d.values())zs = %s(d.items()))r�consuming_callsr!)r�wrapperrPrrrrb+s




zTest_dict.test_unchangedcCs<d}d}|j||�d}d}|j||�dS)Nzd.keys()zlist(d.keys())za[0].foo().keys()zlist(a[0].foo().keys()))r)rr6r7rrr�test_016szTest_dict.test_01cCs d}d}|j||�dS)Nz	d.items()zlist(d.items()))r)rr6r7rrr�test_02?szTest_dict.test_02cCs d}d}|j||�dS)Nz
d.values()zlist(d.values()))r)rr6r7rrr�test_03DszTest_dict.test_03cCs d}d}|j||�dS)Nzd.iterkeys()ziter(d.keys()))r)rr6r7rrr�test_04IszTest_dict.test_04cCs d}d}|j||�dS)Nz
d.iteritems()ziter(d.items()))r)rr6r7rrr�test_05NszTest_dict.test_05cCs d}d}|j||�dS)Nzd.itervalues()ziter(d.values()))r)rr6r7rrr�test_06SszTest_dict.test_06cCsd}|j|�dS)Nzlist(d.keys()))r!)rrPrrr�test_07XszTest_dict.test_07cCsd}|j|�dS)Nzsorted(d.keys()))r!)rrPrrr�test_08\szTest_dict.test_08cCs d}d}|j||�dS)Nziter(d.keys())ziter(list(d.keys())))r)rr6r7rrr�test_09`szTest_dict.test_09cCs d}d}|j||�dS)Nz
foo(d.keys())zfoo(list(d.keys())))r)rr6r7rrrrEeszTest_dict.test_10cCs d}d}|j||�dS)Nzfor i in d.keys(): print iz for i in list(d.keys()): print i)r)rr6r7rrrrFjszTest_dict.test_11cCs d}d}|j||�dS)Nzfor i in d.iterkeys(): print izfor i in d.keys(): print i)r)rr6r7rrr�test_12oszTest_dict.test_12cCs d}d}|j||�dS)Nz[i for i in d.keys()]z for i in list(d.keys())])r)rr6r7rrr�test_13tszTest_dict.test_13cCs d}d}|j||�dS)Nz[i for i in d.iterkeys()]z[i for i in d.keys()])r)rr6r7rrr�test_14yszTest_dict.test_14cCs d}d}|j||�dS)Nz(i for i in d.keys())z(i for i in list(d.keys())))r)rr6r7rrr�test_15~szTest_dict.test_15cCs d}d}|j||�dS)Nz(i for i in d.iterkeys())z(i for i in d.keys()))r)rr6r7rrr�test_16�szTest_dict.test_16cCs d}d}|j||�dS)Nziter(d.iterkeys())ziter(d.keys()))r)rr6r7rrr�test_17�szTest_dict.test_17cCs d}d}|j||�dS)Nzlist(d.iterkeys())zlist(d.keys()))r)rr6r7rrr�test_18�szTest_dict.test_18cCs d}d}|j||�dS)Nzsorted(d.iterkeys())zsorted(d.keys()))r)rr6r7rrr�test_19�szTest_dict.test_19cCs d}d}|j||�dS)Nzfoo(d.iterkeys())zfoo(iter(d.keys())))r)rr6r7rrr�test_20�szTest_dict.test_20cCs d}d}|j||�dS)Nzprint h.iterkeys().next()zprint iter(h.keys()).next())r)rr6r7rrr�test_21�szTest_dict.test_21cCs d}d}|j||�dS)Nzprint h.keys()[0]zprint list(h.keys())[0])r)rr6r7rrr�test_22�szTest_dict.test_22cCs d}d}|j||�dS)Nzprint list(h.iterkeys().next())z!print list(iter(h.keys()).next()))r)rr6r7rrr�test_23�szTest_dict.test_23cCs d}d}|j||�dS)Nzfor x in h.keys()[0]: print xz#for x in list(h.keys())[0]: print x)r)rr6r7rrr�test_24�szTest_dict.test_24cCs d}d}|j||�dS)Nzd.viewkeys()zd.keys())r)rr6r7rrr�test_25�szTest_dict.test_25cCs d}d}|j||�dS)Nz
d.viewitems()z	d.items())r)rr6r7rrr�test_26�szTest_dict.test_26cCs d}d}|j||�dS)Nzd.viewvalues()z
d.values())r)rr6r7rrr�test_27�szTest_dict.test_27cCs d}d}|j||�dS)Nz[i for i in d.viewkeys()]z[i for i in d.keys()])r)rr6r7rrr�test_28�szTest_dict.test_28cCs d}d}|j||�dS)Nz(i for i in d.viewkeys())z(i for i in d.keys()))r)rr6r7rrr�test_29�szTest_dict.test_29cCs d}d}|j||�dS)Nziter(d.viewkeys())ziter(d.keys()))r)rr6r7rrr�test_30�szTest_dict.test_30cCs d}d}|j||�dS)Nzlist(d.viewkeys())zlist(d.keys()))r)rr6r7rrr�test_31�szTest_dict.test_31cCs d}d}|j||�dS)Nzsorted(d.viewkeys())zsorted(d.keys()))r)rr6r7rrr�test_32�szTest_dict.test_32N)'r2r&r3rrer�rbr�r�r�r�r�r�r�r�r�rErFr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��sH	r�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�Test_xrange�xrangecCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nzx =    xrange(  10  )zx =    range(  10  )zx = xrange(  1  ,  10   )zx = range(  1  ,  10   )zx = xrange(  0  ,  10 ,  2 )zx = range(  0  ,  10 ,  2 ))r)rr6r7rrrre�sz$Test_xrange.test_prefix_preservationcCs d}d}|j||�dS)Nzx = xrange(10)z
x = range(10))r)rr6r7rrr�test_single_arg�szTest_xrange.test_single_argcCs d}d}|j||�dS)Nzx = xrange(1, 10)zx = range(1, 10))r)rr6r7rrr�
test_two_args�szTest_xrange.test_two_argscCs d}d}|j||�dS)Nzx = xrange(0, 10, 2)zx = range(0, 10, 2))r)rr6r7rrr�test_three_args�szTest_xrange.test_three_argscCs�d}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�d	}d
}|j||�dS)Nzx = range(10, 3, 9)zx = list(range(10, 3, 9))zx = foo(range(10, 3, 9))zx = foo(list(range(10, 3, 9)))zx = range(10, 3, 9) + [4]zx = list(range(10, 3, 9)) + [4]zx = range(10)[::-1]zx = list(range(10))[::-1]zx = range(10)  [3]zx = list(range(10))  [3])r)rr6r7rrr�test_wrap_in_list�szTest_xrange.test_wrap_in_listcCs<d}d}|j||�d}d}|j||�dS)Nzfor i in xrange(10):
    j=izfor i in range(10):
    j=iz[i for i in xrange(10)]z[i for i in range(10)])r)rr6r7rrr�test_xrange_in_forszTest_xrange.test_xrange_in_forcCs|jd�|jd�dS)Nzfor i in range(10): passz[i for i in range(10)])r!)rrrr�test_range_in_fors
zTest_xrange.test_range_in_forcCs|jd�dS)Nzx in range(10, 3, 9))r!)rrrr�test_in_contains_testsz!Test_xrange.test_in_contains_testcCs)x"tjD]}|jd|�q
WdS)Nza = %s(range(10)))rr�r!)rZcallrrr�test_in_consuming_contextsz%Test_xrange.test_in_consuming_contextN)
r2r&r3rrer�r�r�r�r�r�r�r�rrrrr��s
	r�cs.eZdZ�fdd�Zdd�Z�S)�Test_xrange_with_reducecs tt|�jddg�dS)Nr�rg)�superr�r)r)r%rrr"szTest_xrange_with_reduce.setUpcCs d}d}|j||�dS)Nzreduce(x, xrange(5))z0from functools import reduce
reduce(x, range(5)))r)rr6r7rrr�test_double_transform%sz-Test_xrange_with_reduce.test_double_transform)r2r&r3rr�rr)r%rr� sr�c@sveZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�Test_raw_inputZ	raw_inputcCs<d}d}|j||�d}d}|j||�dS)Nzx =    raw_input(   )zx =    input(   )zx = raw_input(   ''   )zx = input(   ''   ))r)rr6r7rrrre.sz'Test_raw_input.test_prefix_preservationcCs d}d}|j||�dS)Nzx = raw_input()zx = input())r)rr6r7rrrr<7szTest_raw_input.test_1cCs d}d}|j||�dS)Nzx = raw_input('')z
x = input(''))r)rr6r7rrrr=<szTest_raw_input.test_2cCs d}d}|j||�dS)Nzx = raw_input('prompt')zx = input('prompt'))r)rr6r7rrrr>AszTest_raw_input.test_3cCs d}d}|j||�dS)Nzx = raw_input(foo(a) + 6)zx = input(foo(a) + 6))r)rr6r7rrrr?FszTest_raw_input.test_4cCs d}d}|j||�dS)Nzx = raw_input(invite).split()zx = input(invite).split())r)rr6r7rrrr@KszTest_raw_input.test_5cCs d}d}|j||�dS)Nz x = raw_input(invite) . split ()zx = input(invite) . split ())r)rr6r7rrrrAPszTest_raw_input.test_6cCs d}d}|j||�dS)Nzx = int(raw_input())zx = int(input()))r)rr6r7rrrrCUszTest_raw_input.test_8N)r2r&r3rrer<r=r>r?r@rArCrrrrr�+s	r�c@sIeZdZdZdddddddgZd	d
�Zdd�Zd
S)�Test_funcattrsZ	funcattrsZclosure�doc�nameZdefaults�code�globalsr�cCs`xY|jD]N}d|}d|}|j||�d|}d|}|j||�q
WdS)Nz	a.func_%sza.__%s__zself.foo.func_%s.foo_barzself.foo.__%s__.foo_bar)�attrsr)r�attrr6r7rrrr__s



zTest_funcattrs.testcCs]xV|jD]K}d|}|j|�d|}|j|�d|}|j|�q
WdS)Nzfoo(func_%s + 5)z
f(foo.__%s__)zf(foo.__%s__.foo))r�r!)rr�rPrrrrbis




zTest_funcattrs.test_unchangedN)r2r&r3rr�r_rbrrrrr�Zs
r�c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�Test_xreadlinesZ
xreadlinescCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nzfor x in f.xreadlines(): passzfor x in f: passz!for x in foo().xreadlines(): passzfor x in foo(): passz'for x in (5 + foo()).xreadlines(): passzfor x in (5 + foo()): pass)r)rr6r7rrrrMwszTest_xreadlines.test_callcCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nzfoo(f.xreadlines + 5)zfoo(f.__iter__ + 5)zfoo(f().xreadlines + 5)zfoo(f().__iter__ + 5)zfoo((5 + f()).xreadlines + 5)zfoo((5 + f()).__iter__ + 5))r)rr6r7rrr�
test_attr_ref�szTest_xreadlines.test_attr_refcCsPd}|j|�d}|j|�d}|j|�d}|j|�dS)Nzfor x in f.xreadlines(5): passz for x in f.xreadlines(k=5): passz$for x in f.xreadlines(*k, **v): passzfoo(xreadlines))r!)rrPrrrrb�s


zTest_xreadlines.test_unchangedN)r2r&r3rrMr�rbrrrrr�ts

r�c@sXeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ImportsFixerTestscCslxe|jj�D]T\}}d|}d|}|j||�d|}d|}|j||�qWdS)Nz	import %szimport foo, %s, bar)�modules�itemsr)r�old�newr6r7rrr�test_import_module�s



z$ImportsFixerTests.test_import_modulecCs�x�|jj�D]x\}}d|}d|}|j||�d|}d|}|j||�d|}d|}|j||�qWdS)Nzfrom %s import foozfrom %s import foo, barzfrom %s import (yes, no))r�r�r)rr�r�r6r7rrr�test_import_from�s





z"ImportsFixerTests.test_import_fromcCslxe|jj�D]T\}}d|}d|}|j||�d|}d|}|j||�qWdS)Nzimport %s as foo_bar)r�r�r)rr�r�r6r7rrr�test_import_module_as�s



z'ImportsFixerTests.test_import_module_ascCsHxA|jj�D]0\}}d|}d|}|j||�qWdS)Nzfrom %s import foo as bar)r�r�r)rr�r�r6r7rrr�test_import_from_as�s

z%ImportsFixerTests.test_import_from_ascCsHxA|jj�D]0\}}d|}d|}|j||�qWdS)Nzfrom %s import *)r�r�r)rr�r�r6r7rrr�	test_star�s

zImportsFixerTests.test_starcCsx�|jj�D]�\}}d||f}d||f}|j||�d||f}d||f}|j||�d|f}|j|�d|||f}d|||f}|j||�d||f}d||f}|j||�qWdS)NzG
                import %s
                foo(%s.bar)
                zJ
                from %s import x
                %s = 23
                zJ
                def f():
                    %s.method()
                zJ
                import %s
                %s.bar(%s.foo)
                z@
                import %s
                x.%s
                )r�r�rr!)rr�r�r6r7rPrrr�test_import_module_usage�s

z*ImportsFixerTests.test_import_module_usageN)	r2r&r3r�r�r�r�r�r�rrrrr��s

r�c@s>eZdZdZddlmZdd�Zdd�ZdS)	�Test_imports�imports�)�MAPPINGcCs d}d}|j||�dS)Nzimport urlparse, cStringIOzimport urllib.parse, io)r)rr6r7rrr�test_multiple_importssz"Test_imports.test_multiple_importscCs d}d}|j||�dS)Nzv
            import copy_reg as bar, HTMLParser as foo, urlparse
            s = urlparse.spam(bar.foo())
            z~
            import copyreg as bar, html.parser as foo, urllib.parse
            s = urllib.parse.spam(bar.foo())
            )r)rr6r7rrr�test_multiple_imports_as
sz%Test_imports.test_multiple_imports_asN)	r2r&r3r�fixes.fix_importsr�r�r�r�rrrrr�sr�c@s&eZdZdZddlmZdS)�
Test_imports2�imports2r�)r�N)r2r&r3r�fixes.fix_imports2r�r�rrrrr�sr�cs.eZdZ�fdd�Zdd�Z�S)�Test_imports_fixer_ordercsqtt|�jddg�ddlm}|j�|_ddlm}xd	D]}|||j|<qRWdS)
Nr�rr�)r��dbhash�dumbdbm�dbm�gdbm)rrrr)r�rrrr��copyr�r�)rZmapping2Zmapping1�key)r%rrrs
zTest_imports_fixer_order.setUpcCs+x$dD]}||_|jd�qWdS)Nr�r�import)r�r)rr1)rZfixrrr�$test_after_local_imports_refactoring%s
	z=Test_imports_fixer_order.test_after_local_imports_refactoring)r2r&r3rr
rr)r%rrsrc@szeZdZdZddlmZdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dS)�Test_urllibZurllibr�)r�cCs`xY|jj�D]H\}}d|}ddjttd�|��}|j||�qWdS)Nz	import %sz, r)r�r�r�maprr)rr��changesr6r7rrrr�/s
"zTest_urllib.test_import_modulec
CsMxF|jj�D]5\}}g}x�|D]�\}}xb|D]Z}|j|�d||f}d||f}|j||�d|}	|j|	�q<Wd|dj|�f}d|dj|�f}|j||�ddj|�}	|j|	�q)Wd|dj|�f}djdd�|D��}|j||�qWdS)Nzfrom %s import %szfrom foo import %sz, �
cSs/g|]%\}}d|dj|�f�qS)zfrom %s import %sz, )r)r'r��membersrrrr)Ks	z0Test_urllib.test_import_from.<locals>.<listcomp>)r�r��appendrr!r)
rr�r
Zall_membersr�r�memberr6r7rPrrrr�5s&



zTest_urllib.test_import_fromcCs2x+|jD] }d|}|j|d�q
WdS)Nzimport %s as fooz#This module is now multiple modules)r�r#)rr�rPrrrr�Os
z!Test_urllib.test_import_module_ascCs�x�|jj�D]�\}}x�|D]�\}}xt|D]l}d||f}d||f}|j||�d|||f}d|||f}|j||�q6Wq#WqWdS)Nzfrom %s import %s as foo_barzfrom %s import %s as blah, %s)r�r�r)rr�r
r�rrr6r7rrrr�Ts
zTest_urllib.test_import_from_ascCs2x+|jD] }d|}|j|d�q
WdS)Nzfrom %s import *zCannot handle star imports)r�r#)rr�rPrrrr�_s
zTest_urllib.test_starcCs<d}d}|j||�d}d}|j||�dS)Nz6
def foo():
    from urllib import urlencode, urlopen
zZ
def foo():
    from urllib.parse import urlencode
    from urllib.request import urlopen
zB
def foo():
    other()
    from urllib import urlencode, urlopen
zf
def foo():
    other()
    from urllib.parse import urlencode
    from urllib.request import urlopen
)r)rr6r7rrr�
test_indenteddszTest_urllib.test_indentedc		Cs�x�|jj�D]�\}}x�|D]�\}}x�|D]�}djdd�|j|D��}d|||f}d|||f}|j||�d|||||f}d|||||f}|j||�q6Wq#WqWdS)Nz, cSsg|]\}}|�qSrr)r'r0Zmemsrrrr)�s	z8Test_urllib.test_import_module_usage.<locals>.<listcomp>z^
                        import %s
                        foo(%s.%s)
                        z`
                        import %s
                        %s.%s(%s.%s)
                        )r�r�rr)	rr�r
r�rrZ
new_importr6r7rrrr�s
z$Test_urllib.test_import_module_usageN)r2r&r3rZfixes.fix_urllibr�r�r�r�r�r�r�rr�rrrrr+src@sjeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�
Test_input�inputcCs<d}d}|j||�d}d}|j||�dS)Nzx =   input(   )zx =   eval(input(   ))zx = input(   ''   )zx = eval(input(   ''   )))r)rr6r7rrrre�sz#Test_input.test_prefix_preservationcCs d}d}|j||�dS)Nzx = input()  #  foozx = eval(input())  #  foo)r)rr6r7rrrr��sz Test_input.test_trailing_commentcCs=d}|j|�d}|j|�d}|j|�dS)Nzx = eval(input())zx = eval(input(''))zx = eval(input(foo(5) + 9)))r!)rrPrrrrm�s

zTest_input.test_idempotencycCs d}d}|j||�dS)Nzx = input()zx = eval(input()))r)rr6r7rrrr<�szTest_input.test_1cCs d}d}|j||�dS)Nz
x = input('')zx = eval(input('')))r)rr6r7rrrr=�szTest_input.test_2cCs d}d}|j||�dS)Nzx = input('prompt')zx = eval(input('prompt')))r)rr6r7rrrr>�szTest_input.test_3cCs d}d}|j||�dS)Nzx = input(foo(5) + 9)zx = eval(input(foo(5) + 9)))r)rr6r7rrrr?�szTest_input.test_4N)r2r&r3rrer�rmr<r=r>r?rrrrr�s	
rc@seZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*S)+�Test_tuple_paramsZtuple_paramscCsd}|j|�dS)Nzdef foo(): pass)r!)rrPrrrrQ�sz"Test_tuple_params.test_unchanged_1cCsd}|j|�dS)Nzdef foo(a, b, c): pass)r!)rrPrrrrR�sz"Test_tuple_params.test_unchanged_2cCsd}|j|�dS)Nzdef foo(a=3, b=4, c=5): pass)r!)rrPrrrrS�sz"Test_tuple_params.test_unchanged_3cCs d}d}|j||�dS)Nz8
            def foo(((a, b), c)):
                x = 5zn
            def foo(xxx_todo_changeme):
                ((a, b), c) = xxx_todo_changeme
                x = 5)r)rr6r7rrrr<�szTest_tuple_params.test_1cCs d}d}|j||�dS)Nz;
            def foo(((a, b), c), d):
                x = 5zq
            def foo(xxx_todo_changeme, d):
                ((a, b), c) = xxx_todo_changeme
                x = 5)r)rr6r7rrrr=�szTest_tuple_params.test_2cCs d}d}|j||�dS)Nz@
            def foo(((a, b), c), d) -> e:
                x = 5zv
            def foo(xxx_todo_changeme, d) -> e:
                ((a, b), c) = xxx_todo_changeme
                x = 5)r)rr6r7rrrr>�szTest_tuple_params.test_3cCs d}d}|j||�dS)Nz/
            def foo(((a, b), c)): x = 5; y = 7zV
            def foo(xxx_todo_changeme): ((a, b), c) = xxx_todo_changeme; x = 5; y = 7)r)rr6r7rrr�test_semicolon�sz Test_tuple_params.test_semicoloncCs d}d}|j||�dS)NzE
            def foo(((a, b), c), d, e=5) -> z:
                x = 5z{
            def foo(xxx_todo_changeme, d, e=5) -> z:
                ((a, b), c) = xxx_todo_changeme
                x = 5)r)rr6r7rrr�
test_keywordsszTest_tuple_params.test_keywordscCs d}d}|j||�dS)NzR
            def foo(((a, b), c), d, *vargs, **kwargs) -> z:
                x = 5z�
            def foo(xxx_todo_changeme, d, *vargs, **kwargs) -> z:
                ((a, b), c) = xxx_todo_changeme
                x = 5)r)rr6r7rrr�test_varargsszTest_tuple_params.test_varargscCs d}d}|j||�dS)NzH
            def foo(((a, b), c), (d, e, f)) -> z:
                x = 5z�
            def foo(xxx_todo_changeme, xxx_todo_changeme1) -> z:
                ((a, b), c) = xxx_todo_changeme
                (d, e, f) = xxx_todo_changeme1
                x = 5)r)rr6r7rrr�test_multi_1szTest_tuple_params.test_multi_1cCs d}d}|j||�dS)NzQ
            def foo(x, ((a, b), c), d, (e, f, g), y) -> z:
                x = 5z�
            def foo(x, xxx_todo_changeme, d, xxx_todo_changeme1, y) -> z:
                ((a, b), c) = xxx_todo_changeme
                (e, f, g) = xxx_todo_changeme1
                x = 5)r)rr6r7rrr�test_multi_2"szTest_tuple_params.test_multi_2cCs d}d}|j||�dS)Nzj
            def foo(((a, b), c), (d, e, f)) -> z:
                "foo foo foo foo"
                x = 5z�
            def foo(xxx_todo_changeme, xxx_todo_changeme1) -> z:
                "foo foo foo foo"
                ((a, b), c) = xxx_todo_changeme
                (d, e, f) = xxx_todo_changeme1
                x = 5)r)rr6r7rrr�test_docstring.sz Test_tuple_params.test_docstringcCsd}|j|�dS)Nzlambda x: x + 5)r!)rrPrrr�test_lambda_no_change<sz'Test_tuple_params.test_lambda_no_changecCstd}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�dS)Nzlambda (x): x + 5zlambda x: x + 5zlambda(x): x + 5zlambda ((((x)))): x + 5zlambda((((x)))): x + 5)r)rr6r7rrr�test_lambda_parens_single_arg@sz/Test_tuple_params.test_lambda_parens_single_argcCstd}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�dS)Nzlambda (x, y): x + f(y)zlambda x_y: x_y[0] + f(x_y[1])zlambda(x, y): x + f(y)zlambda (((x, y))): x + f(y)zlambda(((x, y))): x + f(y))r)rr6r7rrr�test_lambda_simpleQsz$Test_tuple_params.test_lambda_simplecCs<d}d}|j||�d}d}|j||�dS)Nzlambda (x,): x + f(x)zlambda x1: x1[0] + f(x1[0])zlambda (((x,))): x + f(x))r)rr6r7rrr�test_lambda_one_tuplebsz'Test_tuple_params.test_lambda_one_tuplecCs d}d}|j||�dS)Nzlambda (x, y): x + x + f(x) + xz0lambda x_y: x_y[0] + x_y[0] + f(x_y[0]) + x_y[0])r)rr6r7rrr�test_lambda_simple_multi_useksz.Test_tuple_params.test_lambda_simple_multi_usecCs d}d}|j||�dS)Nzlambda (x, y): y + xzlambda x_y: x_y[1] + x_y[0])r)rr6r7rrr�test_lambda_simple_reversepsz,Test_tuple_params.test_lambda_simple_reversecCs<d}d}|j||�d}d}|j||�dS)Nzlambda (x, (y, z)): x + y + zz2lambda x_y_z: x_y_z[0] + x_y_z[1][0] + x_y_z[1][1]z!lambda (((x, (y, z)))): x + y + z)r)rr6r7rrr�test_lambda_nestedusz$Test_tuple_params.test_lambda_nestedcCs d}d}|j||�dS)Nz lambda (x, (y, z)): x + y + f(y)z5lambda x_y_z: x_y_z[0] + x_y_z[1][0] + f(x_y_z[1][0]))r)rr6r7rrr�test_lambda_nested_multi_use~sz.Test_tuple_params.test_lambda_nested_multi_useN)r2r&r3rrQrRrSr<r=r>rrrrrrrrrrr r!r"r#rrrrr�s*		rc@s=eZdZdZdddgZdd�Zdd�Zd	S)
�Test_methodattrsZmethodattrs�funcr�classcCs�x�|jD]x}d|}|dkr/d}n
d|}|j||�d|}|dkrhd}n
d|}|j||�q
WdS)Nza.im_%sr&za.__self__.__class__za.__%s__zself.foo.im_%s.foo_barz#self.foo.__self__.__class__.foo_barzself.foo.__%s__.foo_bar)r�r)rr�r6r7rrrr_�s
	

	
zTest_methodattrs.testcCs]xV|jD]K}d|}|j|�d|}|j|�d|}|j|�q
WdS)Nzfoo(im_%s + 5)z
f(foo.__%s__)zf(foo.__%s__.foo))r�r!)rr�rPrrrrb�s




zTest_methodattrs.test_unchangedN)r2r&r3rr�r_rbrrrrr$�sr$c@s2eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dLdM�Z)dNdO�Z*dPdQ�Z+dRdS�Z,dTdU�Z-dVdW�Z.dXdY�Z/dZd[�Z0d\S)]�	Test_next�nextcCs d}d}|j||�dS)Nz	it.next()znext(it))r)rr6r7rrrr<�szTest_next.test_1cCs d}d}|j||�dS)Nza.b.c.d.next()z
next(a.b.c.d))r)rr6r7rrrr=�szTest_next.test_2cCs d}d}|j||�dS)Nz(a + b).next()z
next((a + b)))r)rr6r7rrrr>�szTest_next.test_3cCs d}d}|j||�dS)Nz
a().next()z	next(a()))r)rr6r7rrrr?�szTest_next.test_4cCs d}d}|j||�dS)Nza().next() + bz
next(a()) + b)r)rr6r7rrrr@�szTest_next.test_5cCs d}d}|j||�dS)Nzc(      a().next() + b)zc(      next(a()) + b))r)rr6r7rrrrA�szTest_next.test_6cCs d}d}|j||�dS)NzU
            for a in b:
                foo(a)
                a.next()
            zT
            for a in b:
                foo(a)
                next(a)
            )r)rr6r7rrr�test_prefix_preservation_1�sz$Test_next.test_prefix_preservation_1cCs d}d}|j||�dS)Nzq
            for a in b:
                foo(a) # abc
                # def
                a.next()
            zp
            for a in b:
                foo(a) # abc
                # def
                next(a)
            )r)rr6r7rrr�test_prefix_preservation_2�sz$Test_next.test_prefix_preservation_2cCs&d}d}|j||dd�dS)Nzj
            next = 5
            for a in b:
                foo(a)
                a.next()
            zn
            next = 5
            for a in b:
                foo(a)
                a.__next__()
            rT)r)rr6r7rrr�test_prefix_preservation_3�sz$Test_next.test_prefix_preservation_3cCs&d}d}|j||dd�dS)Nz�
            next = 5
            for a in b:
                foo(a) # abc
                # def
                a.next()
            z�
            next = 5
            for a in b:
                foo(a) # abc
                # def
                a.__next__()
            rT)r)rr6r7rrr�test_prefix_preservation_4�sz$Test_next.test_prefix_preservation_4cCs&d}d}|j||dd�dS)Nzz
            next = 5
            for a in b:
                foo(foo(a), # abc
                    a.next())
            z~
            next = 5
            for a in b:
                foo(foo(a), # abc
                    a.__next__())
            rT)r)rr6r7rrr�test_prefix_preservation_5	sz$Test_next.test_prefix_preservation_5cCs d}d}|j||�dS)Nze
            for a in b:
                foo(foo(a), # abc
                    a.next())
            zd
            for a in b:
                foo(foo(a), # abc
                    next(a))
            )r)rr6r7rrr�test_prefix_preservation_6	sz$Test_next.test_prefix_preservation_6cCs d}d}|j||�dS)Nz[
            class A:
                def next(self):
                    pass
            z_
            class A:
                def __next__(self):
                    pass
            )r)rr6r7rrr�
test_method_1	szTest_next.test_method_1cCs d}d}|j||�dS)Nzc
            class A(object):
                def next(self):
                    pass
            zg
            class A(object):
                def __next__(self):
                    pass
            )r)rr6r7rrr�
test_method_2)	szTest_next.test_method_2cCs d}d}|j||�dS)NzX
            class A:
                def next(x):
                    pass
            z\
            class A:
                def __next__(x):
                    pass
            )r)rr6r7rrr�
test_method_36	szTest_next.test_method_3cCs d}d}|j||�dS)Nz�
            class A:
                def __init__(self, foo):
                    self.foo = foo

                def next(self):
                    pass

                def __iter__(self):
                    return self
            z�
            class A:
                def __init__(self, foo):
                    self.foo = foo

                def __next__(self):
                    pass

                def __iter__(self):
                    return self
            )r)rr6r7rrr�
test_method_4C	szTest_next.test_method_4cCsd}|j|�dS)Nza
            class A:
                def next(self, a, b):
                    pass
            )r!)rrPrrr�test_method_unchanged\	szTest_next.test_method_unchangedcCsd}|j|d�dS)Nzy
            next = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_assign_simpled	sz&Test_next.test_shadowing_assign_simplecCsd}|j|d�dS)Nz~
            (next, a) = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_assign_tuple_1n	sz'Test_next.test_shadowing_assign_tuple_1cCsd}|j|d�dS)Nz�
            (a, (b, (next, c)), a) = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_assign_tuple_2x	sz'Test_next.test_shadowing_assign_tuple_2cCsd}|j|d�dS)Nz~
            [next, a] = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_assign_list_1�	sz&Test_next.test_shadowing_assign_list_1cCsd}|j|d�dS)Nz�
            [a, [b, [next, c]], a] = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_assign_list_2�	sz&Test_next.test_shadowing_assign_list_2cCsd}|j|d�dS)Nz�
            def foo():
                __builtin__.next = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_builtin_assign�	szTest_next.test_builtin_assigncCsd}|j|d�dS)Nz�
            def foo():
                (a, __builtin__.next) = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_builtin_assign_in_tuple�	sz&Test_next.test_builtin_assign_in_tuplecCsd}|j|d�dS)Nz�
            def foo():
                [a, __builtin__.next] = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_builtin_assign_in_list�	sz%Test_next.test_builtin_assign_in_listcCsd}|j|�dS)Nz�
            def foo():
                A.next = foo

            class A:
                def next(self, a, b):
                    pass
            )r!)rrPrrr�test_assign_to_next�	szTest_next.test_assign_to_nextcCsd}|j|�dS)Nz�
            def foo():
                (a, A.next) = foo

            class A:
                def next(self, a, b):
                    pass
            )r!)rrPrrr�test_assign_to_next_in_tuple�	sz&Test_next.test_assign_to_next_in_tuplecCsd}|j|�dS)Nz�
            def foo():
                [a, A.next] = foo

            class A:
                def next(self, a, b):
                    pass
            )r!)rrPrrr�test_assign_to_next_in_list�	sz%Test_next.test_assign_to_next_in_listcCsd}|j|d�dS)Nz�
            import foo.bar as next

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_import_1�	sz!Test_next.test_shadowing_import_1cCsd}|j|d�dS)Nz�
            import bar, bar.foo as next

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_import_2�	sz!Test_next.test_shadowing_import_2cCsd}|j|d�dS)Nz�
            import bar, bar.foo as next, baz

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_import_3�	sz!Test_next.test_shadowing_import_3cCsd}|j|d�dS)Nz�
            from x import next

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_import_from_1�	sz&Test_next.test_shadowing_import_from_1cCsd}|j|d�dS)Nz�
            from x.a import next

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_import_from_2
sz&Test_next.test_shadowing_import_from_2cCsd}|j|d�dS)Nz�
            from x import a, next, b

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_import_from_3

sz&Test_next.test_shadowing_import_from_3cCsd}|j|d�dS)Nz�
            from x.a import a, next, b

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_import_from_4
sz&Test_next.test_shadowing_import_from_4cCsd}|j|d�dS)Nz�
            def next(a):
                pass

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_funcdef_1
sz"Test_next.test_shadowing_funcdef_1cCs#d}d}|j||d�dS)Nz�
            def next(a):
                pass

            class A:
                def next(self):
                    pass

            it.next()
            z�
            def next(a):
                pass

            class A:
                def __next__(self):
                    pass

            it.__next__()
            z)Calls to builtin next() possibly shadowed)r")rr6r7rrr�test_shadowing_funcdef_2)
s

z"Test_next.test_shadowing_funcdef_2cCsd}|j|d�dS)NzW
            def f():
                global next
                next = 5
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_global_1@
sz!Test_next.test_shadowing_global_1cCsd}|j|d�dS)Nz]
            def f():
                global a, next, b
                next = 5
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_global_2H
sz!Test_next.test_shadowing_global_2cCsd}|j|d�dS)Nze
            for next in it():
                pass

            b = 5
            c = 6
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_for_simpleP
sz#Test_next.test_shadowing_for_simplecCsd}|j|d�dS)Nzh
            for next, b in it():
                pass

            b = 5
            c = 6
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_for_tuple_1Z
sz$Test_next.test_shadowing_for_tuple_1cCsd}|j|d�dS)Nzp
            for a, (next, c), b in it():
                pass

            b = 5
            c = 6
            z)Calls to builtin next() possibly shadowed)r#)rrPrrr�test_shadowing_for_tuple_2d
sz$Test_next.test_shadowing_for_tuple_2cCs d}d}|j||�dS)Nzgnext = g.nextzgnext = g.__next__)r)rr6r7rrr�test_noncall_access_1n
szTest_next.test_noncall_access_1cCs d}d}|j||�dS)Nz
f(g.next + 5)zf(g.__next__ + 5))r)rr6r7rrr�test_noncall_access_2s
szTest_next.test_noncall_access_2cCs d}d}|j||�dS)Nzf(g().next + 5)zf(g().__next__ + 5))r)rr6r7rrr�test_noncall_access_3x
szTest_next.test_noncall_access_3N)1r2r&r3rr<r=r>r?r@rAr)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrErFrGrHrIrJrKrLrMrNrOrrrrr'�s\



















r'c@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�Test_nonzeroZnonzerocCs d}d}|j||�dS)Nzb
            class A:
                def __nonzero__(self):
                    pass
            z_
            class A:
                def __bool__(self):
                    pass
            )r)rr6r7rrrr<�
szTest_nonzero.test_1cCs d}d}|j||�dS)Nzj
            class A(object):
                def __nonzero__(self):
                    pass
            zg
            class A(object):
                def __bool__(self):
                    pass
            )r)rr6r7rrrr=�
szTest_nonzero.test_2cCsd}|j|�dS)Nzg
            class A(object):
                def __bool__(self):
                    pass
            )r!)rrPrrrrQ�
szTest_nonzero.test_unchanged_1cCsd}|j|�dS)Nzm
            class A(object):
                def __nonzero__(self, a):
                    pass
            )r!)rrPrrrrR�
szTest_nonzero.test_unchanged_2cCsd}|j|�dS)NzE
            def __nonzero__(self):
                pass
            )r!)rrPrrr�test_unchanged_func�
sz Test_nonzero.test_unchanged_funcN)	r2r&r3rr<r=rQrRrQrrrrrP}
s

rPc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�Test_numliteralsZnumliteralscCs d}d}|j||�dS)NZ0755�0o755)r)rr6r7rrr�test_octal_1�
szTest_numliterals.test_octal_1cCs d}d}|j||�dS)Nza = 12Lza = 12)r)rr6r7rrr�test_long_int_1�
sz Test_numliterals.test_long_int_1cCs d}d}|j||�dS)Nza = 12lza = 12)r)rr6r7rrr�test_long_int_2�
sz Test_numliterals.test_long_int_2cCs d}d}|j||�dS)Nz	b = 0x12lzb = 0x12)r)rr6r7rrr�
test_long_hex�
szTest_numliterals.test_long_hexcCs<d}d}|j||�d}d}|j||�dS)Nzb =   0x12Lz
b =   0x12zb = 0755 # spamzb = 0o755 # spam)r)rr6r7rrr�test_comments_and_spacing�
sz*Test_numliterals.test_comments_and_spacingcCsd}|j|�dS)N�5)r!)rrPrrr�test_unchanged_int�
sz#Test_numliterals.test_unchanged_intcCsd}|j|�dS)Nz5.0)r!)rrPrrr�test_unchanged_float�
sz%Test_numliterals.test_unchanged_floatcCsd}|j|�dS)NrS)r!)rrPrrr�test_unchanged_octal�
sz%Test_numliterals.test_unchanged_octalcCsd}|j|�dS)NZ0xABC)r!)rrPrrr�test_unchanged_hex�
sz#Test_numliterals.test_unchanged_hexcCsd}|j|�dS)Nz5.0e10)r!)rrPrrr�test_unchanged_exp�
sz#Test_numliterals.test_unchanged_expcCsd}|j|�dS)Nz5 + 4j)r!)rrPrrr�test_unchanged_complex_int�
sz+Test_numliterals.test_unchanged_complex_intcCsd}|j|�dS)Nz
5.4 + 4.9j)r!)rrPrrr�test_unchanged_complex_float�
sz-Test_numliterals.test_unchanged_complex_floatcCs*d}|j|�d}|j|�dS)NZ4jz4.4j)r!)rrPrrr�test_unchanged_complex_bare�
s
z,Test_numliterals.test_unchanged_complex_bareN)r2r&r3rrTrUrVrWrXrZr[r\r]r^r_r`rarrrrrR�
s	rRc@sReZdZdZddiZdd�Zdd�Zd	d
�Zdd�Zd
S)�Test_renames�renames�sys�maxint�maxsizecCswxpt|jj��D]Y\}\}}d||f}d||f}|j||�d|}|j|�qWdS)Nzfrom %s import %szfrom foo import %s)�listr�r�rr!)r�modr�r�r6r7rPrrrr��
s(
zTest_renames.test_import_fromcCs`xYt|jj��D]B\}\}}d||f}d||f}|j||�qWdS)Nzfrom %s import %s as foo_bar)rgr�r�r)rrhr�r�r6r7rrrr�s(z Test_renames.test_import_from_ascCslxet|jj��D]N\}\}}d||||f}d||||f}|j||�qWdS)NzJ
                import %s
                foo(%s, %s.%s)
                )rgr�r�r)rrhr�r�r6r7rrrr�s(z%Test_renames.test_import_module_usagecCslxet|jj��D]N\}\}}d||||f}d||||f}|j||�qWdS)NzO
                from %s import %s
                foo(%s, %s)
                )rgr�r�r)rrhr�r�r6r7rrr�XXX_test_from_import_usages(z'Test_renames.XXX_test_from_import_usageN)rerf)	r2r&r3rr�r�r�r�rirrrrrb�
s	rbc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�Test_unicodeZunicodecCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nzunicode( x)zstr( x)z unicode(x )z str(x )z u'h'z 'h')r)rr6r7rrr�test_whitespace$szTest_unicode.test_whitespacecCs d}d}|j||�dS)Nzunicode(x, y, z)zstr(x, y, z))r)rr6r7rrr�test_unicode_call1szTest_unicode.test_unicode_callcCs d}d}|j||�dS)Nzunichr(u'h')zchr('h'))r)rr6r7rrr�test_unichr6szTest_unicode.test_unichrcCs d}d}|j||�dS)Nzu"x"z"x")r)rr6r7rrr�test_unicode_literal_1;sz#Test_unicode.test_unicode_literal_1cCs d}d}|j||�dS)Nzur'x'zr'x')r)rr6r7rrr�test_unicode_literal_2@sz#Test_unicode.test_unicode_literal_2cCs d}d}|j||�dS)Nz
UR'''x''' z	R'''x''' )r)rr6r7rrr�test_unicode_literal_3Esz#Test_unicode.test_unicode_literal_3cCs<d}d}|j||�d}d}|j||�dS)Nz'\\\u20ac\U0001d121\\u20ac'z'\\\\u20ac\\U0001d121\\u20ac'zr'\\\u20ac\U0001d121\\u20ac')r)rr6r7rrr�test_native_literal_escape_uJsz)Test_unicode.test_native_literal_escape_ucCs<d}d}|j||�d}d}|j||�dS)Nzb'\\\u20ac\U0001d121\\u20ac'zbr'\\\u20ac\U0001d121\\u20ac')r)rr6r7rrr�test_bytes_literal_escape_uSsz(Test_unicode.test_bytes_literal_escape_ucCs<d}d}|j||�d}d}|j||�dS)Nzu'\\\u20ac\U0001d121\\u20ac'z'\\\u20ac\U0001d121\\u20ac'zur'\\\u20ac\U0001d121\\u20ac'zr'\\\u20ac\U0001d121\\u20ac')r)rr6r7rrr�test_unicode_literal_escape_u\sz*Test_unicode.test_unicode_literal_escape_ucCsRd}|d}|d}|j||�|d}|d}|j||�dS)Nz(from __future__ import unicode_literals
z'\\\u20ac\U0001d121\\u20ac'zr'\\\u20ac\U0001d121\\u20ac')r)r�fr6r7rrr�$test_native_unicode_literal_escape_ues



z1Test_unicode.test_native_unicode_literal_escape_uN)r2r&r3rrkrlrmrnrorprqrrrsrurrrrrj!s
			rjc@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Test_filter�filtercCs<d}d}|j||�d}d}|j||�dS)Nz#x =   filter(    foo,     'abc'   )z)x =   list(filter(    foo,     'abc'   ))zx =   filter(  None , 'abc'  )z x =   [_f for _f in 'abc' if _f])r)rr6r7rrrressz$Test_filter.test_prefix_preservationcCstd}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�dS)Nzx = filter(None, 'abc')zx = [_f for _f in 'abc' if _f]zx = len(filter(f, 'abc'))zx = len(list(filter(f, 'abc')))z)x = filter(lambda x: x%2 == 0, range(10))z&x = [x for x in range(10) if x%2 == 0]z+x = filter(lambda (x): x%2 == 0, range(10)))r)rr6r7rrr�test_filter_basic|szTest_filter.test_filter_basiccCsmd}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d	}|j|�d
}|j|�d}|j|�d}|j|�d
}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�dS)Nzb.join(filter(f, 'abc'))z#(a + foo(5)).join(filter(f, 'abc'))ziter(filter(f, 'abc'))zlist(filter(f, 'abc'))zlist(filter(f, 'abc'))[0]zset(filter(f, 'abc'))zset(filter(f, 'abc')).pop()ztuple(filter(f, 'abc'))zany(filter(f, 'abc'))zall(filter(f, 'abc'))zsum(filter(f, 'abc'))zsorted(filter(f, 'abc'))z"sorted(filter(f, 'abc'), key=blah)z%sorted(filter(f, 'abc'), key=blah)[0]zenumerate(filter(f, 'abc'))z$enumerate(filter(f, 'abc'), start=1)zfor i in filter(f, 'abc'): passz[x for x in filter(f, 'abc')]z(x for x in filter(f, 'abc')))r!)rr7rrr�test_filter_nochange�sL

















z Test_filter.test_filter_nochangecCsFd}|j|�d}d}|j||�d}|j|�dS)Nz:from future_builtins import spam, filter; filter(f, 'ham')z6from future_builtins import spam; x = filter(f, 'abc')z<from future_builtins import spam; x = list(filter(f, 'abc'))z/from future_builtins import *; filter(f, 'ham'))r!r)rr7r6rrr�test_future_builtins�s
z Test_filter.test_future_builtinsN)r2r&r3rrerxryrzrrrrrvps
	(rvcspeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
�S)�Test_maprcs1|jd||�tt|�j||�dS)Nz!from future_builtins import map; )r!r�r{r)rr6r7)r%rrr�szTest_map.checkcCs d}d}|j||�dS)Nzx =    map(   f,    'abc'   )z#x =    list(map(   f,    'abc'   )))r)rr6r7rrrre�sz!Test_map.test_prefix_preservationcCs d}d}|j||�dS)Nzx = map(f, 'abc')   #   fooz!x = list(map(f, 'abc'))   #   foo)r)rr6r7rrrr��szTest_map.test_trailing_commentcCsd}|j|d�dS)Nzx = map(None, a, b, c)z5cannot convert map(None, ...) with multiple arguments)r#)rrPrrr�!test_None_with_multiple_arguments�sz*Test_map.test_None_with_multiple_argumentscCs�d}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�d	}d}|j||�d
}d}|j||d�dS)
Nzx = map(f, 'abc')zx = list(map(f, 'abc'))zx = len(map(f, 'abc', 'def'))z#x = len(list(map(f, 'abc', 'def')))zx = map(None, 'abc')zx = list('abc')z x = map(lambda x: x+1, range(4))zx = [x+1 for x in range(4)]z"x = map(lambda (x): x+1, range(4))zG
            foo()
            # foo
            map(f, x)
            zM
            foo()
            # foo
            list(map(f, x))
            zYou should use a for loop here)rr")rr6r7rrr�test_map_basic�s$zTest_map.test_map_basiccCsmd}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d	}|j|�d
}|j|�d}|j|�d}|j|�d
}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�dS)Nzb.join(map(f, 'abc'))z (a + foo(5)).join(map(f, 'abc'))ziter(map(f, 'abc'))zlist(map(f, 'abc'))zlist(map(f, 'abc'))[0]zset(map(f, 'abc'))zset(map(f, 'abc')).pop()ztuple(map(f, 'abc'))zany(map(f, 'abc'))zall(map(f, 'abc'))zsum(map(f, 'abc'))zsorted(map(f, 'abc'))zsorted(map(f, 'abc'), key=blah)z"sorted(map(f, 'abc'), key=blah)[0]zenumerate(map(f, 'abc'))z!enumerate(map(f, 'abc'), start=1)zfor i in map(f, 'abc'): passz[x for x in map(f, 'abc')]z(x for x in map(f, 'abc')))r!)rr7rrr�test_map_nochangesL

















zTest_map.test_map_nochangecCsFd}|j|�d}d}|j||�d}|j|�dS)Nz:from future_builtins import spam, map, eggs; map(f, 'ham')z9from future_builtins import spam, eggs; x = map(f, 'abc')z?from future_builtins import spam, eggs; x = list(map(f, 'abc'))z,from future_builtins import *; map(f, 'ham'))r!r)rr7r6rrrrz+s
zTest_map.test_future_builtins)r2r&r3rrrer�r|r}r~rzrr)r%rr{�s'(r{csLeZdZdZ�fdd�Zdd�Zdd�Zdd	�Z�S)
�Test_zip�zipcs1|jd||�tt|�j||�dS)Nz!from future_builtins import zip; )r!r�rr)rr6r7)r%rrr9szTest_zip.checkcCs<d}d}|j||�d}d}|j||�dS)Nzx = zip(a, b, c)zx = list(zip(a, b, c))zx = len(zip(a, b))zx = len(list(zip(a, b))))r)rr6r7rrr�test_zip_basic=szTest_zip.test_zip_basiccCsmd}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d	}|j|�d
}|j|�d}|j|�d}|j|�d
}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�dS)Nzb.join(zip(a, b))z(a + foo(5)).join(zip(a, b))ziter(zip(a, b))zlist(zip(a, b))zlist(zip(a, b))[0]zset(zip(a, b))zset(zip(a, b)).pop()ztuple(zip(a, b))zany(zip(a, b))zall(zip(a, b))zsum(zip(a, b))zsorted(zip(a, b))zsorted(zip(a, b), key=blah)zsorted(zip(a, b), key=blah)[0]zenumerate(zip(a, b))zenumerate(zip(a, b), start=1)zfor i in zip(a, b): passz[x for x in zip(a, b)]z(x for x in zip(a, b)))r!)rr7rrr�test_zip_nochangeFsL

















zTest_zip.test_zip_nochangecCsFd}|j|�d}d}|j||�d}|j|�dS)Nz6from future_builtins import spam, zip, eggs; zip(a, b)z5from future_builtins import spam, eggs; x = zip(a, b)z;from future_builtins import spam, eggs; x = list(zip(a, b))z(from future_builtins import *; zip(a, b))r!r)rr7r6rrrrzns
zTest_zip.test_future_builtins)r2r&r3rrr�r�rzrr)r%rr6s
	(rc@s"eZdZdZdd�ZdS)�Test_standarderrorZ
standarderrorcCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nzx =    StandardError()zx =    Exception()zx = StandardError(a, b, c)zx = Exception(a, b, c)zf(2 + StandardError(a, b, c))zf(2 + Exception(a, b, c)))r)rr6r7rrrr_|szTest_standarderror.testN)r2r&r3rr_rrrrr�ysr�c@s"eZdZdZdd�ZdS)�
Test_types�typescCs�d}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�d	}d}|j||�d
}d}|j||�dS)Nztypes.StringType�bytesztypes.DictTyper�ztypes . IntType�intztypes.ListTypergztypes.LongTypeztypes.NoneTypez
type(None))r)rr6r7rrr�test_basic_types_convert�s$z#Test_types.test_basic_types_convertN)r2r&r3rr�rrrrr��sr�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&S)'�Test_idiomsZidiomscCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nzwhile 1: foo()zwhile True: foo()zwhile   1: foo()zwhile   True: foo()z8
            while 1:
                foo()
            z;
            while True:
                foo()
            )r)rr6r7rrr�
test_while�szTest_idioms.test_whilecCsPd}|j|�d}|j|�d}|j|�d}|j|�dS)Nzwhile 11: foo()zwhile 0: foo()zwhile foo(): foo()zwhile []: foo())r!)rrPrrr�test_while_unchanged�s


z Test_idioms.test_while_unchangedcCs<d}d}|j||�d}d}|j||�dS)Nztype(x) == Tzisinstance(x, T)zif   type(x) == T: passzif   isinstance(x, T): pass)r)rr6r7rrr�test_eq_simple�szTest_idioms.test_eq_simplecCs<d}d}|j||�d}d}|j||�dS)NzT == type(x)zisinstance(x, T)zif   T == type(x): passzif   isinstance(x, T): pass)r)rr6r7rrr�test_eq_reverse�szTest_idioms.test_eq_reversecCs<d}d}|j||�d}d}|j||�dS)Nztype(x+y) == d.get('T')zisinstance(x+y, d.get('T'))ztype(   x  +  y) == d.get('T')zisinstance(x  +  y, d.get('T')))r)rr6r7rrr�test_eq_expression�szTest_idioms.test_eq_expressioncCs<d}d}|j||�d}d}|j||�dS)Nztype(x) is Tzisinstance(x, T)zif   type(x) is T: passzif   isinstance(x, T): pass)r)rr6r7rrr�test_is_simple�szTest_idioms.test_is_simplecCs<d}d}|j||�d}d}|j||�dS)NzT is type(x)zisinstance(x, T)zif   T is type(x): passzif   isinstance(x, T): pass)r)rr6r7rrr�test_is_reverse�szTest_idioms.test_is_reversecCs<d}d}|j||�d}d}|j||�dS)Nztype(x+y) is d.get('T')zisinstance(x+y, d.get('T'))ztype(   x  +  y) is d.get('T')zisinstance(x  +  y, d.get('T')))r)rr6r7rrr�test_is_expression�szTest_idioms.test_is_expressioncCs<d}d}|j||�d}d}|j||�dS)Nztype(x) is not Tznot isinstance(x, T)zif   type(x) is not T: passzif   not isinstance(x, T): pass)r)rr6r7rrr�test_is_not_simple�szTest_idioms.test_is_not_simplecCs<d}d}|j||�d}d}|j||�dS)NzT is not type(x)znot isinstance(x, T)zif   T is not type(x): passzif   not isinstance(x, T): pass)r)rr6r7rrr�test_is_not_reverse
szTest_idioms.test_is_not_reversecCs<d}d}|j||�d}d}|j||�dS)Nztype(x+y) is not d.get('T')znot isinstance(x+y, d.get('T'))z"type(   x  +  y) is not d.get('T')z#not isinstance(x  +  y, d.get('T')))r)rr6r7rrr�test_is_not_expression
sz"Test_idioms.test_is_not_expressioncCs<d}d}|j||�d}d}|j||�dS)Nztype(x) != Tznot isinstance(x, T)zif   type(x) != T: passzif   not isinstance(x, T): pass)r)rr6r7rrr�test_ne_simple
szTest_idioms.test_ne_simplecCs<d}d}|j||�d}d}|j||�dS)NzT != type(x)znot isinstance(x, T)zif   T != type(x): passzif   not isinstance(x, T): pass)r)rr6r7rrr�test_ne_reverse"
szTest_idioms.test_ne_reversecCs<d}d}|j||�d}d}|j||�dS)Nztype(x+y) != d.get('T')znot isinstance(x+y, d.get('T'))ztype(   x  +  y) != d.get('T')z#not isinstance(x  +  y, d.get('T')))r)rr6r7rrr�test_ne_expression+
szTest_idioms.test_ne_expressioncCsd}|j|�dS)Nztype(x).__name__)r!)rr7rrr�test_type_unchanged4
szTest_idioms.test_type_unchangedcCs�d}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�d	}d
}|j||�d}d}|j||�d
}d}|j||�d}d}|j||�dS)NzM
            v = list(t)
            v.sort()
            foo(v)
            z:
            v = sorted(t)
            foo(v)
            zV
            v = list(foo(b) + d)
            v.sort()
            foo(v)
            zC
            v = sorted(foo(b) + d)
            foo(v)
            zn
            while x:
                v = list(t)
                v.sort()
                foo(v)
            zW
            while x:
                v = sorted(t)
                foo(v)
            z_
            v = list(t)
            # foo
            v.sort()
            foo(v)
            zL
            v = sorted(t)
            # foo
            foo(v)
            zP
            v = list(   t)
            v.sort()
            foo(v)
            z=
            v = sorted(   t)
            foo(v)
            zl
            try:
                m = list(s)
                m.sort()
            except: pass
            zU
            try:
                m = sorted(s)
            except: pass
            z�
            try:
                m = list(s)
                # foo
                m.sort()
            except: pass
            zk
            try:
                m = sorted(s)
                # foo
            except: pass
            zI
            m = list(s)
            # more comments
            m.sort()z6
            m = sorted(s)
            # more comments)r)rr6r7rrr�test_sort_list_call8
s0zTest_idioms.test_sort_list_callcCs�d}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�d	}d
}|j||�d}d}|j||�d
}d}|j||�dS)NzG
            v = t
            v.sort()
            foo(v)
            z:
            v = sorted(t)
            foo(v)
            zL
            v = foo(b)
            v.sort()
            foo(v)
            z?
            v = sorted(foo(b))
            foo(v)
            zN
            v = b.keys()
            v.sort()
            foo(v)
            zA
            v = sorted(b.keys())
            foo(v)
            zP
            v = foo(b) + d
            v.sort()
            foo(v)
            zC
            v = sorted(foo(b) + d)
            foo(v)
            zh
            while x:
                v = t
                v.sort()
                foo(v)
            zW
            while x:
                v = sorted(t)
                foo(v)
            zY
            v = t
            # foo
            v.sort()
            foo(v)
            zL
            v = sorted(t)
            # foo
            foo(v)
            zI
            v =   t
            v.sort()
            foo(v)
            z<
            v =   sorted(t)
            foo(v)
            )r)rr6r7rrr�test_sort_simple_expr�
s*z!Test_idioms.test_sort_simple_exprcCs*d}|j|�d}|j|�dS)NzM
            v = list(t)
            w.sort()
            foo(w)
            zN
            v = list(t)
            v.sort(u)
            foo(v)
            )r!)rrPrrr�test_sort_unchanged�
s
zTest_idioms.test_sort_unchangedN)r2r&r3rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��s&
												dRr�c@s"eZdZdZdd�ZdS)�Test_basestringZ
basestringcCs d}d}|j||�dS)Nzisinstance(x, basestring)zisinstance(x, str))r)rr6r7rrr�test_basestringszTest_basestring.test_basestringN)r2r&r3rr�rrrrr��
sr�c@s.eZdZdZdd�Zdd�ZdS)�Test_buffer�buffercCs d}d}|j||�dS)Nz
x = buffer(y)zx = memoryview(y))r)rr6r7rrr�test_bufferszTest_buffer.test_buffercCs d}d}|j||�dS)Nzbuffer(y)[4:5]zmemoryview(y)[4:5])r)rr6r7rrr�test_slicing
szTest_buffer.test_slicingN)r2r&r3rr�r�rrrrr�sr�c@s.eZdZdZdd�Zdd�ZdS)�Test_futureZfuturecCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nzfrom __future__ import bracesrz'# comment
from __future__ import bracesz
# comment
z'from __future__ import braces
# commentz

# comment)r)rr6r7rrr�test_futureszTest_future.test_futurecCs|jd�dS)Nrl)r1)rrrr�test_run_order"szTest_future.test_run_orderN)r2r&r3rr�r�rrrrr�s
r�c@sveZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�Test_itertools�	itertoolscCsRxKdD]C}x:dD]2}||d|}||}|j||�qWqWdS)	N�
itertools.rrrwr��i)r�r)rrwr�)r)rrrr�rtr6r7rrr�checkall(s



zTest_itertools.checkallcCs d}d}|j||�dS)Nzitertools.izip(a, b)z	zip(a, b))r)rr6r7rrr�test_02szTest_itertools.test_0cCs d}d}|j||�dS)Nz%s(f, a))r�)rr6r7rrrr<9szTest_itertools.test_1cCs<d}d}|j||�d}d}|j||�dS)Nzitertools.ifilterfalse(a, b)zitertools.filterfalse(a, b)zitertools.izip_longest(a, b)zitertools.zip_longest(a, b))r)rr6r7rrr�test_qualified>szTest_itertools.test_qualifiedcCs<d}d}|j||�d}d}|j||�dS)Nzifilterfalse(a, b)zfilterfalse(a, b)zizip_longest(a, b)zzip_longest(a, b))r)rr6r7rrrr=GszTest_itertools.test_2cCs d}d}|j||�dS)Nz    %s(f, a))r�)rr6r7rrrr[PszTest_itertools.test_space_1cCs<d}d}|j||�d}d}|j||�dS)Nz     itertools.ifilterfalse(a, b)z    itertools.filterfalse(a, b)z     itertools.izip_longest(a, b)z    itertools.zip_longest(a, b))r)rr6r7rrrr\UszTest_itertools.test_space_2cCs|jddd�dS)Nrr�rw)r1)rrrrr�^szTest_itertools.test_run_orderN)r2r&r3rr�r�r<r�r=r[r\r�rrrrr�%s
			r�c@sjeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�Test_itertools_importsZitertools_importscCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nz%from itertools import imap, izip, foozfrom itertools import fooz*from itertools import bar, imap, izip, foozfrom itertools import bar, fooz'from itertools import chain, imap, izipzfrom itertools import chain)r)rr6r7rrr�test_reducedesz#Test_itertools_imports.test_reducedcCs d}d}|j||�dS)Nz%#foo
from itertools import imap, izipz#foo
)r)rr6r7rrr�
test_commentsrsz$Test_itertools_imports.test_commentscCs<d}d}|j||�d}d}|j||�dS)Nz from itertools import imap, iziprzfrom itertools import izip)r)rr6r7rrr�	test_nonewsz Test_itertools_imports.test_nonecCs�d}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�d}|j|�dS)Nz-from itertools import izip, bar as bang, imapz!from itertools import bar as bangz-from itertools import izip as _zip, imap, barzfrom itertools import barz"from itertools import imap as _maprz0from itertools import imap as _map, izip as _zip)rr!)rr6r7rPrrr�test_import_as�sz%Test_itertools_imports.test_import_ascCs�x�d	D]�}d|f}d|f}|j||�d|f}d|f}|j||�d|f}d|f}|j||�qWdS)
N�filterfalse�zip_longestzfrom itertools import i%szfrom itertools import %sz$from itertools import imap, i%s, foozfrom itertools import %s, fooz#from itertools import bar, i%s, fooz"from itertools import bar, %s, foo)r�r�)r)rr�r6r7rrr�test_ifilter_and_zip_longest�s






z3Test_itertools_imports.test_ifilter_and_zip_longestcCsd}|j|�dS)Nzfrom itertools import *)r!)rrPrrr�test_import_star�sz'Test_itertools_imports.test_import_starcCsd}|j|�dS)Nzfrom itertools import foo)r!)rrPrrrrb�sz%Test_itertools_imports.test_unchangedN)r2r&r3rr�r�r�r�r�r�rbrrrrr�bs
	r�cseZdZdZ�fdd�Zdd�Z�fdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Z�S)(�Test_importr	cs`tt��j�g�_t��_d�_�fdd�}ddlm}||_	dS)NTcs&�jj|��jp%|�jkS)N)�
files_checkedr�
always_exists�
present_files)r�)rrr�fake_exists�sz&Test_import.setUp.<locals>.fake_existsr)�
fix_import)
r�r�rr��setr�r��
lib2to3.fixesr��exists)rr�r�)r%)rrr�s		zTest_import.setUpcCs#ddlm}tjj|_dS)Nr)r�)r�r��os�pathr�)rr�rrr�tearDown�szTest_import.tearDowncsEd|_tt|�j||�d|_tt|�j|�dS)NTF)r�r�r�rr!)rr6r7)r%rr�
check_both�s		zTest_import.check_bothcs
dd�}d|_tdg�|_dtjjdddd	f}|d
�d|d�f}x�|D]��g|_�|_|jd
�tjj	��r�tjj	��d�nd�t�fdd�|D��}|j
d�|jt|j�|�qgWdS)NcSstjjj|jd��S)N�/)r�r��pathsepr�split)r�rrr�p�sz)Test_import.test_files_checked.<locals>.pFz__init__.pyz.pyz.pycz.soz.slz.pydz
/spam/eggs.pyzni.pyz../../shrubbery.pyz
import jamz/jamZjamc3s|]}�|VqdS)Nr)r'Zext)r�rr�	<genexpr>�sz1Test_import.test_files_checked.<locals>.<genexpr>)r�r�r�r�r��sepr�rr!�dirname�addr)rr�Zexpected_extensionsZ
names_to_testZexpected_checksr)r�r�test_files_checked�s	
		

zTest_import.test_files_checkedcCs2d}d|_tdg�|_|j|�dS)Nz
import barFzbar.py)r�r�r�r!)rrPrrr�test_not_in_package�s	zTest_import.test_not_in_packagecCs5d}d|_tddg�|_|j|�dS)Nz1from __future__ import absolute_import
import barFz__init__.pyzbar.py)r�r�r�r!)rrPrrr�!test_with_absolute_import_enabled�s	z-Test_import.test_with_absolute_import_enabledcCs>d}d}d|_tddg�|_|j||�dS)Nz
import barzfrom . import barFz__init__.pyzbar.py)r�r�r�r)rr6r7rrr�test_in_package�s
	zTest_import.test_in_packagecCsHd}d}d|_tddtjjg�|_|j||�dS)Nz
import barzfrom . import barFz__init__.pyZbar)r�r�r�r�r�r�r)rr6r7rrr�test_import_from_package�s
	z$Test_import.test_import_from_packagecCsd}|j|�dS)Nzfrom . import bar)r!)rrPrrr�test_already_relative_import�sz(Test_import.test_already_relative_importcCs d}d}|j||�dS)Nzimport bar # Foozfrom . import bar # Foo)r)rr6r7rrr�test_comments_and_indent�sz$Test_import.test_comments_and_indentcCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nzfrom foo import bar, bazzfrom .foo import bar, bazzfrom foo import barzfrom .foo import barzfrom foo import (bar, baz)zfrom .foo import (bar, baz))r�)rr6r7rrr�	test_fromszTest_import.test_fromcCs d}d}|j||�dS)Nzfrom green.eggs import hamzfrom .green.eggs import ham)r�)rr6r7rrr�test_dotted_fromszTest_import.test_dotted_fromcCs d}d}|j||�dS)Nz"from green.eggs import ham as spamz#from .green.eggs import ham as spam)r�)rr6r7rrr�test_from_asszTest_import.test_from_ascCstd}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�dS)	Nz
import foozfrom . import foozimport foo, barzfrom . import foo, barzimport foo, bar, xzfrom . import foo, bar, xzimport x, y, zzfrom . import x, y, z)r�)rr6r7rrr�test_importszTest_import.test_importcCs<d}d}|j||�d}d}|j||�dS)Nzimport foo as xzfrom . import foo as xzimport a as b, b as c, c as dz$from . import a as b, b as c, c as d)r�)rr6r7rrrr�*szTest_import.test_import_ascCs8d|_tddg�|_d}|j|d�dS)NFzfoo.pyz__init__.pyzimport foo, barz#absolute and local imports together)r�r�r�r#)rrPrrr�test_local_and_absolute3s	z#Test_import.test_local_and_absolutecCs d}d}|j||�dS)Nzimport foo.barzfrom . import foo.bar)r�)rr6r7rrr�test_dotted_import:szTest_import.test_dotted_importcCs d}d}|j||�dS)Nzimport foo.bar as bangzfrom . import foo.bar as bang)r�)rr6r7rrr�test_dotted_import_as?sz!Test_import.test_dotted_import_ascCs d}d}|j||�dS)Nz1
        # prefix
        import foo.bar
        z8
        # prefix
        from . import foo.bar
        )r�)rr6r7rrr�test_prefixDszTest_import.test_prefix)r2r&r3rrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr)r%rr��s(
	r�c@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�Test_set_literalZset_literalcCs�d}d}|j||�d}d}|j||�d}d}|j||�d}|j||�d}d}|j||�d	}|j||�d
}d}|j||�d}d
}|j||�d}d}|j||�dS)Nzset([1, 2, 3])z	{1, 2, 3}zset((1, 2, 3))z	set((1,))z{1}zset([1])zset((a, b))z{a, b}zset([a, b])zset((a*234, f(args=23)))z{a*234, f(args=23)}zset([a*23, f(23)])z
{a*23, f(23)}zset([a-234**23])z{a-234**23})r)rr6r7rrrr8Ts2zTest_set_literal.test_basiccCstd}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�dS)	Nzset([x for x in y])z{x for x in y}zset([x for x in y if x == m])z{x for x in y if x == m}zset([x for x in y for a in b])z{x for x in y for a in b}zset([f(x) - 23 for x in y])z{f(x) - 23 for x in y})r)rr6r7rrr�test_listcompswszTest_set_literal.test_listcompscCs�d}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�d	}d
}|j||�d}d}|j||�d
}d}|j||�dS)Nzset( [1, 2])z{1, 2}z
set([1 ,  2])z{1 ,  2}z
set([ 1 ])z{ 1 }z
set( [1] )z{1}zset([  1,  2  ])z{  1,  2  }zset([x  for x in y ])z{x  for x in y }z<set(
                   [1, 2]
               )
            z{1, 2}
)r)rr6r7rrrrk�s*z Test_set_literal.test_whitespacecCs<d}d}|j||�d}d}|j||�dS)Nzset((1, 2)) # Hiz{1, 2} # HizZ
            # Foo
            set( # Bar
               (1, 2)
            )
            z2
            # Foo
            {1, 2}
            )r)rr6r7rrrr��szTest_set_literal.test_commentscCsvd}|j|�d}|j|�d}|j|�d}|j|�d}|j|�d}|j|�dS)Nzset()zset(a)zset(a, b, c)zset(x for x in y)zset(x for x in y if z)zset(a*823-23**2 + f(23)))r!)rrPrrrrb�s




zTest_set_literal.test_unchangedN)	r2r&r3rr8r�rkr�rbrrrrr�Ps# r�c@s^eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�Test_sys_excZsys_exccCs d}d}|j||�dS)Nzsys.exc_typezsys.exc_info()[0])r)rr6r7rrrr��szTest_sys_exc.test_0cCs d}d}|j||�dS)Nz
sys.exc_valuezsys.exc_info()[1])r)rr6r7rrrr<�szTest_sys_exc.test_1cCs d}d}|j||�dS)Nzsys.exc_tracebackzsys.exc_info()[2])r)rr6r7rrrr=�szTest_sys_exc.test_2cCs d}d}|j||�dS)Nzsys.exc_type # Foozsys.exc_info()[0] # Foo)r)rr6r7rrrr>�szTest_sys_exc.test_3cCs d}d}|j||�dS)Nzsys.  exc_typezsys.  exc_info()[0])r)rr6r7rrrr?�szTest_sys_exc.test_4cCs d}d}|j||�dS)Nzsys  .exc_typezsys  .exc_info()[0])r)rr6r7rrrr@�szTest_sys_exc.test_5N)
r2r&r3rr�r<r=r>r?r@rrrrr��sr�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�
Test_parenZparencCs d}d}|j||�dS)Nz[i for i in 1, 2 ]z[i for i in (1, 2) ])r)rr6r7rrrr��szTest_paren.test_0cCs d}d}|j||�dS)Nz[i for i in 1, 2, ]z[i for i in (1, 2,) ])r)rr6r7rrrr<�szTest_paren.test_1cCs d}d}|j||�dS)Nz[i for i  in     1, 2 ]z[i for i  in     (1, 2) ])r)rr6r7rrrr=�szTest_paren.test_2cCs d}d}|j||�dS)Nz[i for i in 1, 2 if i]z[i for i in (1, 2) if i])r)rr6r7rrrr>szTest_paren.test_3cCs d}d}|j||�dS)Nz[i for i in 1,    2    ]z[i for i in (1,    2)    ])r)rr6r7rrrr?szTest_paren.test_4cCs d}d}|j||�dS)Nz(i for i in 1, 2)z(i for i in (1, 2)))r)rr6r7rrrr@
szTest_paren.test_5cCs d}d}|j||�dS)Nz(i for i in 1   ,2   if i)z(i for i in (1   ,2)   if i))r)rr6r7rrrrAszTest_paren.test_6cCsd}|j|�dS)Nz[i for i in (1, 2)])r!)rrPrrr�test_unchanged_0szTest_paren.test_unchanged_0cCsd}|j|�dS)Nz[i for i in foo()])r!)rrPrrrrQszTest_paren.test_unchanged_1cCsd}|j|�dS)Nz[i for i in (1, 2) if nothing])r!)rrPrrrrRszTest_paren.test_unchanged_2cCsd}|j|�dS)Nz(i for i in (1, 2)))r!)rrPrrrrS#szTest_paren.test_unchanged_3cCsd}|j|�dS)Nz[i for i in m])r!)rrPrrrrT'szTest_paren.test_unchanged_4N)r2r&r3rr�r<r=r>r?r@rAr�rQrRrSrTrrrrr��sr�c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�Test_metaclass�	metaclasscCs�|jd�|jd�|jd�|jd�|jd�|jd�|jd�d}|j|�d	}|j|�dS)
Nzclass X(): passzclass X(object): passzclass X(object1, object2): passz(class X(object1, object2, object3): passzclass X(metaclass=Meta): passz'class X(b, arg=23, metclass=Meta): passz2class X(b, arg=23, metaclass=Meta, other=42): passzD
        class X:
            def __metaclass__(self): pass
        z1
        class X:
            a[23] = 74
        )r!)rrPrrrrb/s







zTest_metaclass.test_unchangedcCs<d}d}|j||�d}d}|j||�dS)NzQ
        class X:
            # hi
            __metaclass__ = AppleMeta
        zQ
        class X(metaclass=AppleMeta):
            # hi
            pass
        zR
        class X:
            __metaclass__ = Meta
            # Bedtime!
        zR
        class X(metaclass=Meta):
            pass
            # Bedtime!
        )r)rr6r7rrrr�DszTest_metaclass.test_commentscCs8d}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�d	}d}|j||�d
}d}|j||�d}d
}|j||�d}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�dS)NzK
        class X():
            __metaclass__ = Q
            pass
        z8
        class X(metaclass=Q):
            pass
        z"class X(object): __metaclass__ = Qz"class X(object, metaclass=Q): passzW
        class X(object):
            __metaclass__ = Meta
            bar = 7
        zF
        class X(object, metaclass=Meta):
            bar = 7
        zJ
        class X:
            __metaclass__ = Meta; x = 4; g = 23
        zD
        class X(metaclass=Meta):
            x = 4; g = 23
        zW
        class X(object):
            bar = 7
            __metaclass__ = Meta
        zl
        class X():
            __metaclass__ = A
            __metaclass__ = B
            bar = 7
        z;
        class X(metaclass=B):
            bar = 7
        z[
        class X(clsA, clsB):
            __metaclass__ = Meta
            bar = 7
        zJ
        class X(clsA, clsB, metaclass=Meta):
            bar = 7
        z(class m(a, arg=23): __metaclass__ = Metaz(class m(a, arg=23, metaclass=Meta): passzN
        class X(expression(2 + 4)):
            __metaclass__ = Meta
        zN
        class X(expression(2 + 4), metaclass=Meta):
            pass
        zT
        class X(expression(2 + 4), x**4):
            __metaclass__ = Meta
        zT
        class X(expression(2 + 4), x**4, metaclass=Meta):
            pass
        zT
        class X:
            __metaclass__ = Meta
            save.py = 23
        zC
        class X(metaclass=Meta):
            save.py = 23
        )r)rr6r7rrr�	test_meta]sBzTest_metaclass.test_metaN)r2r&r3rrbr�r�rrrrr�+sr�c@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�Test_getcwduZgetcwducCstd}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�dS)	Nz
os.getcwduz	os.getcwdzos.getcwdu()zos.getcwd()zmeth = os.getcwduzmeth = os.getcwdzos.getcwdu(args)zos.getcwd(args))r)rr6r7rrrr8�szTest_getcwdu.test_basiccCs d}d}|j||�dS)Nzos.getcwdu() # Foozos.getcwd() # Foo)r)rr6r7rrrr`�szTest_getcwdu.test_commentcCs=d}|j|�d}|j|�d}|j|�dS)Nzos.getcwd()z	getcwdu()zos.getcwdb())r!)rrPrrrrb�s

zTest_getcwdu.test_unchangedcCs d}d}|j||�dS)Nz<
            if 1:
                os.getcwdu()
            z;
            if 1:
                os.getcwd()
            )r)rr6r7rrr�test_indentation�szTest_getcwdu.test_indentationcCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nz
os .getcwdu()zos .getcwd()zos.  getcwduzos.  getcwdzos.getcwdu (  )zos.getcwd (  ))r)rr6r7rrr�test_multilation�szTest_getcwdu.test_multilationN)	r2r&r3rr8r`rbr�r�rrrrr��s
r�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�
Test_operator�operatorcCs d}d}|j||�dS)Nzoperator.isCallable(x)zhasattr(x, '__call__'))r)rr6r7rrr�test_operator_isCallablesz&Test_operator.test_operator_isCallablecCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nzoperator.sequenceIncludes(x, y)zoperator.contains(x, y)z operator .sequenceIncludes(x, y)zoperator .contains(x, y)z!operator.  sequenceIncludes(x, y)zoperator.  contains(x, y))r)rr6r7rrr�test_operator_sequenceIncludessz,Test_operator.test_operator_sequenceIncludescCs d}d}|j||�dS)Nzoperator.isSequenceType(x)z6import collections
isinstance(x, collections.Sequence))r)rr6r7rrr�test_operator_isSequenceType#sz*Test_operator.test_operator_isSequenceTypecCs d}d}|j||�dS)Nzoperator.isMappingType(x)z5import collections
isinstance(x, collections.Mapping))r)rr6r7rrr�test_operator_isMappingType(sz)Test_operator.test_operator_isMappingTypecCs d}d}|j||�dS)Nzoperator.isNumberType(x)z,import numbers
isinstance(x, numbers.Number))r)rr6r7rrr�test_operator_isNumberType-sz(Test_operator.test_operator_isNumberTypecCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nzoperator.repeat(x, n)zoperator.mul(x, n)zoperator .repeat(x, n)zoperator .mul(x, n)zoperator.  repeat(x, n)zoperator.  mul(x, n))r)rr6r7rrr�test_operator_repeat2sz"Test_operator.test_operator_repeatcCsXd}d}|j||�d}d}|j||�d}d}|j||�dS)Nzoperator.irepeat(x, n)zoperator.imul(x, n)zoperator .irepeat(x, n)zoperator .imul(x, n)zoperator.  irepeat(x, n)zoperator.  imul(x, n))r)rr6r7rrr�test_operator_irepeat?sz#Test_operator.test_operator_irepeatcCs d}d}|j||�dS)Nz
isCallable(x)z-You should use 'hasattr(x, '__call__')' here.)r#)rrP�trrr�test_bare_isCallableLsz"Test_operator.test_bare_isCallablecCs d}d}|j||�dS)NzsequenceIncludes(x, y)z.You should use 'operator.contains(x, y)' here.)r#)rrPr�rrr�test_bare_sequenceIncludesQsz(Test_operator.test_bare_sequenceIncludescCs d}d}|j||�dS)NzisSequenceType(z)z:You should use 'isinstance(z, collections.Sequence)' here.)r#)rrPr�rrr�!test_bare_operator_isSequenceTypeVsz/Test_operator.test_bare_operator_isSequenceTypecCs d}d}|j||�dS)NzisMappingType(x)z9You should use 'isinstance(x, collections.Mapping)' here.)r#)rrPr�rrr� test_bare_operator_isMappingType[sz.Test_operator.test_bare_operator_isMappingTypecCs d}d}|j||�dS)NzisNumberType(y)z4You should use 'isinstance(y, numbers.Number)' here.)r#)rrPr�rrr�test_bare_operator_isNumberType`sz-Test_operator.test_bare_operator_isNumberTypecCs d}d}|j||�dS)Nzrepeat(x, n)z)You should use 'operator.mul(x, n)' here.)r#)rrPr�rrr�test_bare_operator_repeatesz'Test_operator.test_bare_operator_repeatcCs d}d}|j||�dS)Nzirepeat(y, 187)z,You should use 'operator.imul(y, 187)' here.)r#)rrPr�rrr�test_bare_operator_irepeatjsz(Test_operator.test_bare_operator_irepeatN)r2r&r3rr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�
s


r�c@sjeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�
Test_exitfuncZexitfunccCs d}d}|j||�dS)NzI
            import sys
            sys.exitfunc = my_atexit
            ze
            import sys
            import atexit
            atexit.register(my_atexit)
            )r)rr6r7rrrr�tszTest_exitfunc.test_simplecCs d}d}|j||�dS)NzO
            import sys, crumbs
            sys.exitfunc = my_func
            zY
            import sys, crumbs, atexit
            atexit.register(my_func)
            )r)rr6r7rrr�test_names_import�szTest_exitfunc.test_names_importcCs d}d}|j||�dS)Nzh
            import sys
            sys.exitfunc = do(d)/a()+complex(f=23, g=23)*expression
            z�
            import sys
            import atexit
            atexit.register(do(d)/a()+complex(f=23, g=23)*expression)
            )r)rr6r7rrr�test_complex_expression�sz%Test_exitfunc.test_complex_expressioncCs<d}d}|j||�d}d}|j||�dS)NzN
            import sys # Foo
            sys.exitfunc = f # Blah
            zj
            import sys
            import atexit # Foo
            atexit.register(f) # Blah
            zo
            import apples, sys, crumbs, larry # Pleasant comments
            sys.exitfunc = func
            zy
            import apples, sys, crumbs, larry, atexit # Pleasant comments
            atexit.register(func)
            )r)rr6r7rrrr��szTest_exitfunc.test_commentscCs d}d}|j||�dS)Nz]
            import sys
            def f():
                sys.exitfunc = func
            zz
            import sys
            import atexit
            def f():
                atexit.register(func)
             )r)rr6r7rrr�test_in_a_function�sz Test_exitfunc.test_in_a_functioncCs)d}d}d}|j|||�dS)Nzsys.exitfunc = fzatexit.register(f)zKCan't find sys import; Please add an atexit import at the top of your file.)r")rr6r7�msgrrr�test_no_sys_import�sz Test_exitfunc.test_no_sys_importcCsd}|j|�dS)Nzf(sys.exitfunc))r!)rrPrrrrb�szTest_exitfunc.test_unchangedN)r2r&r3rr�r�r�r�r�r�rbrrrrr�psr�c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�Test_assertsZassertsc
CsUddddddddddddg}x$|D]\}}|j||�q1WdS) N�self.assert_(True)�self.assertTrue(True)�self.assertEquals(2, 2)�self.assertEqual(2, 2)�self.assertNotEquals(2, 3)�self.assertNotEqual(2, 3)�self.assertAlmostEquals(2, 3)�self.assertAlmostEqual(2, 3)� self.assertNotAlmostEquals(2, 8)�self.assertNotAlmostEqual(2, 8)�self.failUnlessEqual(2, 2)�self.failIfEqual(2, 3)� self.failUnlessAlmostEqual(2, 3)�self.failIfAlmostEqual(2, 8)�self.failUnless(True)�self.failUnlessRaises(foo)�self.assertRaises(foo)�self.failIf(False)�self.assertFalse(False))r�r�)r�r�)rr)rr)rr)rr�)rr)rr)r	r)r
r�)rr)r
r)r)rZtestsr6r7rrr�test_deprecated_names�s	z"Test_asserts.test_deprecated_namescCs�d}d}|j||�d}d}|j||�d}d}|j||�d}d}|j||�d	}d
}|j||�d}d}|j||�d
}d}|j||�dS)Nzeq = self.assertEqualszeq = self.assertEqualz#self.assertEquals(2, 3, msg="fail")z"self.assertEqual(2, 3, msg="fail")z)self.assertEquals(2, 3, msg="fail") # fooz(self.assertEqual(2, 3, msg="fail") # foozself.assertEquals (2, 3)zself.assertEqual (2, 3)z  self.assertEquals (2, 3)z  self.assertEqual (2, 3)z0with self.failUnlessRaises(Explosion): explode()z,with self.assertRaises(Explosion): explode()z6with self.failUnlessRaises(Explosion) as cm: explode()z2with self.assertRaises(Explosion) as cm: explode())r)rr6r7rrr�
test_variants�s*zTest_asserts.test_variantscCs|jd�|jd�dS)Nzself.assertEqualsOnSaturdayz!self.assertEqualsOnSaturday(3, 5))r!)rrrrrb�s
zTest_asserts.test_unchangedN)r2r&r3rrrrbrrrrr��sr�)F�__doc__r�Zunittestr�rr�rr
rrrrZ
lib2to3.testsrZTestCaser	r4r;rGr]rcrfrkrxr|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr$r'rPrRrbrjrvr{rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>s�"9:�;1#j3&�}.&�H/+bn/� ��4B.OVpC�Y
=J�":�=cX