
mYs                @   sM  d  Z  d d l Z d d l Z d d l m Z d d l m Z d d l m Z m	 Z	 m
 Z
 m Z d d l m Z Gd d   d e j  Z Gd	 d
   d
 e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d    d  e  Z Gd! d"   d" e  Z Gd# d$   d$ e  Z Gd% d&   d& e  Z Gd' d(   d( e  Z Gd) d*   d* e  Z  Gd+ d,   d, e  Z! Gd- d.   d. e  Z" Gd/ d0   d0 e  Z# Gd1 d2   d2 e  Z$ Gd3 d4   d4  Z% Gd5 d6   d6 e e%  Z& Gd7 d8   d8 e e%  Z' Gd9 d:   d: e e%  Z( Gd; d<   d< e  Z) Gd= d>   d> e  Z* Gd? d@   d@ e  Z+ GdA dB   dB e  Z, GdC dD   dD e  Z- GdE dF   dF e  Z. GdG dH   dH e  Z/ GdI dJ   dJ e  Z0 GdK dL   dL e  Z1 GdM dN   dN e  Z2 GdO dP   dP e  Z3 GdQ dR   dR e  Z4 GdS dT   dT e  Z5 GdU dV   dV e  Z6 GdW dX   dX e  Z7 GdY dZ   dZ e  Z8 Gd[ d\   d\ e  Z9 Gd] d^   d^ e  Z: Gd_ d`   d` e  Z; Gda db   db e  Z< Gdc dd   dd e  Z= Gde df   df e  Z> Gdg dh   dh e  Z? Gdi dj   dj e  Z@ Gdk dl   dl e  ZA Gdm dn   dn e  ZB Gdo dp   dp e  ZC Gdq dr   dr e  ZD Gds dt   dt e  ZE Gdu dv   dv e  ZF d S)wz" Test suite for the fixer modules     N)chain)
itemgetter)pygrampytreerefactor
fixer_util)supportc               @   sv   e  Z d  Z d d d d d  Z d d   Z d d d	  Z d d
 d  Z d d   Z d d d  Z d d   Z	 d S)FixerTestCaseNlib2to3c             C   sx   | d  k r |  j  g } t j | | |  |  _ g  |  _ d |  _ x/ t |  j j |  j j  D] } |  j | _	 q^ Wd  S)Nz<string>)
fixerr   get_refactorerr   	fixer_logfilenamer   Z	pre_orderZ
post_orderlog)selfZfix_listZ	fixer_pkgoptionsr    r   L/build/mts/release/bora-5583004/publish/lin64/lib64/python3.5/test_fixers.pysetUp   s    		zFixerTestCase.setUpc             C   sP   t  j |  } t  j |  } |  j j | |  j  } |  j | t |   | S)N)r   Zreformatr   Zrefactor_stringr   assertEqualstr)r   beforeaftertreer   r   r   _check   s
    zFixerTestCase._checkFc             C   s?   |  j  | |  } |  j | j  | s; |  j |  j g   d  S)N)r   
assertTruewas_changedr   r   )r   r   r   ignore_warningsr   r   r   r   check$   s    zFixerTestCase.checkc             C   sH   |  j  | |  } |  j | d j |  j   | sD |  j | j  d  S)N )r   ZassertInjoinr   r   r   )r   r   r   message	unchangedr   r   r   r   warns*   s    zFixerTestCase.warnsc             C   s   |  j  | | | d d d  S)Nr"   T)r#   )r   r   r!   r   r   r   warns_unchanged0   s    zFixerTestCase.warns_unchangedc             C   s-   |  j  | |  | s) |  j |  j g   d  S)N)r   r   r   )r   r   r   r   r   r   r"   3   s    zFixerTestCase.unchangedc             G   s   |  j  g } | j |  t j d |  } | j   \ } } d |  j  } | rm | d j j j |  rm d  S| r | d	 j j j |  r | r d  S|  j d d j	 d d   | | D  | f  d  S)
Nr
   Zfix_   z5Fixer run order (%s) is incorrect; %s should be last.z, c             S   s   g  |  ] } | j  j  q Sr   )	__class__
__module__).0xr   r   r   
<listcomp>E   s   	 z3FixerTestCase.assert_runs_after.<locals>.<listcomp>r+   )
r   extendr   r   Z
get_fixersr&   r'   endswithZfailr    )r   namesfixesrpreZpostnr   r   r   assert_runs_after8   s    &	zFixerTestCase.assert_runs_after)
__name__r'   __qualname__r   r   r   r#   r$   r"   r3   r   r   r   r   r	      s   r	   c               @   s:   e  Z d  Z d Z d d   Z d d   Z d d   Z d S)	Test_nenec             C   s    d } d } |  j  | |  d  S)Nzif x <> y:
            passzif x != y:
            pass)r   )r   bar   r   r   
test_basicJ   s    zTest_ne.test_basicc             C   s    d } d } |  j  | |  d  S)Nzif x<>y:
            passzif x!=y:
            pass)r   )r   r8   r9   r   r   r   test_no_spacesR   s    zTest_ne.test_no_spacesc             C   s    d } d } |  j  | |  d  S)Nzif x<>y<>z:
            passzif x!=y!=z:
            pass)r   )r   r8   r9   r   r   r   test_chainedZ   s    zTest_ne.test_chainedN)r4   r'   r5   r   r:   r;   r<   r   r   r   r   r6   G   s   r6   c               @   s   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d S)Test_has_keyZhas_keyc             C   s    d } d } |  j  | |  d  S)Nz$x = d.has_key("x") or d.has_key("y")zx = "x" in d or "y" in d)r   )r   r8   r9   r   r   r   test_1e   s    zTest_has_key.test_1c             C   s    d } d } |  j  | |  d  S)Nzx = a.b.c.d.has_key("x") ** 3zx = ("x" in a.b.c.d) ** 3)r   )r   r8   r9   r   r   r   test_2j   s    zTest_has_key.test_2c             C   s    d } d } |  j  | |  d  S)Nz!x = a.b.has_key(1 + 2).__repr__()zx = (1 + 2 in a.b).__repr__())r   )r   r8   r9   r   r   r   test_3o   s    zTest_has_key.test_3c             C   s    d } d } |  j  | |  d  S)Nz,x = a.b.has_key(1 + 2).__repr__() ** -3 ** 4z(x = (1 + 2 in a.b).__repr__() ** -3 ** 4)r   )r   r8   r9   r   r   r   test_4t   s    zTest_has_key.test_4c             C   s    d } d } |  j  | |  d  S)Nzx = a.has_key(f or g)zx = (f or g) in a)r   )r   r8   r9   r   r   r   test_5y   s    zTest_has_key.test_5c             C   s    d } d } |  j  | |  d  S)Nzx = a + b.has_key(c)zx = a + (c in b))r   )r   r8   r9   r   r   r   test_6~   s    zTest_has_key.test_6c             C   s    d } d } |  j  | |  d  S)Nzx = a.has_key(lambda: 12)zx = (lambda: 12) in a)r   )r   r8   r9   r   r   r   test_7   s    zTest_has_key.test_7c             C   s    d } d } |  j  | |  d  S)Nzx = a.has_key(a for a in b)zx = (a for a in b) in a)r   )r   r8   r9   r   r   r   test_8   s    zTest_has_key.test_8c             C   s    d } d } |  j  | |  d  S)Nzif not a.has_key(b): passzif b not in a: pass)r   )r   r8   r9   r   r   r   test_9   s    zTest_has_key.test_9c             C   s    d } d } |  j  | |  d  S)Nz$if not a.has_key(b).__repr__(): passz if not (b in a).__repr__(): pass)r   )r   r8   r9   r   r   r   test_10   s    zTest_has_key.test_10c             C   s    d } d } |  j  | |  d  S)Nzif not a.has_key(b) ** 2: passzif not (b in a) ** 2: pass)r   )r   r8   r9   r   r   r   test_11   s    zTest_has_key.test_11N)r4   r'   r5   r   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   r   r   r   r   r=   b   s   r=   c               @   sB  e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d  d!   Z d" d#   Z d$ d%   Z d& d'   Z d( d)   Z d* d+   Z d, d-   Z d. d/   Z d0 d1   Z d2 d3   Z d4 S)5
Test_applyZapplyc             C   s    d } d } |  j  | |  d  S)Nzx = apply(f, g + h)zx = f(*g + h))r   )r   r8   r9   r   r   r   r>      s    zTest_apply.test_1c             C   s    d } d } |  j  | |  d  S)Nzy = apply(f, g, h)zy = f(*g, **h))r   )r   r8   r9   r   r   r   r?      s    zTest_apply.test_2c             C   s    d } d } |  j  | |  d  S)Nz z = apply(fs[0], g or h, h or g)zz = fs[0](*g or h, **h or g))r   )r   r8   r9   r   r   r   r@      s    zTest_apply.test_3c             C   s    d } d } |  j  | |  d  S)Nzapply(f, (x, y) + t)zf(*(x, y) + t))r   )r   r8   r9   r   r   r   rA      s    zTest_apply.test_4c             C   s    d } d } |  j  | |  d  S)Nzapply(f, args,)zf(*args))r   )r   r8   r9   r   r   r   rB      s    zTest_apply.test_5c             C   s    d } d } |  j  | |  d  S)Nzapply(f, args, kwds,)zf(*args, **kwds))r   )r   r8   r9   r   r   r   rC      s    zTest_apply.test_6c             C   s    d } d } |  j  | |  d  S)Nzx = apply(f+g, args)zx = (f+g)(*args))r   )r   r8   r9   r   r   r   test_complex_1   s    zTest_apply.test_complex_1c             C   s    d } d } |  j  | |  d  S)Nzx = apply(f*g, args)zx = (f*g)(*args))r   )r   r8   r9   r   r   r   test_complex_2   s    zTest_apply.test_complex_2c             C   s    d } d } |  j  | |  d  S)Nzx = apply(f**g, args)zx = (f**g)(*args))r   )r   r8   r9   r   r   r   test_complex_3   s    zTest_apply.test_complex_3c             C   s    d } d } |  j  | |  d  S)Nzx = apply(f.g, args)zx = f.g(*args))r   )r   r8   r9   r   r   r   test_dotted_name   s    zTest_apply.test_dotted_namec             C   s    d } d } |  j  | |  d  S)Nzx = apply(f[x], args)zx = f[x](*args))r   )r   r8   r9   r   r   r   test_subscript   s    zTest_apply.test_subscriptc             C   s    d } d } |  j  | |  d  S)Nzx = apply(f(), args)zx = f()(*args))r   )r   r8   r9   r   r   r   	test_call   s    zTest_apply.test_callc             C   s    d } d } |  j  | |  d  S)Nz"x = apply(a.b.c.d.e.f, args, kwds)zx = a.b.c.d.e.f(*args, **kwds))r   )r   r8   r9   r   r   r   test_extreme   s    zTest_apply.test_extremec             C   s    d } d } |  j  | |  d  S)Nz1apply(   # foo
          f, # bar
          args)zf(*args))r   )r   r8   r9   r   r   r   test_weird_comments   s    zTest_apply.test_weird_commentsc             C   s   d } |  j  |  d  S)Nzapply())r"   )r   sr   r   r   test_unchanged_1   s    zTest_apply.test_unchanged_1c             C   s   d } |  j  |  d  S)Nzapply(f))r"   )r   rR   r   r   r   test_unchanged_2   s    zTest_apply.test_unchanged_2c             C   s   d } |  j  |  d  S)Nz	apply(f,))r"   )r   rR   r   r   r   test_unchanged_3   s    zTest_apply.test_unchanged_3c             C   s   d } |  j  |  d  S)Nzapply(f, args, kwds, extras))r"   )r   rR   r   r   r   test_unchanged_4   s    zTest_apply.test_unchanged_4c             C   s   d } |  j  |  d  S)Nzapply(f, *args, **kwds))r"   )r   rR   r   r   r   test_unchanged_5   s    zTest_apply.test_unchanged_5c             C   s   d } |  j  |  d  S)Nzapply(f, *args))r"   )r   rR   r   r   r   test_unchanged_6  s    zTest_apply.test_unchanged_6c             C   s   d } |  j  |  d  S)Nz#apply(func=f, args=args, kwds=kwds))r"   )r   rR   r   r   r   test_unchanged_7  s    zTest_apply.test_unchanged_7c             C   s   d } |  j  |  d  S)Nzapply(f, args=args, kwds=kwds))r"   )r   rR   r   r   r   test_unchanged_8  s    zTest_apply.test_unchanged_8c             C   s   d } |  j  |  d  S)Nzapply(f, args, kwds=kwds))r"   )r   rR   r   r   r   test_unchanged_9  s    zTest_apply.test_unchanged_9c             C   s    d } d } |  j  | |  d  S)Nzapply(  f,  args,   kwds)zf(*args, **kwds))r   )r   r9   r8   r   r   r   test_space_1  s    zTest_apply.test_space_1c             C   s    d } d } |  j  | |  d  S)Nzapply(  f  ,args,kwds   )zf(*args, **kwds))r   )r   r9   r8   r   r   r   test_space_2  s    zTest_apply.test_space_2N)r4   r'   r5   r   r>   r?   r@   rA   rB   rC   rJ   rK   rL   rM   rN   rO   rP   rQ   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r   r   r   r   rI      s4   	rI   c               @   sF   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 S)Test_reloadreloadc             C   s    d } d } |  j  | |  d  S)Nz	reload(a)zimport imp
imp.reload(a))r   )r   r8   r9   r   r   r   test   s    zTest_reload.testc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzreload( a ) # commentz$import imp
imp.reload( a ) # commentzreload( a )  # commentz%import imp
imp.reload( a )  # comment)r   )r   r8   r9   r   r   r   test_comment%  s    zTest_reload.test_commentc             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzreload( a )zimport imp
imp.reload( a )z
reload( a)zimport imp
imp.reload( a)z
reload(a )zimport imp
imp.reload(a ))r   )r   r8   r9   r   r   r   
test_space/  s    zTest_reload.test_spacec             C   s   d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d	 } |  j  |  d  S)
Nzreload(a=1)zreload(f, g)zreload(f, *h)zreload(f, *h, **i)zreload(f, **i)zreload(*h, **i)z
reload(*h)zreload(**i)zreload())r"   )r   rR   r   r   r   test_unchanged<  s$    zTest_reload.test_unchangedN)r4   r'   r5   r   r`   ra   rb   rc   r   r   r   r   r^     s
   
r^   c               @   s:   e  Z d  Z d Z d d   Z d d   Z d d   Z d S)	Test_interninternc             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzx =   intern(  a  )z"import sys
x =   sys.intern(  a  )z%y = intern("b" # test
              )z4import sys
y = sys.intern("b" # test
              )zz = intern(a+b+c.d,   )z&import sys
z = sys.intern(a+b+c.d,   ))r   )r   r8   r9   r   r   r   test_prefix_preservation[  s    z$Test_intern.test_prefix_preservationc             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzx = intern(a)zimport sys
x = sys.intern(a)zz = 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   )r   r8   r9   r   r   r   r`   j  s    zTest_intern.testc             C   sc   d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d  S)Nzintern(a=1)zintern(f, g)z
intern(*h)zintern(**i)zintern())r"   )r   rR   r   r   r   rc   y  s    zTest_intern.test_unchangedN)r4   r'   r5   r   rf   r`   rc   r   r   r   r   rd   X  s   rd   c               @   sF   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 S)Test_reducereducec             C   s    d } d } |  j  | |  d  S)Nzreduce(a, b, c)z,from functools import reduce
reduce(a, b, c))r   )r   r8   r9   r   r   r   test_simple_call  s    zTest_reduce.test_simple_callc             C   s    d } d } |  j  | |  d  S)Nzdef x(arg): reduce(sum, [])z8from functools import reduce
def x(arg): reduce(sum, []))r   )r   r8   r9   r   r   r   test_bug_7253  s    zTest_reduce.test_bug_7253c             C   s    d } d } |  j  | |  d  S)Nzreduce(lambda x, y: x + y, seq)z<from functools import reduce
reduce(lambda x, y: x + y, seq))r   )r   r8   r9   r   r   r   test_call_with_lambda  s    z!Test_reduce.test_call_with_lambdac             C   sc   d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d  S)Nz	reduce(a)zreduce(a, b=42)zreduce(a, b, c, d)zreduce(**c)zreduce())r"   )r   rR   r   r   r   rc     s    zTest_reduce.test_unchangedN)r4   r'   r5   r   ri   rj   rk   rc   r   r   r   r   rg     s
   rg   c               @   s   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d  d!   Z d" d#   Z d$ S)%
Test_printprintc             C   s    d } d } |  j  | |  d  S)Nzprint 1,   1+1,   1+1+1zprint(1,   1+1,   1+1+1))r   )r   r8   r9   r   r   r   rf     s    z#Test_print.test_prefix_preservationc             C   s*   d } |  j  |  d } |  j  |  d  S)Nzprint()z	print(''))r"   )r   rR   r   r   r   test_idempotency  s    zTest_print.test_idempotencyc             C   sO   t  j |  j j _ d } |  j |  d } |  j |  d } |  j |  d  S)Nzprint(1, 1+1, 1+1+1)zprint()z	print(''))r   Z!python_grammar_no_print_statementr   ZdriverZgrammarr"   )r   rR   r   r   r   "test_idempotency_print_as_function  s    z-Test_print.test_idempotency_print_as_functionc             C   s    d } d } |  j  | |  d  S)Nzprint 1, 1+1, 1+1+1zprint(1, 1+1, 1+1+1))r   )r   r8   r9   r   r   r   r>     s    zTest_print.test_1c             C   s    d } d } |  j  | |  d  S)Nz
print 1, 2zprint(1, 2))r   )r   r8   r9   r   r   r   r?     s    zTest_print.test_2c             C   s    d } d } |  j  | |  d  S)Nrm   zprint())r   )r   r8   r9   r   r   r   r@     s    zTest_print.test_3c             C   s    d } d } |  j  | |  d  S)Nzprint whatever; printzprint(whatever); print())r   )r   r8   r9   r   r   r   rA     s    zTest_print.test_4c             C   s    d } d } |  j  | |  d  S)Nzprint; print whatever;zprint(); print(whatever);)r   )r   r8   r9   r   r   r   rB     s    zTest_print.test_5c             C   s    d } d } |  j  | |  d  S)Nzprint (a, b, c)zprint((a, b, c)))r   )r   r8   r9   r   r   r   
test_tuple  s    zTest_print.test_tuplec             C   s    d } d } |  j  | |  d  S)Nzprint 1, 2, 3,zprint(1, 2, 3, end=' '))r   )r   r8   r9   r   r   r   test_trailing_comma_1  s    z Test_print.test_trailing_comma_1c             C   s    d } d } |  j  | |  d  S)Nzprint 1, 2,zprint(1, 2, end=' '))r   )r   r8   r9   r   r   r   test_trailing_comma_2  s    z Test_print.test_trailing_comma_2c             C   s    d } d } |  j  | |  d  S)Nzprint 1,zprint(1, end=' '))r   )r   r8   r9   r   r   r   test_trailing_comma_3  s    z Test_print.test_trailing_comma_3c             C   s    d } d } |  j  | |  d  S)Nzprint >>sys.stderr, 1, 2, 3zprint(1, 2, 3, file=sys.stderr))r   )r   r8   r9   r   r   r   !test_vargs_without_trailing_comma  s    z,Test_print.test_vargs_without_trailing_commac             C   s    d } d } |  j  | |  d  S)Nzprint >>sys.stderr, 1, 2,z%print(1, 2, end=' ', file=sys.stderr))r   )r   r8   r9   r   r   r   test_with_trailing_comma  s    z#Test_print.test_with_trailing_commac             C   s    d } d } |  j  | |  d  S)Nzprint >>sys.stderr, 1+1zprint(1+1, file=sys.stderr))r   )r   r8   r9   r   r   r   test_no_trailing_comma  s    z!Test_print.test_no_trailing_commac             C   s    d } d } |  j  | |  d  S)Nzprint >>  sys.stderrzprint(file=sys.stderr))r   )r   r8   r9   r   r   r   test_spaces_before_file  s    z"Test_print.test_spaces_before_filec             C   s3   d } |  j  |  d } d } |  j | |  d  S)Nz<from __future__ import print_function
print('Hai!', end=' ')zprint 'Hello, world!'zprint('Hello, world!'))r"   r   )r   rR   r8   r9   r   r   r   test_with_future_print_function  s
    z*Test_print.test_with_future_print_functionN)r4   r'   r5   r   rf   rn   ro   r>   r?   r@   rA   rB   rp   rq   rr   rs   rt   ru   rv   rw   rx   r   r   r   r   rl     s$   rl   c               @   s   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d S)	Test_execexecc             C   s    d } d } |  j  | |  d  S)Nz  exec code in ns1,   ns2z  exec(code, ns1,   ns2))r   )r   r8   r9   r   r   r   rf     s    z"Test_exec.test_prefix_preservationc             C   s    d } d } |  j  | |  d  S)Nz	exec codez
exec(code))r   )r   r8   r9   r   r   r   r:     s    zTest_exec.test_basicc             C   s    d } d } |  j  | |  d  S)Nzexec code in nszexec(code, ns))r   )r   r8   r9   r   r   r   test_with_globals#  s    zTest_exec.test_with_globalsc             C   s    d } d } |  j  | |  d  S)Nzexec code in ns1, ns2zexec(code, ns1, ns2))r   )r   r8   r9   r   r   r   test_with_globals_locals(  s    z"Test_exec.test_with_globals_localsc             C   s    d } d } |  j  | |  d  S)Nzexec (a.b()) in nszexec((a.b()), ns))r   )r   r8   r9   r   r   r   rJ   -  s    zTest_exec.test_complex_1c             C   s    d } d } |  j  | |  d  S)Nzexec a.b() + c in nszexec(a.b() + c, ns))r   )r   r8   r9   r   r   r   rK   2  s    zTest_exec.test_complex_2c             C   s   d } |  j  |  d  S)Nz
exec(code))r"   )r   rR   r   r   r   rS   9  s    zTest_exec.test_unchanged_1c             C   s   d } |  j  |  d  S)Nzexec (code))r"   )r   rR   r   r   r   rT   =  s    zTest_exec.test_unchanged_2c             C   s   d } |  j  |  d  S)Nzexec(code, ns))r"   )r   rR   r   r   r   rU   A  s    zTest_exec.test_unchanged_3c             C   s   d } |  j  |  d  S)Nzexec(code, ns1, ns2))r"   )r   rR   r   r   r   rV   E  s    zTest_exec.test_unchanged_4N)r4   r'   r5   r   rf   r:   r{   r|   rJ   rK   rS   rT   rU   rV   r   r   r   r   ry     s   ry   c               @   sj   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d S)	Test_reprreprc             C   s    d } d } |  j  | |  d  S)Nzx =   `1 + 2`zx =   repr(1 + 2))r   )r   r8   r9   r   r   r   rf   L  s    z"Test_repr.test_prefix_preservationc             C   s    d } d } |  j  | |  d  S)Nzx = `1 + 2`zx = repr(1 + 2))r   )r   r8   r9   r   r   r   test_simple_1Q  s    zTest_repr.test_simple_1c             C   s    d } d } |  j  | |  d  S)Nzy = `x`zy = repr(x))r   )r   r8   r9   r   r   r   test_simple_2V  s    zTest_repr.test_simple_2c             C   s    d } d } |  j  | |  d  S)Nzz = `y`.__repr__()zz = repr(y).__repr__())r   )r   r8   r9   r   r   r   test_complex[  s    zTest_repr.test_complexc             C   s    d } d } |  j  | |  d  S)Nzx = `1, 2, 3`zx = repr((1, 2, 3)))r   )r   r8   r9   r   r   r   rp   `  s    zTest_repr.test_tuplec             C   s    d } d } |  j  | |  d  S)Nzx = `1 + `2``zx = repr(1 + repr(2)))r   )r   r8   r9   r   r   r   test_nestede  s    zTest_repr.test_nestedc             C   s    d } d } |  j  | |  d  S)Nzx = `1, 2 + `3, 4``zx = repr((1, 2 + repr((3, 4)))))r   )r   r8   r9   r   r   r   test_nested_tuplesj  s    zTest_repr.test_nested_tuplesN)r4   r'   r5   r   rf   r   r   r   rp   r   r   r   r   r   r   r}   I  s   r}   c               @   s   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d  d!   Z d" S)#Test_exceptexceptc             C   s    d } d } |  j  | |  d  S)Nzq
            try:
                pass
            except (RuntimeError, ImportError),    e:
                passzs
            try:
                pass
            except (RuntimeError, ImportError) as    e:
                pass)r   )r   r8   r9   r   r   r   rf   r  s    z$Test_except.test_prefix_preservationc             C   s    d } d } |  j  | |  d  S)NzV
            try:
                pass
            except Foo, e:
                passzX
            try:
                pass
            except Foo as e:
                pass)r   )r   r8   r9   r   r   r   test_simple  s    zTest_except.test_simplec             C   s    d } d } |  j  | |  d  S)NzU
            try:
                pass
            except Foo,e:
                passzX
            try:
                pass
            except Foo as e:
                pass)r   )r   r8   r9   r   r   r   "test_simple_no_space_before_target  s    z.Test_except.test_simple_no_space_before_targetc             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   test_tuple_unpack  s    
zTest_except.test_tuple_unpackc             C   s    d } d } |  j  | |  d  S)Nzn
            try:
                pass
            except (RuntimeError, ImportError), e:
                passzp
            try:
                pass
            except (RuntimeError, ImportError) as e:
                pass)r   )r   r8   r9   r   r   r   test_multi_class  s    zTest_except.test_multi_classc             C   s    d } d } |  j  | |  d  S)Nza
            try:
                pass
            except Exception, [a, b]:
                passz
            try:
                pass
            except Exception as xxx_todo_changeme:
                [a, b] = xxx_todo_changeme.args
                pass)r   )r   r8   r9   r   r   r   test_list_unpack  s    zTest_except.test_list_unpackc             C   s    d } d } |  j  | |  d  S)Nz_
            try:
                pass
            except Exception, d[5]:
                passz
            try:
                pass
            except Exception as xxx_todo_changeme:
                d[5] = xxx_todo_changeme
                pass)r   )r   r8   r9   r   r   r   test_weird_target_1  s    zTest_except.test_weird_target_1c             C   s    d } d } |  j  | |  d  S)Nz`
            try:
                pass
            except Exception, a.foo:
                passz
            try:
                pass
            except Exception as xxx_todo_changeme:
                a.foo = xxx_todo_changeme
                pass)r   )r   r8   r9   r   r   r   test_weird_target_2  s    zTest_except.test_weird_target_2c             C   s    d } d } |  j  | |  d  S)Nzb
            try:
                pass
            except Exception, a().foo:
                passz
            try:
                pass
            except Exception as xxx_todo_changeme:
                a().foo = xxx_todo_changeme
                pass)r   )r   r8   r9   r   r   r   test_weird_target_3  s    zTest_except.test_weird_target_3c             C   s    d } d } |  j  | |  d  S)Nz
            try:
                pass
            except Exception, a:
                pass
            except:
                passz
            try:
                pass
            except Exception as a:
                pass
            except:
                pass)r   )r   r8   r9   r   r   r   test_bare_except  s    zTest_except.test_bare_exceptc             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   !test_bare_except_and_else_finally
  s    z-Test_except.test_bare_except_and_else_finallyc             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   +test_multi_fixed_excepts_before_bare_except$  s    	
z7Test_except.test_multi_fixed_excepts_before_bare_exceptc             C   st   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)	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   )r   r8   r9   r   r   r   test_one_line_suites:  s    z Test_except.test_one_line_suitesc             C   s   d } |  j  |  d  S)NzO
            try:
                pass
            except:
                pass)r"   )r   rR   r   r   r   rS   j  s    zTest_except.test_unchanged_1c             C   s   d } |  j  |  d  S)NzY
            try:
                pass
            except Exception:
                pass)r"   )r   rR   r   r   r   rT   r  s    zTest_except.test_unchanged_2c             C   s   d } |  j  |  d  S)Nzg
            try:
                pass
            except (Exception, SystemExit):
                pass)r"   )r   rR   r   r   r   rU   z  s    zTest_except.test_unchanged_3N)r4   r'   r5   r   rf   r   r   r   r   r   r   r   r   r   r   r   r   rS   rT   rU   r   r   r   r   r   o  s"   0r   c               @   s   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d  d!   Z d" d#   Z d$ S)%
Test_raiseraisec             C   s    d } d } |  j  | |  d  S)Nzraise Exception, 5zraise Exception(5))r   )r   r8   r9   r   r   r   r:     s    zTest_raise.test_basicc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzraise Exception,5zraise Exception(5)zraise   Exception,    5zraise   Exception(5))r   )r   r8   r9   r   r   r   rf     s    z#Test_raise.test_prefix_preservationc             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzraise Exception, 5 # foozraise Exception(5) # foozraise E, (5, 6) % (a, b) # foozraise E((5, 6) % (a, b)) # fooz:def foo():
                    raise Exception, 5, 6 # foozIdef foo():
                    raise Exception(5).with_traceback(6) # foo)r   )r   r8   r9   r   r   r   test_with_comments  s    zTest_raise.test_with_commentsc             C   s    d } d } |  j  | |  d  S)Nzraise Exception(5), None, tbz%raise Exception(5).with_traceback(tb))r   )r   r8   r9   r   r   r   test_None_value  s    zTest_raise.test_None_valuec             C   s    d } d } |  j  | |  d  S)Nzraise Exception, (5, 6, 7)zraise Exception(5, 6, 7))r   )r   r8   r9   r   r   r   test_tuple_value  s    zTest_raise.test_tuple_valuec             C   s    d } d } |  j  | |  d  S)Nzraise E, (5, 6) % (a, b)zraise E((5, 6) % (a, b)))r   )r   r8   r9   r   r   r   test_tuple_detection  s    zTest_raise.test_tuple_detectionc             C   s    d } d } |  j  | |  d  S)Nzraise (((E1, E2), E3), E4), Vzraise E1(V))r   )r   r8   r9   r   r   r   test_tuple_exc_1  s    zTest_raise.test_tuple_exc_1c             C   s    d } d } |  j  | |  d  S)Nzraise (E1, (E2, E3), E4), Vzraise E1(V))r   )r   r8   r9   r   r   r   test_tuple_exc_2  s    zTest_raise.test_tuple_exc_2c             C   s   d } |  j  | d  d  S)Nzraise 'foo'z+Python 3 does not support string exceptions)r$   )r   rR   r   r   r   test_string_exc  s    zTest_raise.test_string_excc             C   s   d } |  j  | d  d  S)Nzraise "foo", 5z+Python 3 does not support string exceptions)r$   )r   rR   r   r   r   test_string_exc_val  s    zTest_raise.test_string_exc_valc             C   s   d } |  j  | d  d  S)Nzraise "foo", 5, 6z+Python 3 does not support string exceptions)r$   )r   rR   r   r   r   test_string_exc_val_tb  s    z!Test_raise.test_string_exc_val_tbc             C   s    d } d } |  j  | |  d  S)Nz4def foo():
                    raise Exception, 5, 6zCdef foo():
                    raise Exception(5).with_traceback(6))r   )r   r8   r9   r   r   r   	test_tb_1  s    zTest_raise.test_tb_1c             C   s    d } d } |  j  | |  d  S)Nzhdef foo():
                    a = 5
                    raise Exception, 5, 6
                    b = 6zwdef foo():
                    a = 5
                    raise Exception(5).with_traceback(6)
                    b = 6)r   )r   r8   r9   r   r   r   	test_tb_2  s    zTest_raise.test_tb_2c             C   s    d } d } |  j  | |  d  S)Nz2def foo():
                    raise Exception,5,6zCdef foo():
                    raise Exception(5).with_traceback(6))r   )r   r8   r9   r   r   r   	test_tb_3  s    zTest_raise.test_tb_3c             C   s    d } d } |  j  | |  d  S)Nzfdef foo():
                    a = 5
                    raise Exception,5,6
                    b = 6zwdef foo():
                    a = 5
                    raise Exception(5).with_traceback(6)
                    b = 6)r   )r   r8   r9   r   r   r   	test_tb_4  s    zTest_raise.test_tb_4c             C   s    d } d } |  j  | |  d  S)Nz<def foo():
                    raise Exception, (5, 6, 7), 6zIdef foo():
                    raise Exception(5, 6, 7).with_traceback(6))r   )r   r8   r9   r   r   r   	test_tb_5  s    zTest_raise.test_tb_5c             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   	test_tb_6  s    zTest_raise.test_tb_6N)r4   r'   r5   r   r:   rf   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s$   	r   c               @   s   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d  d!   Z d" d#   Z d$ d%   Z d& S)'
Test_throwthrowc             C   s    d } d } |  j  | |  d  S)Nzg.throw(Exception, 5)zg.throw(Exception(5)))r   )r   r8   r9   r   r   r   r>     s    zTest_throw.test_1c             C   s    d } d } |  j  | |  d  S)Nzg.throw(Exception,5)zg.throw(Exception(5)))r   )r   r8   r9   r   r   r   r?   	  s    zTest_throw.test_2c             C   s    d } d } |  j  | |  d  S)Nzg.throw(Exception, (5, 6, 7))zg.throw(Exception(5, 6, 7)))r   )r   r8   r9   r   r   r   r@     s    zTest_throw.test_3c             C   s    d } d } |  j  | |  d  S)Nz5 + g.throw(Exception, 5)z5 + g.throw(Exception(5)))r   )r   r8   r9   r   r   r   rA     s    zTest_throw.test_4c             C   s   d } |  j  | d  d  S)Nzg.throw("foo")z+Python 3 does not support string exceptions)r$   )r   rR   r   r   r   test_warn_1  s    zTest_throw.test_warn_1c             C   s   d } |  j  | d  d  S)Nzg.throw("foo", 5)z+Python 3 does not support string exceptions)r$   )r   rR   r   r   r   test_warn_2  s    zTest_throw.test_warn_2c             C   s   d } |  j  | d  d  S)Nzg.throw("foo", 5, 6)z+Python 3 does not support string exceptions)r$   )r   rR   r   r   r   test_warn_3"  s    zTest_throw.test_warn_3c             C   s   d } |  j  |  d  S)Nzg.throw(Exception))r"   )r   rR   r   r   r   test_untouched_1(  s    zTest_throw.test_untouched_1c             C   s   d } |  j  |  d  S)Nzg.throw(Exception(5, 6)))r"   )r   rR   r   r   r   test_untouched_2,  s    zTest_throw.test_untouched_2c             C   s   d } |  j  |  d  S)Nz5 + g.throw(Exception(5, 6)))r"   )r   rR   r   r   r   test_untouched_30  s    zTest_throw.test_untouched_3c             C   s    d } d } |  j  | |  d  S)Nz7def foo():
                    g.throw(Exception, 5, 6)zFdef foo():
                    g.throw(Exception(5).with_traceback(6)))r   )r   r8   r9   r   r   r   r   6  s    zTest_throw.test_tb_1c             C   s    d } d } |  j  | |  d  S)Nzkdef foo():
                    a = 5
                    g.throw(Exception, 5, 6)
                    b = 6zzdef foo():
                    a = 5
                    g.throw(Exception(5).with_traceback(6))
                    b = 6)r   )r   r8   r9   r   r   r   r   =  s    zTest_throw.test_tb_2c             C   s    d } d } |  j  | |  d  S)Nz5def foo():
                    g.throw(Exception,5,6)zFdef foo():
                    g.throw(Exception(5).with_traceback(6)))r   )r   r8   r9   r   r   r   r   H  s    zTest_throw.test_tb_3c             C   s    d } d } |  j  | |  d  S)Nzidef foo():
                    a = 5
                    g.throw(Exception,5,6)
                    b = 6zzdef foo():
                    a = 5
                    g.throw(Exception(5).with_traceback(6))
                    b = 6)r   )r   r8   r9   r   r   r   r   O  s    zTest_throw.test_tb_4c             C   s    d } d } |  j  | |  d  S)Nz?def foo():
                    g.throw(Exception, (5, 6, 7), 6)zLdef foo():
                    g.throw(Exception(5, 6, 7).with_traceback(6)))r   )r   r8   r9   r   r   r   r   Z  s    zTest_throw.test_tb_5c             C   s    d } d } |  j  | |  d  S)Nzsdef foo():
                    a = 5
                    g.throw(Exception, (5, 6, 7), 6)
                    b = 6zdef foo():
                    a = 5
                    g.throw(Exception(5, 6, 7).with_traceback(6))
                    b = 6)r   )r   r8   r9   r   r   r   r   a  s    zTest_throw.test_tb_6c             C   s    d } d } |  j  | |  d  S)Nz;def foo():
                    a + g.throw(Exception, 5, 6)zJdef foo():
                    a + g.throw(Exception(5).with_traceback(6)))r   )r   r8   r9   r   r   r   	test_tb_7l  s    zTest_throw.test_tb_7c             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   	test_tb_8s  s    zTest_throw.test_tb_8N)r4   r'   r5   r   r>   r?   r@   rA   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s&   r   c               @   sR   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d S)	Test_longlongc             C   s    d } d } |  j  | |  d  S)Nzx = long(x)z
x = int(x))r   )r   r8   r9   r   r   r   r>     s    zTest_long.test_1c             C   s    d } d } |  j  | |  d  S)Nzy = isinstance(x, long)zy = isinstance(x, int))r   )r   r8   r9   r   r   r   r?     s    zTest_long.test_2c             C   s    d } d } |  j  | |  d  S)Nzz = type(x) in (int, long)zz = type(x) in (int, int))r   )r   r8   r9   r   r   r   r@     s    zTest_long.test_3c             C   s   d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d  S)Nzlong = Truezs.long = Truezdef long(): passzclass long(): passzdef f(long): passzdef f(g, long): passzdef f(x, long=True): pass)r"   )r   rR   r   r   r   rc     s    zTest_long.test_unchangedc             C   s    d } d } |  j  | |  d  S)Nzx =   long(  x  )zx =   int(  x  ))r   )r   r8   r9   r   r   r   rf     s    z"Test_long.test_prefix_preservationN)	r4   r'   r5   r   r>   r?   r@   rc   rf   r   r   r   r   r   ~  s   r   c               @   s.   e  Z d  Z d Z d d   Z d d   Z d S)Test_execfileZexecfilec             C   s   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d	 } d
 } |  j  | |  d } d } |  j  | |  d  S)Nzexecfile("fn")z.exec(compile(open("fn").read(), "fn", 'exec'))zexecfile("fn", glob)z4exec(compile(open("fn").read(), "fn", 'exec'), glob)zexecfile("fn", glob, loc)z9exec(compile(open("fn").read(), "fn", 'exec'), glob, loc)zexecfile("fn", globals=glob)z<exec(compile(open("fn").read(), "fn", 'exec'), globals=glob)zexecfile("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   )r   r8   r9   r   r   r   test_conversion  s$    zTest_execfile.test_conversionc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzexecfile( "fn" )z0exec(compile(open( "fn" ).read(), "fn", 'exec'))zexecfile("fn",  globals = glob)z?exec(compile(open("fn").read(), "fn", 'exec'),  globals = glob))r   )r   r8   r9   r   r   r   test_spacing  s    zTest_execfile.test_spacingN)r4   r'   r5   r   r   r   r   r   r   r   r     s   r   c               @   s:   e  Z d  Z d Z d d   Z d d   Z d d   Z d S)	Test_isinstance
isinstancec             C   st   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)	Nzisinstance(x, (int, int, int))zisinstance(x, int)z,isinstance(x, (int, float, int, int, float))zisinstance(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   )r   r8   r9   r   r   r   test_remove_multiple_items  s    z*Test_isinstance.test_remove_multiple_itemsc             C   s    d } d } |  j  | |  d  S)Nz4if    isinstance(  foo(), (  bar, bar, baz )) : passz/if    isinstance(  foo(), (  bar, baz )) : pass)r   )r   r8   r9   r   r   r   rf     s    z(Test_isinstance.test_prefix_preservationc             C   s   |  j  d  d  S)Nzisinstance(x, (str, int)))r"   )r   r   r   r   rc     s    zTest_isinstance.test_unchangedN)r4   r'   r5   r   r   rf   rc   r   r   r   r   r     s   r   c               @   s  e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d  d!   Z d" d#   Z d$ d%   Z d& d'   Z d( d)   Z d* d+   Z d, d-   Z d. d/   Z d0 d1   Z d2 d3   Z d4 d5   Z d6 d7   Z d8 d9   Z d: d;   Z  d< d=   Z! d> d?   Z" d@ dA   Z# dB dC   Z$ dD dE   Z% dF dG   Z& dH S)I	Test_dictdictc             C   s   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d	 } d
 } |  j  | |  d } d } |  j  | |  d  S)Nzif   d. keys  (  )  : passz if   list(d. keys  (  ))  : passzif   d. items  (  )  : passz!if   list(d. items  (  ))  : passzif   d. iterkeys  ( )  : passzif   iter(d. keys  ( ))  : passz"[i for i in    d.  iterkeys(  )  ]z[i for i in    d.  keys(  )  ]zif   d. viewkeys  ( )  : passzif   d. keys  ( )  : passz"[i for i in    d.  viewkeys(  )  ])r   )r   r8   r9   r   r   r   rf     s$    z"Test_dict.test_prefix_preservationc             C   s   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d	 } d } |  j  | |  d  S)
Nzd.keys() # foozlist(d.keys()) # foozd.items()  # foozlist(d.items())  # foozd.iterkeys()  # fooziter(d.keys())  # fooz/[i for i in d.iterkeys() # foo
               ]z+[i for i in d.keys() # foo
               ]zd.viewitems()  # foo)r   )r   r8   r9   r   r   r   test_trailing_comment
  s$    zTest_dict.test_trailing_commentc             C   s]   xV t  j D]K } d | } |  j |  d | } |  j |  d | } |  j |  q
 Wd  S)Nzs = %s(d.keys())zs = %s(d.values())zs = %s(d.items()))r   consuming_callsr"   )r   wrapperrR   r   r   r   rc   '  s    


zTest_dict.test_unchangedc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzd.keys()zlist(d.keys())za[0].foo().keys()zlist(a[0].foo().keys()))r   )r   r8   r9   r   r   r   test_012  s    zTest_dict.test_01c             C   s    d } d } |  j  | |  d  S)Nz	d.items()zlist(d.items()))r   )r   r8   r9   r   r   r   test_02;  s    zTest_dict.test_02c             C   s    d } d } |  j  | |  d  S)Nz
d.values()zlist(d.values()))r   )r   r8   r9   r   r   r   test_03@  s    zTest_dict.test_03c             C   s    d } d } |  j  | |  d  S)Nzd.iterkeys()ziter(d.keys()))r   )r   r8   r9   r   r   r   test_04E  s    zTest_dict.test_04c             C   s    d } d } |  j  | |  d  S)Nzd.iteritems()ziter(d.items()))r   )r   r8   r9   r   r   r   test_05J  s    zTest_dict.test_05c             C   s    d } d } |  j  | |  d  S)Nzd.itervalues()ziter(d.values()))r   )r   r8   r9   r   r   r   test_06O  s    zTest_dict.test_06c             C   s   d } |  j  |  d  S)Nzlist(d.keys()))r"   )r   rR   r   r   r   test_07T  s    zTest_dict.test_07c             C   s   d } |  j  |  d  S)Nzsorted(d.keys()))r"   )r   rR   r   r   r   test_08X  s    zTest_dict.test_08c             C   s    d } d } |  j  | |  d  S)Nziter(d.keys())ziter(list(d.keys())))r   )r   r8   r9   r   r   r   test_09\  s    zTest_dict.test_09c             C   s    d } d } |  j  | |  d  S)Nzfoo(d.keys())zfoo(list(d.keys())))r   )r   r8   r9   r   r   r   rG   a  s    zTest_dict.test_10c             C   s    d } d } |  j  | |  d  S)Nzfor i in d.keys(): print iz for i in list(d.keys()): print i)r   )r   r8   r9   r   r   r   rH   f  s    zTest_dict.test_11c             C   s    d } d } |  j  | |  d  S)Nzfor i in d.iterkeys(): print izfor i in d.keys(): print i)r   )r   r8   r9   r   r   r   test_12k  s    zTest_dict.test_12c             C   s    d } d } |  j  | |  d  S)Nz[i for i in d.keys()]z[i for i in list(d.keys())])r   )r   r8   r9   r   r   r   test_13p  s    zTest_dict.test_13c             C   s    d } d } |  j  | |  d  S)Nz[i for i in d.iterkeys()]z[i for i in d.keys()])r   )r   r8   r9   r   r   r   test_14u  s    zTest_dict.test_14c             C   s    d } d } |  j  | |  d  S)Nz(i for i in d.keys())z(i for i in list(d.keys())))r   )r   r8   r9   r   r   r   test_15z  s    zTest_dict.test_15c             C   s    d } d } |  j  | |  d  S)Nz(i for i in d.iterkeys())z(i for i in d.keys()))r   )r   r8   r9   r   r   r   test_16  s    zTest_dict.test_16c             C   s    d } d } |  j  | |  d  S)Nziter(d.iterkeys())ziter(d.keys()))r   )r   r8   r9   r   r   r   test_17  s    zTest_dict.test_17c             C   s    d } d } |  j  | |  d  S)Nzlist(d.iterkeys())zlist(d.keys()))r   )r   r8   r9   r   r   r   test_18  s    zTest_dict.test_18c             C   s    d } d } |  j  | |  d  S)Nzsorted(d.iterkeys())zsorted(d.keys()))r   )r   r8   r9   r   r   r   test_19  s    zTest_dict.test_19c             C   s    d } d } |  j  | |  d  S)Nzfoo(d.iterkeys())zfoo(iter(d.keys())))r   )r   r8   r9   r   r   r   test_20  s    zTest_dict.test_20c             C   s    d } d } |  j  | |  d  S)Nzprint h.iterkeys().next()zprint iter(h.keys()).next())r   )r   r8   r9   r   r   r   test_21  s    zTest_dict.test_21c             C   s    d } d } |  j  | |  d  S)Nzprint h.keys()[0]zprint list(h.keys())[0])r   )r   r8   r9   r   r   r   test_22  s    zTest_dict.test_22c             C   s    d } d } |  j  | |  d  S)Nzprint list(h.iterkeys().next())z!print list(iter(h.keys()).next()))r   )r   r8   r9   r   r   r   test_23  s    zTest_dict.test_23c             C   s    d } d } |  j  | |  d  S)Nzfor x in h.keys()[0]: print xz#for x in list(h.keys())[0]: print x)r   )r   r8   r9   r   r   r   test_24  s    zTest_dict.test_24c             C   s    d } d } |  j  | |  d  S)Nzd.viewkeys()zd.keys())r   )r   r8   r9   r   r   r   test_25  s    zTest_dict.test_25c             C   s    d } d } |  j  | |  d  S)Nzd.viewitems()z	d.items())r   )r   r8   r9   r   r   r   test_26  s    zTest_dict.test_26c             C   s    d } d } |  j  | |  d  S)Nzd.viewvalues()z
d.values())r   )r   r8   r9   r   r   r   test_27  s    zTest_dict.test_27c             C   s    d } d } |  j  | |  d  S)Nz[i for i in d.viewkeys()]z[i for i in d.keys()])r   )r   r8   r9   r   r   r   test_28  s    zTest_dict.test_28c             C   s    d } d } |  j  | |  d  S)Nz(i for i in d.viewkeys())z(i for i in d.keys()))r   )r   r8   r9   r   r   r   test_29  s    zTest_dict.test_29c             C   s    d } d } |  j  | |  d  S)Nziter(d.viewkeys())ziter(d.keys()))r   )r   r8   r9   r   r   r   test_30  s    zTest_dict.test_30c             C   s    d } d } |  j  | |  d  S)Nzlist(d.viewkeys())zlist(d.keys()))r   )r   r8   r9   r   r   r   test_31  s    zTest_dict.test_31c             C   s    d } d } |  j  | |  d  S)Nzsorted(d.viewkeys())zsorted(d.keys()))r   )r   r8   r9   r   r   r   test_32  s    zTest_dict.test_32N)'r4   r'   r5   r   rf   r   rc   r   r   r   r   r   r   r   r   r   rG   rH   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     sH   	r   c               @   s   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d S)Test_xrangexrangec             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzx =    xrange(  10  )zx =    range(  10  )zx = xrange(  1  ,  10   )zx = range(  1  ,  10   )zx = xrange(  0  ,  10 ,  2 )zx = range(  0  ,  10 ,  2 ))r   )r   r8   r9   r   r   r   rf     s    z$Test_xrange.test_prefix_preservationc             C   s    d } d } |  j  | |  d  S)Nzx = xrange(10)zx = range(10))r   )r   r8   r9   r   r   r   test_single_arg  s    zTest_xrange.test_single_argc             C   s    d } d } |  j  | |  d  S)Nzx = xrange(1, 10)zx = range(1, 10))r   )r   r8   r9   r   r   r   test_two_args  s    zTest_xrange.test_two_argsc             C   s    d } d } |  j  | |  d  S)Nzx = xrange(0, 10, 2)zx = range(0, 10, 2))r   )r   r8   r9   r   r   r   test_three_args  s    zTest_xrange.test_three_argsc             C   s   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d	 } d
 } |  j  | |  d  S)Nzx = range(10, 3, 9)zx = list(range(10, 3, 9))zx = foo(range(10, 3, 9))zx = foo(list(range(10, 3, 9)))zx = range(10, 3, 9) + [4]zx = list(range(10, 3, 9)) + [4]zx = range(10)[::-1]zx = list(range(10))[::-1]zx = range(10)  [3]zx = list(range(10))  [3])r   )r   r8   r9   r   r   r   test_wrap_in_list  s    zTest_xrange.test_wrap_in_listc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzfor i in xrange(10):
    j=izfor i in range(10):
    j=iz[i for i in xrange(10)]z[i for i in range(10)])r   )r   r8   r9   r   r   r   test_xrange_in_for  s    zTest_xrange.test_xrange_in_forc             C   s   |  j  d  |  j  d  d  S)Nzfor i in range(10): passz[i for i in range(10)])r"   )r   r   r   r   test_range_in_for  s    zTest_xrange.test_range_in_forc             C   s   |  j  d  d  S)Nzx in range(10, 3, 9))r"   )r   r   r   r   test_in_contains_test  s    z!Test_xrange.test_in_contains_testc             C   s)   x" t  j D] } |  j d |  q
 Wd  S)Nza = %s(range(10)))r   r   r"   )r   callr   r   r   test_in_consuming_context  s    z%Test_xrange.test_in_consuming_contextN)r4   r'   r5   r   rf   r   r   r   r   r   r   r   r   r   r   r   r   r     s   	r   c                   s.   e  Z d  Z   f d d   Z d d   Z   S)Test_xrange_with_reducec                s    t  t |   j d d g  d  S)Nr   rh   )superr   r   )r   )r&   r   r   r     s    zTest_xrange_with_reduce.setUpc             C   s    d } d } |  j  | |  d  S)Nzreduce(x, xrange(5))z0from functools import reduce
reduce(x, range(5)))r   )r   r8   r9   r   r   r   test_double_transform!  s    z-Test_xrange_with_reduce.test_double_transform)r4   r'   r5   r   r   r   r   )r&   r   r     s   r   c               @   sv   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d S)Test_raw_inputZ	raw_inputc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzx =    raw_input(   )zx =    input(   )zx = raw_input(   ''   )zx = input(   ''   ))r   )r   r8   r9   r   r   r   rf   *  s    z'Test_raw_input.test_prefix_preservationc             C   s    d } d } |  j  | |  d  S)Nzx = raw_input()zx = input())r   )r   r8   r9   r   r   r   r>   3  s    zTest_raw_input.test_1c             C   s    d } d } |  j  | |  d  S)Nzx = raw_input('')zx = input(''))r   )r   r8   r9   r   r   r   r?   8  s    zTest_raw_input.test_2c             C   s    d } d } |  j  | |  d  S)Nzx = raw_input('prompt')zx = input('prompt'))r   )r   r8   r9   r   r   r   r@   =  s    zTest_raw_input.test_3c             C   s    d } d } |  j  | |  d  S)Nzx = raw_input(foo(a) + 6)zx = input(foo(a) + 6))r   )r   r8   r9   r   r   r   rA   B  s    zTest_raw_input.test_4c             C   s    d } d } |  j  | |  d  S)Nzx = raw_input(invite).split()zx = input(invite).split())r   )r   r8   r9   r   r   r   rB   G  s    zTest_raw_input.test_5c             C   s    d } d } |  j  | |  d  S)Nz x = raw_input(invite) . split ()zx = input(invite) . split ())r   )r   r8   r9   r   r   r   rC   L  s    zTest_raw_input.test_6c             C   s    d } d } |  j  | |  d  S)Nzx = int(raw_input())zx = int(input()))r   )r   r8   r9   r   r   r   rE   Q  s    zTest_raw_input.test_8N)r4   r'   r5   r   rf   r>   r?   r@   rA   rB   rC   rE   r   r   r   r   r   '  s   	r   c               @   sI   e  Z d  Z d Z d d d d d d d g Z d	 d
   Z d d   Z d S)Test_funcattrsZ	funcattrsZclosuredocnamedefaultscodeglobalsr   c             C   s`   xY |  j  D]N } d | } d | } |  j | |  d | } d | } |  j | |  q
 Wd  S)Nz	a.func_%sza.__%s__zself.foo.func_%s.foo_barzself.foo.__%s__.foo_bar)attrsr   )r   attrr8   r9   r   r   r   r`   [  s    



zTest_funcattrs.testc             C   s]   xV |  j  D]K } d | } |  j |  d | } |  j |  d | } |  j |  q
 Wd  S)Nzfoo(func_%s + 5)zf(foo.__%s__)zf(foo.__%s__.foo))r   r"   )r   r   rR   r   r   r   rc   e  s    


zTest_funcattrs.test_unchangedN)r4   r'   r5   r   r   r`   rc   r   r   r   r   r   V  s   
r   c               @   s:   e  Z d  Z d Z d d   Z d d   Z d d   Z d S)	Test_xreadlinesZ
xreadlinesc             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzfor x in f.xreadlines(): passzfor x in f: passz!for x in foo().xreadlines(): passzfor x in foo(): passz'for x in (5 + foo()).xreadlines(): passzfor x in (5 + foo()): pass)r   )r   r8   r9   r   r   r   rO   s  s    zTest_xreadlines.test_callc             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzfoo(f.xreadlines + 5)zfoo(f.__iter__ + 5)zfoo(f().xreadlines + 5)zfoo(f().__iter__ + 5)zfoo((5 + f()).xreadlines + 5)zfoo((5 + f()).__iter__ + 5))r   )r   r8   r9   r   r   r   test_attr_ref  s    zTest_xreadlines.test_attr_refc             C   sP   d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d  S)Nzfor x in f.xreadlines(5): passz for x in f.xreadlines(k=5): passz$for x in f.xreadlines(*k, **v): passzfoo(xreadlines))r"   )r   rR   r   r   r   rc     s    zTest_xreadlines.test_unchangedN)r4   r'   r5   r   rO   r   rc   r   r   r   r   r   p  s   r   c               @   sX   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d d   Z d S)ImportsFixerTestsc             C   sl   xe |  j  j   D]T \ } } d | } d | } |  j | |  d | } d | } |  j | |  q Wd  S)Nz	import %szimport foo, %s, bar)modulesitemsr   )r   oldnewr8   r9   r   r   r   test_import_module  s    



z$ImportsFixerTests.test_import_modulec             C   s   x |  j  j   D]x \ } } d | } d | } |  j | |  d | } d | } |  j | |  d | } d | } |  j | |  q Wd  S)Nzfrom %s import foozfrom %s import foo, barzfrom %s import (yes, no))r   r   r   )r   r   r   r8   r9   r   r   r   test_import_from  s    





z"ImportsFixerTests.test_import_fromc             C   sl   xe |  j  j   D]T \ } } d | } d | } |  j | |  d | } d | } |  j | |  q Wd  S)Nzimport %s as foo_bar)r   r   r   )r   r   r   r8   r9   r   r   r   test_import_module_as  s    



z'ImportsFixerTests.test_import_module_asc             C   sH   xA |  j  j   D]0 \ } } d | } d | } |  j | |  q Wd  S)Nzfrom %s import foo as bar)r   r   r   )r   r   r   r8   r9   r   r   r   test_import_from_as  s    

z%ImportsFixerTests.test_import_from_asc             C   sH   xA |  j  j   D]0 \ } } d | } d | } |  j | |  q Wd  S)Nzfrom %s import *)r   r   r   )r   r   r   r8   r9   r   r   r   	test_star  s    

zImportsFixerTests.test_starc             C   s  x |  j  j   D] \ } } d | | f } d | | f } |  j | |  d | | f } d | | f } |  j | |  d | f } |  j |  d | | | f } d | | | f } |  j | |  d | | f } d | | f } |  j | |  q Wd  S)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   r   r"   )r   r   r   r8   r9   rR   r   r   r   test_import_module_usage  s    z*ImportsFixerTests.test_import_module_usageN)	r4   r'   r5   r   r   r   r   r   r   r   r   r   r   r     s   

r   c               @   s>   e  Z d  Z d Z d d l m Z d d   Z d d   Z d S)	Test_importsimports   )MAPPINGc             C   s    d } d } |  j  | |  d  S)Nzimport urlparse, cStringIOzimport urllib.parse, io)r   )r   r8   r9   r   r   r   test_multiple_imports  s    z"Test_imports.test_multiple_importsc             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   test_multiple_imports_as  s    z%Test_imports.test_multiple_imports_asN)	r4   r'   r5   r   fixes.fix_importsr   r   r   r  r   r   r   r   r     s   r   c               @   s&   e  Z d  Z d Z d d l m Z d S)Test_imports2imports2r   )r   N)r4   r'   r5   r   fixes.fix_imports2r   r   r   r   r   r   r    s   r  c                   s.   e  Z d  Z   f d d   Z d d   Z   S)Test_imports_fixer_orderc                sq   t  t |   j d d g  d d l m } | j   |  _ d d l m } x d	 D] } | | |  j | <qR Wd  S)
Nr   r  r   )r   dbhashdumbdbmdbmgdbm)zdbhashzdumbdbmzdbmzgdbm)r   r  r   r  r   copyr   r  )r   Zmapping2Zmapping1key)r&   r   r   r     s    zTest_imports_fixer_order.setUpc             C   s+   x$ d D] } | |  _  |  j d  q Wd  S)Nr   r  import)zimportszimports2)r   r3   )r   Zfixr   r   r   $test_after_local_imports_refactoring!  s    	z=Test_imports_fixer_order.test_after_local_imports_refactoring)r4   r'   r5   r   r  r   r   )r&   r   r    s   r  c               @   sz   e  Z d  Z d Z d d l m Z d d   Z d d   Z d d	   Z	 d
 d   Z
 d d   Z d d   Z d d   Z d S)Test_urlliburllibr   )r   c             C   s`   xY |  j  j   D]H \ } } d | } d d j t t d  |   } |  j | |  q Wd  S)Nz	import %sz, r   )r   r   r    mapr   r   )r   r   changesr8   r9   r   r   r   r   +  s    
"zTest_urllib.test_import_modulec       
      C   sM  xF|  j  j   D]5\ } } g  } x | D] \ } } xb | D]Z } | j |  d | | f } d | | f } |  j | |  d | }	 |  j |	  q< Wd | d j |  f } d | d j |  f } |  j | |  d d j |  }	 |  j |	  q) Wd | d j |  f } d j d d   | D  } |  j | |  q Wd  S)Nzfrom %s import %szfrom foo import %sz, 
c             S   s/   g  |  ]% \ } } d  | d j  |  f  q S)zfrom %s import %sz, )r    )r(   r   membersr   r   r   r*   G  s   	z0Test_urllib.test_import_from.<locals>.<listcomp>)r   r   appendr   r"   r    )
r   r   r  Zall_membersr   r  memberr8   r9   rR   r   r   r   r   1  s&    
zTest_urllib.test_import_fromc             C   s2   x+ |  j  D]  } d | } |  j | d  q
 Wd  S)Nzimport %s as fooz#This module is now multiple modules)r   r$   )r   r   rR   r   r   r   r   K  s    
z!Test_urllib.test_import_module_asc             C   s   x |  j  j   D] \ } } x | D] \ } } xt | D]l } d | | f } d | | f } |  j | |  d | | | f } d | | | f } |  j | |  q6 Wq# Wq Wd  S)Nzfrom %s import %s as foo_barzfrom %s import %s as blah, %s)r   r   r   )r   r   r  r   r  r  r8   r9   r   r   r   r   P  s    zTest_urllib.test_import_from_asc             C   s2   x+ |  j  D]  } d | } |  j | d  q
 Wd  S)Nzfrom %s import *zCannot handle star imports)r   r$   )r   r   rR   r   r   r   r   [  s    
zTest_urllib.test_starc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   test_indented`  s    zTest_urllib.test_indentedc       	   	   C   s   x |  j  j   D] \ } } x | D] \ } } x | D] } d j d d   |  j  | D  } d | | | f } d | | | f } |  j | |  d | | | | | f } d | | | | | f } |  j | |  q6 Wq# Wq Wd  S)Nz, c             S   s   g  |  ] \ } } |  q Sr   r   )r(   r2   Zmemsr   r   r   r*     s   	 z8Test_urllib.test_import_module_usage.<locals>.<listcomp>z^
                        import %s
                        foo(%s.%s)
                        z`
                        import %s
                        %s.%s(%s.%s)
                        )r   r   r    r   )	r   r   r  r   r  r  Z
new_importr8   r9   r   r   r   r   {  s    z$Test_urllib.test_import_module_usageN)r4   r'   r5   r   Zfixes.fix_urllibr   r   r   r   r   r   r   r  r   r   r   r   r   r  '  s   r  c               @   sj   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d S)
Test_inputinputc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzx =   input(   )zx =   eval(input(   ))zx = input(   ''   )zx = eval(input(   ''   )))r   )r   r8   r9   r   r   r   rf     s    z#Test_input.test_prefix_preservationc             C   s    d } d } |  j  | |  d  S)Nzx = input()  #  foozx = eval(input())  #  foo)r   )r   r8   r9   r   r   r   r     s    z Test_input.test_trailing_commentc             C   s=   d } |  j  |  d } |  j  |  d } |  j  |  d  S)Nzx = eval(input())zx = eval(input(''))zx = eval(input(foo(5) + 9)))r"   )r   rR   r   r   r   rn     s    zTest_input.test_idempotencyc             C   s    d } d } |  j  | |  d  S)Nzx = input()zx = eval(input()))r   )r   r8   r9   r   r   r   r>     s    zTest_input.test_1c             C   s    d } d } |  j  | |  d  S)Nzx = input('')zx = eval(input('')))r   )r   r8   r9   r   r   r   r?     s    zTest_input.test_2c             C   s    d } d } |  j  | |  d  S)Nzx = input('prompt')zx = eval(input('prompt')))r   )r   r8   r9   r   r   r   r@     s    zTest_input.test_3c             C   s    d } d } |  j  | |  d  S)Nzx = input(foo(5) + 9)zx = eval(input(foo(5) + 9)))r   )r   r8   r9   r   r   r   rA     s    zTest_input.test_4N)r4   r'   r5   r   rf   r   rn   r>   r?   r@   rA   r   r   r   r   r    s   	
r  c               @   s  e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d  d!   Z d" d#   Z d$ d%   Z d& d'   Z d( d)   Z d* S)+Test_tuple_paramsZtuple_paramsc             C   s   d } |  j  |  d  S)Nzdef foo(): pass)r"   )r   rR   r   r   r   rS     s    z"Test_tuple_params.test_unchanged_1c             C   s   d } |  j  |  d  S)Nzdef foo(a, b, c): pass)r"   )r   rR   r   r   r   rT     s    z"Test_tuple_params.test_unchanged_2c             C   s   d } |  j  |  d  S)Nzdef foo(a=3, b=4, c=5): pass)r"   )r   rR   r   r   r   rU     s    z"Test_tuple_params.test_unchanged_3c             C   s    d } d } |  j  | |  d  S)Nz8
            def foo(((a, b), c)):
                x = 5zn
            def foo(xxx_todo_changeme):
                ((a, b), c) = xxx_todo_changeme
                x = 5)r   )r   r8   r9   r   r   r   r>     s    zTest_tuple_params.test_1c             C   s    d } d } |  j  | |  d  S)Nz;
            def foo(((a, b), c), d):
                x = 5zq
            def foo(xxx_todo_changeme, d):
                ((a, b), c) = xxx_todo_changeme
                x = 5)r   )r   r8   r9   r   r   r   r?     s    zTest_tuple_params.test_2c             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   r@     s    zTest_tuple_params.test_3c             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   test_semicolon  s    z Test_tuple_params.test_semicolonc             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   test_keywords  s    zTest_tuple_params.test_keywordsc             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   test_varargs  s    zTest_tuple_params.test_varargsc             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   test_multi_1  s    zTest_tuple_params.test_multi_1c             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   test_multi_2  s    zTest_tuple_params.test_multi_2c             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   test_docstring*  s    z Test_tuple_params.test_docstringc             C   s   d } |  j  |  d  S)Nzlambda x: x + 5)r"   )r   rR   r   r   r   test_lambda_no_change8  s    z'Test_tuple_params.test_lambda_no_changec             C   st   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzlambda (x): x + 5zlambda x: x + 5zlambda(x): x + 5zlambda ((((x)))): x + 5zlambda((((x)))): x + 5)r   )r   r8   r9   r   r   r   test_lambda_parens_single_arg<  s    z/Test_tuple_params.test_lambda_parens_single_argc             C   st   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzlambda (x, y): x + f(y)zlambda x_y: x_y[0] + f(x_y[1])zlambda(x, y): x + f(y)zlambda (((x, y))): x + f(y)zlambda(((x, y))): x + f(y))r   )r   r8   r9   r   r   r   test_lambda_simpleM  s    z$Test_tuple_params.test_lambda_simplec             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzlambda (x,): x + f(x)zlambda x1: x1[0] + f(x1[0])zlambda (((x,))): x + f(x))r   )r   r8   r9   r   r   r   test_lambda_one_tuple^  s    z'Test_tuple_params.test_lambda_one_tuplec             C   s    d } d } |  j  | |  d  S)Nzlambda (x, y): x + x + f(x) + xz0lambda x_y: x_y[0] + x_y[0] + f(x_y[0]) + x_y[0])r   )r   r8   r9   r   r   r   test_lambda_simple_multi_useg  s    z.Test_tuple_params.test_lambda_simple_multi_usec             C   s    d } d } |  j  | |  d  S)Nzlambda (x, y): y + xzlambda x_y: x_y[1] + x_y[0])r   )r   r8   r9   r   r   r   test_lambda_simple_reversel  s    z,Test_tuple_params.test_lambda_simple_reversec             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzlambda (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   )r   r8   r9   r   r   r   test_lambda_nestedq  s    z$Test_tuple_params.test_lambda_nestedc             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   test_lambda_nested_multi_usez  s    z.Test_tuple_params.test_lambda_nested_multi_useN)r4   r'   r5   r   rS   rT   rU   r>   r?   r@   r  r  r  r  r  r   r!  r"  r#  r$  r%  r&  r'  r(  r   r   r   r   r    s*   		r  c               @   s=   e  Z d  Z d Z d d d g Z d d   Z d d   Z d	 S)
Test_methodattrsZmethodattrsfuncr   classc             C   s   x |  j  D]x } d | } | d k r/ d } n
 d | } |  j | |  d | } | d k rh d } n
 d | } |  j | |  q
 Wd  S)Nza.im_%sr+  za.__self__.__class__za.__%s__zself.foo.im_%s.foo_barz#self.foo.__self__.__class__.foo_barzself.foo.__%s__.foo_bar)r   r   )r   r   r8   r9   r   r   r   r`     s    
	

	
zTest_methodattrs.testc             C   s]   xV |  j  D]K } d | } |  j |  d | } |  j |  d | } |  j |  q
 Wd  S)Nzfoo(im_%s + 5)zf(foo.__%s__)zf(foo.__%s__.foo))r   r"   )r   r   rR   r   r   r   rc     s    


zTest_methodattrs.test_unchangedN)r4   r'   r5   r   r   r`   rc   r   r   r   r   r)    s   r)  c               @   s2  e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d  d!   Z d" d#   Z d$ d%   Z d& d'   Z d( d)   Z d* d+   Z d, d-   Z d. d/   Z d0 d1   Z d2 d3   Z d4 d5   Z d6 d7   Z d8 d9   Z d: d;   Z  d< d=   Z! d> d?   Z" d@ dA   Z# dB dC   Z$ dD dE   Z% dF dG   Z& dH dI   Z' dJ dK   Z( dL dM   Z) dN dO   Z* dP dQ   Z+ dR dS   Z, dT dU   Z- dV dW   Z. dX dY   Z/ dZ d[   Z0 d\ S)]	Test_nextnextc             C   s    d } d } |  j  | |  d  S)Nz	it.next()znext(it))r   )r   r8   r9   r   r   r   r>     s    zTest_next.test_1c             C   s    d } d } |  j  | |  d  S)Nza.b.c.d.next()znext(a.b.c.d))r   )r   r8   r9   r   r   r   r?     s    zTest_next.test_2c             C   s    d } d } |  j  | |  d  S)Nz(a + b).next()znext((a + b)))r   )r   r8   r9   r   r   r   r@     s    zTest_next.test_3c             C   s    d } d } |  j  | |  d  S)Nz
a().next()z	next(a()))r   )r   r8   r9   r   r   r   rA     s    zTest_next.test_4c             C   s    d } d } |  j  | |  d  S)Nza().next() + bznext(a()) + b)r   )r   r8   r9   r   r   r   rB     s    zTest_next.test_5c             C   s    d } d } |  j  | |  d  S)Nzc(      a().next() + b)zc(      next(a()) + b))r   )r   r8   r9   r   r   r   rC     s    zTest_next.test_6c             C   s    d } d } |  j  | |  d  S)NzU
            for a in b:
                foo(a)
                a.next()
            zT
            for a in b:
                foo(a)
                next(a)
            )r   )r   r8   r9   r   r   r   test_prefix_preservation_1  s    z$Test_next.test_prefix_preservation_1c             C   s    d } d } |  j  | |  d  S)Nzq
            for a in b:
                foo(a) # abc
                # def
                a.next()
            zp
            for a in b:
                foo(a) # abc
                # def
                next(a)
            )r   )r   r8   r9   r   r   r   test_prefix_preservation_2  s    z$Test_next.test_prefix_preservation_2c             C   s&   d } d } |  j  | | d d d  S)Nzj
            next = 5
            for a in b:
                foo(a)
                a.next()
            zn
            next = 5
            for a in b:
                foo(a)
                a.__next__()
            r   T)r   )r   r8   r9   r   r   r   test_prefix_preservation_3  s    z$Test_next.test_prefix_preservation_3c             C   s&   d } d } |  j  | | d d d  S)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__()
            r   T)r   )r   r8   r9   r   r   r   test_prefix_preservation_4  s    z$Test_next.test_prefix_preservation_4c             C   s&   d } d } |  j  | | d d d  S)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__())
            r   T)r   )r   r8   r9   r   r   r   test_prefix_preservation_5  s    z$Test_next.test_prefix_preservation_5c             C   s    d } d } |  j  | |  d  S)Nze
            for a in b:
                foo(foo(a), # abc
                    a.next())
            zd
            for a in b:
                foo(foo(a), # abc
                    next(a))
            )r   )r   r8   r9   r   r   r   test_prefix_preservation_6	  s    z$Test_next.test_prefix_preservation_6c             C   s    d } d } |  j  | |  d  S)Nz[
            class A:
                def next(self):
                    pass
            z_
            class A:
                def __next__(self):
                    pass
            )r   )r   r8   r9   r   r   r   test_method_1	  s    zTest_next.test_method_1c             C   s    d } d } |  j  | |  d  S)Nzc
            class A(object):
                def next(self):
                    pass
            zg
            class A(object):
                def __next__(self):
                    pass
            )r   )r   r8   r9   r   r   r   test_method_2%	  s    zTest_next.test_method_2c             C   s    d } d } |  j  | |  d  S)NzX
            class A:
                def next(x):
                    pass
            z\
            class A:
                def __next__(x):
                    pass
            )r   )r   r8   r9   r   r   r   test_method_32	  s    zTest_next.test_method_3c             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   test_method_4?	  s    zTest_next.test_method_4c             C   s   d } |  j  |  d  S)Nza
            class A:
                def next(self, a, b):
                    pass
            )r"   )r   rR   r   r   r   test_method_unchangedX	  s    zTest_next.test_method_unchangedc             C   s   d } |  j  | d  d  S)Nzy
            next = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_assign_simple`	  s    z&Test_next.test_shadowing_assign_simplec             C   s   d } |  j  | d  d  S)Nz~
            (next, a) = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_assign_tuple_1j	  s    z'Test_next.test_shadowing_assign_tuple_1c             C   s   d } |  j  | d  d  S)Nz
            (a, (b, (next, c)), a) = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_assign_tuple_2t	  s    z'Test_next.test_shadowing_assign_tuple_2c             C   s   d } |  j  | d  d  S)Nz~
            [next, a] = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_assign_list_1~	  s    z&Test_next.test_shadowing_assign_list_1c             C   s   d } |  j  | d  d  S)Nz
            [a, [b, [next, c]], a] = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_assign_list_2	  s    z&Test_next.test_shadowing_assign_list_2c             C   s   d } |  j  | d  d  S)Nz
            def foo():
                __builtin__.next = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_builtin_assign	  s    zTest_next.test_builtin_assignc             C   s   d } |  j  | d  d  S)Nz
            def foo():
                (a, __builtin__.next) = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_builtin_assign_in_tuple	  s    z&Test_next.test_builtin_assign_in_tuplec             C   s   d } |  j  | d  d  S)Nz
            def foo():
                [a, __builtin__.next] = foo

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_builtin_assign_in_list	  s    z%Test_next.test_builtin_assign_in_listc             C   s   d } |  j  |  d  S)Nz
            def foo():
                A.next = foo

            class A:
                def next(self, a, b):
                    pass
            )r"   )r   rR   r   r   r   test_assign_to_next	  s    zTest_next.test_assign_to_nextc             C   s   d } |  j  |  d  S)Nz
            def foo():
                (a, A.next) = foo

            class A:
                def next(self, a, b):
                    pass
            )r"   )r   rR   r   r   r   test_assign_to_next_in_tuple	  s    z&Test_next.test_assign_to_next_in_tuplec             C   s   d } |  j  |  d  S)Nz
            def foo():
                [a, A.next] = foo

            class A:
                def next(self, a, b):
                    pass
            )r"   )r   rR   r   r   r   test_assign_to_next_in_list	  s    z%Test_next.test_assign_to_next_in_listc             C   s   d } |  j  | d  d  S)Nz
            import foo.bar as next

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_import_1	  s    z!Test_next.test_shadowing_import_1c             C   s   d } |  j  | d  d  S)Nz
            import bar, bar.foo as next

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_import_2	  s    z!Test_next.test_shadowing_import_2c             C   s   d } |  j  | d  d  S)Nz
            import bar, bar.foo as next, baz

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_import_3	  s    z!Test_next.test_shadowing_import_3c             C   s   d } |  j  | d  d  S)Nz
            from x import next

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_import_from_1	  s    z&Test_next.test_shadowing_import_from_1c             C   s   d } |  j  | d  d  S)Nz
            from x.a import next

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_import_from_2	  s    z&Test_next.test_shadowing_import_from_2c             C   s   d } |  j  | d  d  S)Nz
            from x import a, next, b

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_import_from_3
  s    z&Test_next.test_shadowing_import_from_3c             C   s   d } |  j  | d  d  S)Nz
            from x.a import a, next, b

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_import_from_4
  s    z&Test_next.test_shadowing_import_from_4c             C   s   d } |  j  | d  d  S)Nz
            def next(a):
                pass

            class A:
                def next(self, a, b):
                    pass
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_funcdef_1
  s    z"Test_next.test_shadowing_funcdef_1c             C   s#   d } d } |  j  | | d  d  S)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#   )r   r8   r9   r   r   r   test_shadowing_funcdef_2%
  s    

z"Test_next.test_shadowing_funcdef_2c             C   s   d } |  j  | d  d  S)NzW
            def f():
                global next
                next = 5
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_global_1<
  s    z!Test_next.test_shadowing_global_1c             C   s   d } |  j  | d  d  S)Nz]
            def f():
                global a, next, b
                next = 5
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_global_2D
  s    z!Test_next.test_shadowing_global_2c             C   s   d } |  j  | d  d  S)Nze
            for next in it():
                pass

            b = 5
            c = 6
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_for_simpleL
  s    z#Test_next.test_shadowing_for_simplec             C   s   d } |  j  | d  d  S)Nzh
            for next, b in it():
                pass

            b = 5
            c = 6
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_for_tuple_1V
  s    z$Test_next.test_shadowing_for_tuple_1c             C   s   d } |  j  | d  d  S)Nzp
            for a, (next, c), b in it():
                pass

            b = 5
            c = 6
            z)Calls to builtin next() possibly shadowed)r$   )r   rR   r   r   r   test_shadowing_for_tuple_2`
  s    z$Test_next.test_shadowing_for_tuple_2c             C   s    d } d } |  j  | |  d  S)Nzgnext = g.nextzgnext = g.__next__)r   )r   r8   r9   r   r   r   test_noncall_access_1j
  s    zTest_next.test_noncall_access_1c             C   s    d } d } |  j  | |  d  S)Nzf(g.next + 5)zf(g.__next__ + 5))r   )r   r8   r9   r   r   r   test_noncall_access_2o
  s    zTest_next.test_noncall_access_2c             C   s    d } d } |  j  | |  d  S)Nzf(g().next + 5)zf(g().__next__ + 5))r   )r   r8   r9   r   r   r   test_noncall_access_3t
  s    zTest_next.test_noncall_access_3N)1r4   r'   r5   r   r>   r?   r@   rA   rB   rC   r.  r/  r0  r1  r2  r3  r4  r5  r6  r7  r8  r9  r:  r;  r<  r=  r>  r?  r@  rA  rB  rC  rD  rE  rF  rG  rH  rI  rJ  rK  rL  rM  rN  rO  rP  rQ  rR  rS  rT  r   r   r   r   r,    s\   














r,  c               @   sR   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d S)Test_nonzeroZnonzeroc             C   s    d } d } |  j  | |  d  S)Nzb
            class A:
                def __nonzero__(self):
                    pass
            z_
            class A:
                def __bool__(self):
                    pass
            )r   )r   r8   r9   r   r   r   r>   |
  s    zTest_nonzero.test_1c             C   s    d } d } |  j  | |  d  S)Nzj
            class A(object):
                def __nonzero__(self):
                    pass
            zg
            class A(object):
                def __bool__(self):
                    pass
            )r   )r   r8   r9   r   r   r   r?   
  s    zTest_nonzero.test_2c             C   s   d } |  j  |  d  S)Nzg
            class A(object):
                def __bool__(self):
                    pass
            )r"   )r   rR   r   r   r   rS   
  s    zTest_nonzero.test_unchanged_1c             C   s   d } |  j  |  d  S)Nzm
            class A(object):
                def __nonzero__(self, a):
                    pass
            )r"   )r   rR   r   r   r   rT   
  s    zTest_nonzero.test_unchanged_2c             C   s   d } |  j  |  d  S)NzE
            def __nonzero__(self):
                pass
            )r"   )r   rR   r   r   r   test_unchanged_func
  s    z Test_nonzero.test_unchanged_funcN)	r4   r'   r5   r   r>   r?   rS   rT   rV  r   r   r   r   rU  y
  s   rU  c               @   s   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d S)Test_numliteralsZnumliteralsc             C   s    d } d } |  j  | |  d  S)NZ07550o755)r   )r   r8   r9   r   r   r   test_octal_1
  s    zTest_numliterals.test_octal_1c             C   s    d } d } |  j  | |  d  S)Nza = 12Lza = 12)r   )r   r8   r9   r   r   r   test_long_int_1
  s    z Test_numliterals.test_long_int_1c             C   s    d } d } |  j  | |  d  S)Nza = 12lza = 12)r   )r   r8   r9   r   r   r   test_long_int_2
  s    z Test_numliterals.test_long_int_2c             C   s    d } d } |  j  | |  d  S)Nz	b = 0x12lzb = 0x12)r   )r   r8   r9   r   r   r   test_long_hex
  s    zTest_numliterals.test_long_hexc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzb =   0x12Lz
b =   0x12zb = 0755 # spamzb = 0o755 # spam)r   )r   r8   r9   r   r   r   test_comments_and_spacing
  s    z*Test_numliterals.test_comments_and_spacingc             C   s   d } |  j  |  d  S)N5)r"   )r   rR   r   r   r   test_unchanged_int
  s    z#Test_numliterals.test_unchanged_intc             C   s   d } |  j  |  d  S)Nz5.0)r"   )r   rR   r   r   r   test_unchanged_float
  s    z%Test_numliterals.test_unchanged_floatc             C   s   d } |  j  |  d  S)NrX  )r"   )r   rR   r   r   r   test_unchanged_octal
  s    z%Test_numliterals.test_unchanged_octalc             C   s   d } |  j  |  d  S)NZ0xABC)r"   )r   rR   r   r   r   test_unchanged_hex
  s    z#Test_numliterals.test_unchanged_hexc             C   s   d } |  j  |  d  S)Nz5.0e10)r"   )r   rR   r   r   r   test_unchanged_exp
  s    z#Test_numliterals.test_unchanged_expc             C   s   d } |  j  |  d  S)Nz5 + 4j)r"   )r   rR   r   r   r   test_unchanged_complex_int
  s    z+Test_numliterals.test_unchanged_complex_intc             C   s   d } |  j  |  d  S)Nz
5.4 + 4.9j)r"   )r   rR   r   r   r   test_unchanged_complex_float
  s    z-Test_numliterals.test_unchanged_complex_floatc             C   s*   d } |  j  |  d } |  j  |  d  S)NZ4jz4.4j)r"   )r   rR   r   r   r   test_unchanged_complex_bare
  s    z,Test_numliterals.test_unchanged_complex_bareN)r4   r'   r5   r   rY  rZ  r[  r\  r]  r_  r`  ra  rb  rc  rd  re  rf  r   r   r   r   rW  
  s   	rW  c               @   sR   e  Z d  Z d Z d d i Z d d   Z d d   Z d	 d
   Z d d   Z d S)Test_renamesrenamessysmaxintmaxsizec             C   sw   xp t  |  j j    D]Y \ } \ } } d | | f } d | | f } |  j | |  d | } |  j |  q Wd  S)Nzfrom %s import %szfrom foo import %s)listr   r   r   r"   )r   modr   r   r8   r9   rR   r   r   r   r   
  s    (
zTest_renames.test_import_fromc             C   s`   xY t  |  j j    D]B \ } \ } } d | | f } d | | f } |  j | |  q Wd  S)Nzfrom %s import %s as foo_bar)rl  r   r   r   )r   rm  r   r   r8   r9   r   r   r   r   
  s    (z Test_renames.test_import_from_asc             C   sl   xe t  |  j j    D]N \ } \ } } d | | | | f } d | | | | f } |  j | |  q Wd  S)NzJ
                import %s
                foo(%s, %s.%s)
                )rl  r   r   r   )r   rm  r   r   r8   r9   r   r   r   r     s    (z%Test_renames.test_import_module_usagec             C   sl   xe t  |  j j    D]N \ } \ } } d | | | | f } d | | | | f } |  j | |  q Wd  S)NzO
                from %s import %s
                foo(%s, %s)
                )rl  r   r   r   )r   rm  r   r   r8   r9   r   r   r   XXX_test_from_import_usage  s    (z'Test_renames.XXX_test_from_import_usageN)rj  zmaxsize)	r4   r'   r5   r   r   r   r   r   rn  r   r   r   r   rg  
  s   	rg  c               @   s   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d S)Test_unicodeunicodec             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzunicode( x)zstr( x)z unicode(x )z str(x )z u'h'z 'h')r   )r   r8   r9   r   r   r   test_whitespace   s    zTest_unicode.test_whitespacec             C   s    d } d } |  j  | |  d  S)Nzunicode(x, y, z)zstr(x, y, z))r   )r   r8   r9   r   r   r   test_unicode_call-  s    zTest_unicode.test_unicode_callc             C   s    d } d } |  j  | |  d  S)Nzunichr(u'h')zchr('h'))r   )r   r8   r9   r   r   r   test_unichr2  s    zTest_unicode.test_unichrc             C   s    d } d } |  j  | |  d  S)Nzu"x"z"x")r   )r   r8   r9   r   r   r   test_unicode_literal_17  s    z#Test_unicode.test_unicode_literal_1c             C   s    d } d } |  j  | |  d  S)Nzur'x'zr'x')r   )r   r8   r9   r   r   r   test_unicode_literal_2<  s    z#Test_unicode.test_unicode_literal_2c             C   s    d } d } |  j  | |  d  S)Nz
UR'''x''' z	R'''x''' )r   )r   r8   r9   r   r   r   test_unicode_literal_3A  s    z#Test_unicode.test_unicode_literal_3c             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nz'\\\u20ac\U0001d121\\u20ac'z'\\\\u20ac\\U0001d121\\u20ac'zr'\\\u20ac\U0001d121\\u20ac')r   )r   r8   r9   r   r   r   test_native_literal_escape_uF  s    z)Test_unicode.test_native_literal_escape_uc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzb'\\\u20ac\U0001d121\\u20ac'zbr'\\\u20ac\U0001d121\\u20ac')r   )r   r8   r9   r   r   r   test_bytes_literal_escape_uO  s    z(Test_unicode.test_bytes_literal_escape_uc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzu'\\\u20ac\U0001d121\\u20ac'z'\\\u20ac\U0001d121\\u20ac'zur'\\\u20ac\U0001d121\\u20ac'zr'\\\u20ac\U0001d121\\u20ac')r   )r   r8   r9   r   r   r   test_unicode_literal_escape_uX  s    z*Test_unicode.test_unicode_literal_escape_uc             C   sR   d } | d } | d } |  j  | |  | d } | d } |  j  | |  d  S)Nz(from __future__ import unicode_literals
z'\\\u20ac\U0001d121\\u20ac'zr'\\\u20ac\U0001d121\\u20ac')r   )r   fr8   r9   r   r   r   $test_native_unicode_literal_escape_ua  s    



z1Test_unicode.test_native_unicode_literal_escape_uN)r4   r'   r5   r   rq  rr  rs  rt  ru  rv  rw  rx  ry  r{  r   r   r   r   ro    s   			ro  c               @   sF   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 S)Test_callablecallablec             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzcallable(    x)z:import collections
isinstance(    x, collections.Callable)zif     callable(x): passzCimport collections
if     isinstance(x, collections.Callable): pass)r   )r   r8   r9   r   r   r   rf   n  s    z&Test_callable.test_prefix_preservationc             C   s    d } d } |  j  | |  d  S)Nzcallable(x)z6import collections
isinstance(x, collections.Callable))r   )r   r8   r9   r   r   r   test_callable_callx  s    z Test_callable.test_callable_callc             C   s   d d d   } d d d   } |  j  | |  d d d   } |  j  | |  d d d   } d d d   } |  j  | |  d d d   } d d d   } |  j  | |  d	 d d   } d
 d d   } |  j  | |  d  S)Nz!
def spam(foo):
    callable(foo)r%   zL
import collections
def spam(foo):
    isinstance(foo, collections.Callable)z4
import collections
def spam(foo):
    callable(foo)z;
from collections import *
def spam(foo):
    callable(foo)zf
from collections import *
import collections
def spam(foo):
    isinstance(foo, collections.Callable)z;
do_stuff()
do_some_other_stuff()
assert callable(do_stuff)zf
import collections
do_stuff()
do_some_other_stuff()
assert isinstance(do_stuff, collections.Callable)z
if isinstance(do_stuff, Callable):
    assert callable(do_stuff)
    do_stuff(do_stuff)
    if not callable(do_stuff):
        exit(1)
    else:
        assert callable(do_stuff)
else:
    assert not callable(do_stuff)aN  
import collections
if isinstance(do_stuff, Callable):
    assert isinstance(do_stuff, collections.Callable)
    do_stuff(do_stuff)
    if not isinstance(do_stuff, collections.Callable):
        exit(1)
    else:
        assert isinstance(do_stuff, collections.Callable)
else:
    assert not isinstance(do_stuff, collections.Callable))r   )r   r8   r9   r   r   r   test_global_import}  s    z Test_callable.test_global_importc             C   sP   d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d  S)Nzcallable(*x)zcallable(x, y)zcallable(x, kw=y)z
callable())r"   )r   r9   r   r   r   test_callable_should_not_change  s    z-Test_callable.test_callable_should_not_changeN)r4   r'   r5   r   rf   r~  r  r  r   r   r   r   r|  k  s
   
>r|  c               @   sF   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 S)Test_filterfilterc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nz#x =   filter(    foo,     'abc'   )z)x =   list(filter(    foo,     'abc'   ))zx =   filter(  None , 'abc'  )z x =   [_f for _f in 'abc' if _f])r   )r   r8   r9   r   r   r   rf     s    z$Test_filter.test_prefix_preservationc             C   st   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzx = filter(None, 'abc')zx = [_f for _f in 'abc' if _f]zx = len(filter(f, 'abc'))zx = 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   )r   r8   r9   r   r   r   test_filter_basic  s    zTest_filter.test_filter_basicc             C   sm  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  |  d } |  j  |  d  S)Nzb.join(filter(f, 'abc'))z#(a + foo(5)).join(filter(f, 'abc'))ziter(filter(f, 'abc'))zlist(filter(f, 'abc'))zlist(filter(f, 'abc'))[0]zset(filter(f, 'abc'))zset(filter(f, 'abc')).pop()ztuple(filter(f, 'abc'))zany(filter(f, 'abc'))zall(filter(f, 'abc'))zsum(filter(f, 'abc'))zsorted(filter(f, 'abc'))z"sorted(filter(f, 'abc'), key=blah)z%sorted(filter(f, 'abc'), key=blah)[0]zenumerate(filter(f, 'abc'))z$enumerate(filter(f, 'abc'), start=1)zfor i in filter(f, 'abc'): passz[x for x in filter(f, 'abc')]z(x for x in filter(f, 'abc')))r"   )r   r9   r   r   r   test_filter_nochange  sL    z Test_filter.test_filter_nochangec             C   sF   d } |  j  |  d } d } |  j | |  d } |  j  |  d  S)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   )r   r9   r8   r   r   r   test_future_builtins  s    z Test_filter.test_future_builtinsN)r4   r'   r5   r   rf   r  r  r  r   r   r   r   r    s
   	(r  c                   sp   e  Z d  Z d Z   f d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
   S)Test_mapr  c                s1   |  j  d | |  t t |   j | |  d  S)Nz!from future_builtins import map; )r"   r   r  r   )r   r8   r9   )r&   r   r   r   !  s    zTest_map.checkc             C   s    d } d } |  j  | |  d  S)Nzx =    map(   f,    'abc'   )z#x =    list(map(   f,    'abc'   )))r   )r   r8   r9   r   r   r   rf   %  s    z!Test_map.test_prefix_preservationc             C   s    d } d } |  j  | |  d  S)Nzx = map(f, 'abc')   #   fooz!x = list(map(f, 'abc'))   #   foo)r   )r   r8   r9   r   r   r   r   *  s    zTest_map.test_trailing_commentc             C   s   d } |  j  | d  d  S)Nzx = map(None, a, b, c)z5cannot convert map(None, ...) with multiple arguments)r$   )r   rR   r   r   r   !test_None_with_multiple_arguments/  s    z*Test_map.test_None_with_multiple_argumentsc             C   s   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d	 } d } |  j  | |  d
 } d } |  j | | d  d  S)Nzx = map(f, 'abc')zx = list(map(f, 'abc'))zx = len(map(f, 'abc', 'def'))z#x = len(list(map(f, 'abc', 'def')))zx = map(None, 'abc')zx = list('abc')z x = map(lambda x: x+1, range(4))zx = [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))
            zYou should use a for loop here)r   r#   )r   r8   r9   r   r   r   test_map_basic4  s$    zTest_map.test_map_basicc             C   sm  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  |  d } |  j  |  d  S)Nzb.join(map(f, 'abc'))z (a + foo(5)).join(map(f, 'abc'))ziter(map(f, 'abc'))zlist(map(f, 'abc'))zlist(map(f, 'abc'))[0]zset(map(f, 'abc'))zset(map(f, 'abc')).pop()ztuple(map(f, 'abc'))zany(map(f, 'abc'))zall(map(f, 'abc'))zsum(map(f, 'abc'))zsorted(map(f, 'abc'))zsorted(map(f, 'abc'), key=blah)z"sorted(map(f, 'abc'), key=blah)[0]zenumerate(map(f, 'abc'))z!enumerate(map(f, 'abc'), start=1)zfor i in map(f, 'abc'): passz[x for x in map(f, 'abc')]z(x for x in map(f, 'abc')))r"   )r   r9   r   r   r   test_map_nochange[  sL    zTest_map.test_map_nochangec             C   sF   d } |  j  |  d } d } |  j | |  d } |  j  |  d  S)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   )r   r9   r8   r   r   r   r    s    zTest_map.test_future_builtins)r4   r'   r5   r   r   rf   r   r  r  r  r  r   r   )r&   r   r    s   '(r  c                   sL   e  Z d  Z d Z   f d d   Z d d   Z d d   Z d d	   Z   S)
Test_zipzipc                s1   |  j  d | |  t t |   j | |  d  S)Nz!from future_builtins import zip; )r"   r   r  r   )r   r8   r9   )r&   r   r   r     s    zTest_zip.checkc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzx = zip(a, b, c)zx = list(zip(a, b, c))zx = len(zip(a, b))zx = len(list(zip(a, b))))r   )r   r8   r9   r   r   r   test_zip_basic  s    zTest_zip.test_zip_basicc             C   sm  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  |  d } |  j  |  d  S)Nzb.join(zip(a, b))z(a + foo(5)).join(zip(a, b))ziter(zip(a, b))zlist(zip(a, b))zlist(zip(a, b))[0]zset(zip(a, b))zset(zip(a, b)).pop()ztuple(zip(a, b))zany(zip(a, b))zall(zip(a, b))zsum(zip(a, b))zsorted(zip(a, b))zsorted(zip(a, b), key=blah)zsorted(zip(a, b), key=blah)[0]zenumerate(zip(a, b))zenumerate(zip(a, b), start=1)zfor i in zip(a, b): passz[x for x in zip(a, b)]z(x for x in zip(a, b)))r"   )r   r9   r   r   r   test_zip_nochange  sL    zTest_zip.test_zip_nochangec             C   sF   d } |  j  |  d } d } |  j | |  d } |  j  |  d  S)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   )r   r9   r8   r   r   r   r    s    zTest_zip.test_future_builtins)r4   r'   r5   r   r   r  r  r  r   r   )r&   r   r    s
   	(r  c               @   s"   e  Z d  Z d Z d d   Z d S)Test_standarderrorZstandarderrorc             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzx =    StandardError()zx =    Exception()zx = StandardError(a, b, c)zx = Exception(a, b, c)zf(2 + StandardError(a, b, c))zf(2 + Exception(a, b, c)))r   )r   r8   r9   r   r   r   r`     s    zTest_standarderror.testN)r4   r'   r5   r   r`   r   r   r   r   r    s   r  c               @   s"   e  Z d  Z d Z d d   Z d S)
Test_typestypesc             C   s   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d	 } d } |  j  | |  d
 } d } |  j  | |  d  S)Nztypes.StringTypebytesztypes.DictTyper   ztypes . IntTypeintztypes.ListTyperl  ztypes.LongTypeztypes.NoneTypez
type(None))r   )r   r8   r9   r   r   r   test_basic_types_convert  s$    z#Test_types.test_basic_types_convertN)r4   r'   r5   r   r  r   r   r   r   r    s   r  c               @   s   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d  d!   Z d" d#   Z d$ d%   Z d& S)'Test_idiomsZidiomsc             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzwhile 1: foo()zwhile True: foo()zwhile   1: foo()zwhile   True: foo()z8
            while 1:
                foo()
            z;
            while True:
                foo()
            )r   )r   r8   r9   r   r   r   
test_while   s    zTest_idioms.test_whilec             C   sP   d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d  S)Nzwhile 11: foo()zwhile 0: foo()zwhile foo(): foo()zwhile []: foo())r"   )r   rR   r   r   r   test_while_unchanged  s    z Test_idioms.test_while_unchangedc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nztype(x) == Tzisinstance(x, T)zif   type(x) == T: passzif   isinstance(x, T): pass)r   )r   r8   r9   r   r   r   test_eq_simple   s    zTest_idioms.test_eq_simplec             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)NzT == type(x)zisinstance(x, T)zif   T == type(x): passzif   isinstance(x, T): pass)r   )r   r8   r9   r   r   r   test_eq_reverse)  s    zTest_idioms.test_eq_reversec             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nztype(x+y) == d.get('T')zisinstance(x+y, d.get('T'))ztype(   x  +  y) == d.get('T')zisinstance(x  +  y, d.get('T')))r   )r   r8   r9   r   r   r   test_eq_expression2  s    zTest_idioms.test_eq_expressionc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nztype(x) is Tzisinstance(x, T)zif   type(x) is T: passzif   isinstance(x, T): pass)r   )r   r8   r9   r   r   r   test_is_simple;  s    zTest_idioms.test_is_simplec             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)NzT is type(x)zisinstance(x, T)zif   T is type(x): passzif   isinstance(x, T): pass)r   )r   r8   r9   r   r   r   test_is_reverseD  s    zTest_idioms.test_is_reversec             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nztype(x+y) is d.get('T')zisinstance(x+y, d.get('T'))ztype(   x  +  y) is d.get('T')zisinstance(x  +  y, d.get('T')))r   )r   r8   r9   r   r   r   test_is_expressionM  s    zTest_idioms.test_is_expressionc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nztype(x) is not Tznot isinstance(x, T)zif   type(x) is not T: passzif   not isinstance(x, T): pass)r   )r   r8   r9   r   r   r   test_is_not_simpleV  s    zTest_idioms.test_is_not_simplec             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)NzT is not type(x)znot isinstance(x, T)zif   T is not type(x): passzif   not isinstance(x, T): pass)r   )r   r8   r9   r   r   r   test_is_not_reverse_  s    zTest_idioms.test_is_not_reversec             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nztype(x+y) is not d.get('T')znot isinstance(x+y, d.get('T'))z"type(   x  +  y) is not d.get('T')z#not isinstance(x  +  y, d.get('T')))r   )r   r8   r9   r   r   r   test_is_not_expressionh  s    z"Test_idioms.test_is_not_expressionc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nztype(x) != Tznot isinstance(x, T)zif   type(x) != T: passzif   not isinstance(x, T): pass)r   )r   r8   r9   r   r   r   test_ne_simpleq  s    zTest_idioms.test_ne_simplec             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)NzT != type(x)znot isinstance(x, T)zif   T != type(x): passzif   not isinstance(x, T): pass)r   )r   r8   r9   r   r   r   test_ne_reversez  s    zTest_idioms.test_ne_reversec             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nztype(x+y) != d.get('T')znot isinstance(x+y, d.get('T'))ztype(   x  +  y) != d.get('T')z#not isinstance(x  +  y, d.get('T')))r   )r   r8   r9   r   r   r   test_ne_expression  s    zTest_idioms.test_ne_expressionc             C   s   d } |  j  |  d  S)Nztype(x).__name__)r"   )r   r9   r   r   r   test_type_unchanged  s    zTest_idioms.test_type_unchangedc             C   s   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  S)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   )r   r8   r9   r   r   r   test_sort_list_call  s0    zTest_idioms.test_sort_list_callc             C   s   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d	 } d
 } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   test_sort_simple_expr  s*    z!Test_idioms.test_sort_simple_exprc             C   s*   d } |  j  |  d } |  j  |  d  S)NzM
            v = list(t)
            w.sort()
            foo(w)
            zN
            v = list(t)
            v.sort(u)
            foo(v)
            )r"   )r   rR   r   r   r   test_sort_unchangedF  s    zTest_idioms.test_sort_unchangedN)r4   r'   r5   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r    s&   												dRr  c               @   s"   e  Z d  Z d Z d d   Z d S)Test_basestring
basestringc             C   s    d } d } |  j  | |  d  S)Nzisinstance(x, basestring)zisinstance(x, str))r   )r   r8   r9   r   r   r   test_basestringX  s    zTest_basestring.test_basestringN)r4   r'   r5   r   r  r   r   r   r   r  U  s   r  c               @   s.   e  Z d  Z d Z d d   Z d d   Z d S)Test_bufferbufferc             C   s    d } d } |  j  | |  d  S)Nzx = buffer(y)zx = memoryview(y))r   )r   r8   r9   r   r   r   test_buffer`  s    zTest_buffer.test_bufferc             C   s    d } d } |  j  | |  d  S)Nzbuffer(y)[4:5]zmemoryview(y)[4:5])r   )r   r8   r9   r   r   r   test_slicinge  s    zTest_buffer.test_slicingN)r4   r'   r5   r   r  r  r   r   r   r   r  ]  s   r  c               @   s.   e  Z d  Z d Z d d   Z d d   Z d S)Test_futurefuturec             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzfrom __future__ import bracesr   z'# comment
from __future__ import bracesz
# comment
z'from __future__ import braces
# commentz

# comment)r   )r   r8   r9   r   r   r   test_futurem  s    zTest_future.test_futurec             C   s   |  j  d  d  S)Nrm   )r3   )r   r   r   r   test_run_orderz  s    zTest_future.test_run_orderN)r4   r'   r5   r   r  r  r   r   r   r   r  j  s   r  c               @   sv   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d S)Test_itertools	itertoolsc             C   sR   xK d D]C } x: d D]2 } | | d | } | | } |  j  | |  q Wq Wd  S)	N
itertools.r   r  r  r  i)r  r   )zmapzfilterzzip)r   )r   r   r   r  rz  r8   r9   r   r   r   checkall  s
    
zTest_itertools.checkallc             C   s    d } d } |  j  | |  d  S)Nzitertools.izip(a, b)z	zip(a, b))r   )r   r8   r9   r   r   r   test_0  s    zTest_itertools.test_0c             C   s    d } d } |  j  | |  d  S)Nz%s(f, a))r  )r   r8   r9   r   r   r   r>     s    zTest_itertools.test_1c             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzitertools.ifilterfalse(a, b)zitertools.filterfalse(a, b)zitertools.izip_longest(a, b)zitertools.zip_longest(a, b))r   )r   r8   r9   r   r   r   test_qualified  s    zTest_itertools.test_qualifiedc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzifilterfalse(a, b)zfilterfalse(a, b)zizip_longest(a, b)zzip_longest(a, b))r   )r   r8   r9   r   r   r   r?     s    zTest_itertools.test_2c             C   s    d } d } |  j  | |  d  S)Nz    %s(f, a))r  )r   r8   r9   r   r   r   r\     s    zTest_itertools.test_space_1c             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nz     itertools.ifilterfalse(a, b)z    itertools.filterfalse(a, b)z     itertools.izip_longest(a, b)z    itertools.zip_longest(a, b))r   )r   r8   r9   r   r   r   r]     s    zTest_itertools.test_space_2c             C   s   |  j  d d d  d  S)Nr  r  r  )r3   )r   r   r   r   r    s    zTest_itertools.test_run_orderN)r4   r'   r5   r   r  r  r>   r  r?   r\   r]   r  r   r   r   r   r  }  s   
			r  c               @   sj   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d S)Test_itertools_importsZitertools_importsc             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nz%from itertools import imap, izip, foozfrom itertools import fooz*from itertools import bar, imap, izip, foozfrom itertools import bar, fooz'from itertools import chain, imap, izipzfrom itertools import chain)r   )r   r8   r9   r   r   r   test_reduced  s    z#Test_itertools_imports.test_reducedc             C   s    d } d } |  j  | |  d  S)Nz%#foo
from itertools import imap, izipz#foo
)r   )r   r8   r9   r   r   r   test_comments  s    z$Test_itertools_imports.test_commentsc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nz from itertools import imap, izipr   zfrom itertools import izip)r   )r   r8   r9   r   r   r   	test_none  s    z Test_itertools_imports.test_nonec             C   s   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } |  j |  d  S)Nz-from itertools import izip, bar as bang, imapz!from itertools import bar as bangz-from itertools import izip as _zip, imap, barzfrom itertools import barz"from itertools import imap as _mapr   z0from itertools import imap as _map, izip as _zip)r   r"   )r   r8   r9   rR   r   r   r   test_import_as  s    z%Test_itertools_imports.test_import_asc             C   s   x d	 D] } d | f } d | f } |  j  | |  d | f } d | f } |  j  | |  d | f } d | f } |  j  | |  q Wd  S)
Nfilterfalsezip_longestzfrom itertools import i%szfrom itertools import %sz$from itertools import imap, i%s, foozfrom itertools import %s, fooz#from itertools import bar, i%s, fooz"from itertools import bar, %s, foo)zfilterfalsezzip_longest)r   )r   r   r8   r9   r   r   r   test_ifilter_and_zip_longest  s    z3Test_itertools_imports.test_ifilter_and_zip_longestc             C   s   d } |  j  |  d  S)Nzfrom itertools import *)r"   )r   rR   r   r   r   test_import_star  s    z'Test_itertools_imports.test_import_starc             C   s   d } |  j  |  d  S)Nzfrom itertools import foo)r"   )r   rR   r   r   r   rc     s    z%Test_itertools_imports.test_unchangedN)r4   r'   r5   r   r  r  r  r  r  r  rc   r   r   r   r   r    s   	r  c                   s  e  Z d  Z d Z   f d d   Z d d   Z   f d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d  d!   Z d" d#   Z d$ d%   Z d& d'   Z   S)(Test_importr  c                s`   t  t    j   g    _ t     _ d   _   f d d   } d d l m } | | _	 d  S)NTc                s&     j  j |     j p% |    j k S)N)files_checkedr  always_existspresent_files)r   )r   r   r   fake_exists  s    z&Test_import.setUp.<locals>.fake_existsr   )
fix_import)
r   r  r   r  setr  r  lib2to3.fixesr  exists)r   r  r  )r&   )r   r   r     s    		zTest_import.setUpc             C   s#   d d l  m } t j j | _ d  S)Nr   )r  )r  r  ospathr  )r   r  r   r   r   tearDown  s    zTest_import.tearDownc                sE   d |  _  t t |   j | |  d |  _  t t |   j |  d  S)NTF)r  r   r  r   r"   )r   r8   r9   )r&   r   r   
check_both  s    		zTest_import.check_bothc                s
  d d   } d |  _  t d g  |  _ d t j j d d d d	 f } | d
  d | d  f } x | D]   g  |  _   |  _ |  j d  t j j	    r t j j	    d   n d   t   f d d   | D  } | j
 d  |  j t |  j  |  qg Wd  S)Nc             S   s   t  j j j |  j d   S)N/)r  r  pathsepr    split)r  r   r   r   p   s    z)Test_import.test_files_checked.<locals>.pFz__init__.pyz.pyz.pycz.soz.slz.pydz/spam/eggs.pyzni.pyz../../shrubbery.pyz
import jamz/jamZjamc             3   s   |  ] }   | Vq d  S)Nr   )r(   ext)r   r   r   	<genexpr>2  s    z1Test_import.test_files_checked.<locals>.<genexpr>)r  r  r  r  r  sepr  r   r"   dirnameaddr   )r   r  Zexpected_extensionsZnames_to_testZexpected_checksr   )r   r   test_files_checked  s    			zTest_import.test_files_checkedc             C   s2   d } d |  _  t d g  |  _ |  j |  d  S)Nz
import barFzbar.py)r  r  r  r"   )r   rR   r   r   r   test_not_in_package7  s    	zTest_import.test_not_in_packagec             C   s5   d } d |  _  t d d g  |  _ |  j |  d  S)Nz1from __future__ import absolute_import
import barFz__init__.pyzbar.py)r  r  r  r"   )r   rR   r   r   r   !test_with_absolute_import_enabled=  s    	z-Test_import.test_with_absolute_import_enabledc             C   s>   d } d } d |  _  t d d g  |  _ |  j | |  d  S)Nz
import barzfrom . import barFz__init__.pyzbar.py)r  r  r  r   )r   r8   r9   r   r   r   test_in_packageC  s
    	zTest_import.test_in_packagec             C   sH   d } d } d |  _  t d d t j j g  |  _ |  j | |  d  S)Nz
import barzfrom . import barFz__init__.pyZbar)r  r  r  r  r  r  r   )r   r8   r9   r   r   r   test_import_from_packageJ  s
    	z$Test_import.test_import_from_packagec             C   s   d } |  j  |  d  S)Nzfrom . import bar)r"   )r   rR   r   r   r   test_already_relative_importQ  s    z(Test_import.test_already_relative_importc             C   s    d } d } |  j  | |  d  S)Nzimport bar # Foozfrom . import bar # Foo)r   )r   r8   r9   r   r   r   test_comments_and_indentU  s    z$Test_import.test_comments_and_indentc             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzfrom foo import bar, bazzfrom .foo import bar, bazzfrom foo import barzfrom .foo import barzfrom foo import (bar, baz)zfrom .foo import (bar, baz))r  )r   r8   r9   r   r   r   	test_fromZ  s    zTest_import.test_fromc             C   s    d } d } |  j  | |  d  S)Nzfrom green.eggs import hamzfrom .green.eggs import ham)r  )r   r8   r9   r   r   r   test_dotted_fromg  s    zTest_import.test_dotted_fromc             C   s    d } d } |  j  | |  d  S)Nz"from green.eggs import ham as spamz#from .green.eggs import ham as spam)r  )r   r8   r9   r   r   r   test_from_asl  s    zTest_import.test_from_asc             C   st   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)	Nz
import foozfrom . import foozimport foo, barzfrom . import foo, barzimport foo, bar, xzfrom . import foo, bar, xzimport x, y, zzfrom . import x, y, z)r  )r   r8   r9   r   r   r   test_importq  s    zTest_import.test_importc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzimport foo as xzfrom . import foo as xzimport a as b, b as c, c as dz$from . import a as b, b as c, c as d)r  )r   r8   r9   r   r   r   r    s    zTest_import.test_import_asc             C   s8   d |  _  t d d g  |  _ d } |  j | d  d  S)NFzfoo.pyz__init__.pyzimport foo, barz#absolute and local imports together)r  r  r  r$   )r   rR   r   r   r   test_local_and_absolute  s    	z#Test_import.test_local_and_absolutec             C   s    d } d } |  j  | |  d  S)Nzimport foo.barzfrom . import foo.bar)r  )r   r8   r9   r   r   r   test_dotted_import  s    zTest_import.test_dotted_importc             C   s    d } d } |  j  | |  d  S)Nzimport foo.bar as bangzfrom . import foo.bar as bang)r  )r   r8   r9   r   r   r   test_dotted_import_as  s    z!Test_import.test_dotted_import_asc             C   s    d } d } |  j  | |  d  S)Nz1
        # prefix
        import foo.bar
        z8
        # prefix
        from . import foo.bar
        )r  )r   r8   r9   r   r   r   test_prefix  s    zTest_import.test_prefix)r4   r'   r5   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   )r&   r   r    s(   	r  c               @   sR   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d S)Test_set_literalZset_literalc             C   s   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  | |  d  S)Nzset([1, 2, 3])z	{1, 2, 3}zset((1, 2, 3))z	set((1,))z{1}zset([1])zset((a, b))z{a, b}zset([a, b])zset((a*234, f(args=23)))z{a*234, f(args=23)}zset([a*23, f(23)])z{a*23, f(23)}zset([a-234**23])z{a-234**23})r   )r   r8   r9   r   r   r   r:     s2    zTest_set_literal.test_basicc             C   st   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)	Nzset([x for x in y])z{x for x in y}zset([x for x in y if x == m])z{x for x in y if x == m}zset([x for x in y for a in b])z{x for x in y for a in b}zset([f(x) - 23 for x in y])z{f(x) - 23 for x in y})r   )r   r8   r9   r   r   r   test_listcomps  s    zTest_set_literal.test_listcompsc             C   s   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d	 } d
 } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzset( [1, 2])z{1, 2}zset([1 ,  2])z{1 ,  2}z
set([ 1 ])z{ 1 }z
set( [1] )z{1}zset([  1,  2  ])z{  1,  2  }zset([x  for x in y ])z{x  for x in y }z<set(
                   [1, 2]
               )
            z{1, 2}
)r   )r   r8   r9   r   r   r   rq    s*    z Test_set_literal.test_whitespacec             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)Nzset((1, 2)) # Hiz{1, 2} # HizZ
            # Foo
            set( # Bar
               (1, 2)
            )
            z2
            # Foo
            {1, 2}
            )r   )r   r8   r9   r   r   r   r     s    zTest_set_literal.test_commentsc             C   sv   d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d } |  j  |  d  S)Nzset()zset(a)zset(a, b, c)zset(x for x in y)zset(x for x in y if z)zset(a*823-23**2 + f(23)))r"   )r   rR   r   r   r   rc     s    zTest_set_literal.test_unchangedN)	r4   r'   r5   r   r:   r  rq  r  rc   r   r   r   r   r    s   # r  c               @   s^   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d S)Test_sys_excZsys_excc             C   s    d } d } |  j  | |  d  S)Nzsys.exc_typezsys.exc_info()[0])r   )r   r8   r9   r   r   r   r  *  s    zTest_sys_exc.test_0c             C   s    d } d } |  j  | |  d  S)Nzsys.exc_valuezsys.exc_info()[1])r   )r   r8   r9   r   r   r   r>   /  s    zTest_sys_exc.test_1c             C   s    d } d } |  j  | |  d  S)Nzsys.exc_tracebackzsys.exc_info()[2])r   )r   r8   r9   r   r   r   r?   4  s    zTest_sys_exc.test_2c             C   s    d } d } |  j  | |  d  S)Nzsys.exc_type # Foozsys.exc_info()[0] # Foo)r   )r   r8   r9   r   r   r   r@   9  s    zTest_sys_exc.test_3c             C   s    d } d } |  j  | |  d  S)Nzsys.  exc_typezsys.  exc_info()[0])r   )r   r8   r9   r   r   r   rA   >  s    zTest_sys_exc.test_4c             C   s    d } d } |  j  | |  d  S)Nzsys  .exc_typezsys  .exc_info()[0])r   )r   r8   r9   r   r   r   rB   C  s    zTest_sys_exc.test_5N)
r4   r'   r5   r   r  r>   r?   r@   rA   rB   r   r   r   r   r  '  s   r  c               @   s   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d S)
Test_parenZparenc             C   s    d } d } |  j  | |  d  S)Nz[i for i in 1, 2 ]z[i for i in (1, 2) ])r   )r   r8   r9   r   r   r   r  L  s    zTest_paren.test_0c             C   s    d } d } |  j  | |  d  S)Nz[i for i in 1, 2, ]z[i for i in (1, 2,) ])r   )r   r8   r9   r   r   r   r>   Q  s    zTest_paren.test_1c             C   s    d } d } |  j  | |  d  S)Nz[i for i  in     1, 2 ]z[i for i  in     (1, 2) ])r   )r   r8   r9   r   r   r   r?   V  s    zTest_paren.test_2c             C   s    d } d } |  j  | |  d  S)Nz[i for i in 1, 2 if i]z[i for i in (1, 2) if i])r   )r   r8   r9   r   r   r   r@   [  s    zTest_paren.test_3c             C   s    d } d } |  j  | |  d  S)Nz[i for i in 1,    2    ]z[i for i in (1,    2)    ])r   )r   r8   r9   r   r   r   rA   `  s    zTest_paren.test_4c             C   s    d } d } |  j  | |  d  S)Nz(i for i in 1, 2)z(i for i in (1, 2)))r   )r   r8   r9   r   r   r   rB   e  s    zTest_paren.test_5c             C   s    d } d } |  j  | |  d  S)Nz(i for i in 1   ,2   if i)z(i for i in (1   ,2)   if i))r   )r   r8   r9   r   r   r   rC   j  s    zTest_paren.test_6c             C   s   d } |  j  |  d  S)Nz[i for i in (1, 2)])r"   )r   rR   r   r   r   test_unchanged_0o  s    zTest_paren.test_unchanged_0c             C   s   d } |  j  |  d  S)Nz[i for i in foo()])r"   )r   rR   r   r   r   rS   s  s    zTest_paren.test_unchanged_1c             C   s   d } |  j  |  d  S)Nz[i for i in (1, 2) if nothing])r"   )r   rR   r   r   r   rT   w  s    zTest_paren.test_unchanged_2c             C   s   d } |  j  |  d  S)Nz(i for i in (1, 2)))r"   )r   rR   r   r   r   rU   {  s    zTest_paren.test_unchanged_3c             C   s   d } |  j  |  d  S)Nz[i for i in m])r"   )r   rR   r   r   r   rV     s    zTest_paren.test_unchanged_4N)r4   r'   r5   r   r  r>   r?   r@   rA   rB   rC   r  rS   rT   rU   rV   r   r   r   r   r  I  s   r  c               @   s:   e  Z d  Z d Z d d   Z d d   Z d d   Z d S)	Test_metaclass	metaclassc             C   s   |  j  d  |  j  d  |  j  d  |  j  d  |  j  d  |  j  d  |  j  d  d } |  j  |  d	 } |  j  |  d  S)
Nzclass X(): passzclass X(object): passzclass X(object1, object2): passz(class X(object1, object2, object3): passzclass 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"   )r   rR   r   r   r   rc     s    zTest_metaclass.test_unchangedc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   r    s    zTest_metaclass.test_commentsc             C   s8  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  | |  d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   	test_meta  sB    zTest_metaclass.test_metaN)r4   r'   r5   r   rc   r  r  r   r   r   r   r    s   r  c               @   sR   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d S)Test_getcwduZgetcwduc             C   st   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)	Nz
os.getcwduz	os.getcwdzos.getcwdu()zos.getcwd()zmeth = os.getcwduzmeth = os.getcwdzos.getcwdu(args)zos.getcwd(args))r   )r   r8   r9   r   r   r   r:   ,  s    zTest_getcwdu.test_basicc             C   s    d } d } |  j  | |  d  S)Nzos.getcwdu() # Foozos.getcwd() # Foo)r   )r   r8   r9   r   r   r   ra   =  s    zTest_getcwdu.test_commentc             C   s=   d } |  j  |  d } |  j  |  d } |  j  |  d  S)Nzos.getcwd()z	getcwdu()zos.getcwdb())r"   )r   rR   r   r   r   rc   B  s    zTest_getcwdu.test_unchangedc             C   s    d } d } |  j  | |  d  S)Nz<
            if 1:
                os.getcwdu()
            z;
            if 1:
                os.getcwd()
            )r   )r   r8   r9   r   r   r   test_indentationL  s    zTest_getcwdu.test_indentationc             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzos .getcwdu()zos .getcwd()zos.  getcwduzos.  getcwdzos.getcwdu (  )zos.getcwd (  ))r   )r   r8   r9   r   r   r   test_multilationW  s    zTest_getcwdu.test_multilationN)	r4   r'   r5   r   r:   ra   rc   r  r  r   r   r   r   r  (  s   
r  c               @   s   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d S)Test_operatoroperatorc             C   s    d } d } |  j  | |  d  S)Nzoperator.isCallable(x)zhasattr(x, '__call__'))r   )r   r8   r9   r   r   r   test_operator_isCallablei  s    z&Test_operator.test_operator_isCallablec             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzoperator.sequenceIncludes(x, y)zoperator.contains(x, y)z operator .sequenceIncludes(x, y)zoperator .contains(x, y)z!operator.  sequenceIncludes(x, y)zoperator.  contains(x, y))r   )r   r8   r9   r   r   r   test_operator_sequenceIncludesn  s    z,Test_operator.test_operator_sequenceIncludesc             C   s    d } d } |  j  | |  d  S)Nzoperator.isSequenceType(x)z6import collections
isinstance(x, collections.Sequence))r   )r   r8   r9   r   r   r   test_operator_isSequenceType{  s    z*Test_operator.test_operator_isSequenceTypec             C   s    d } d } |  j  | |  d  S)Nzoperator.isMappingType(x)z5import collections
isinstance(x, collections.Mapping))r   )r   r8   r9   r   r   r   test_operator_isMappingType  s    z)Test_operator.test_operator_isMappingTypec             C   s    d } d } |  j  | |  d  S)Nzoperator.isNumberType(x)z,import numbers
isinstance(x, numbers.Number))r   )r   r8   r9   r   r   r   test_operator_isNumberType  s    z(Test_operator.test_operator_isNumberTypec             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzoperator.repeat(x, n)zoperator.mul(x, n)zoperator .repeat(x, n)zoperator .mul(x, n)zoperator.  repeat(x, n)zoperator.  mul(x, n))r   )r   r8   r9   r   r   r   test_operator_repeat  s    z"Test_operator.test_operator_repeatc             C   sX   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzoperator.irepeat(x, n)zoperator.imul(x, n)zoperator .irepeat(x, n)zoperator .imul(x, n)zoperator.  irepeat(x, n)zoperator.  imul(x, n))r   )r   r8   r9   r   r   r   test_operator_irepeat  s    z#Test_operator.test_operator_irepeatc             C   s    d } d } |  j  | |  d  S)NzisCallable(x)z-You should use 'hasattr(x, '__call__')' here.)r$   )r   rR   tr   r   r   test_bare_isCallable  s    z"Test_operator.test_bare_isCallablec             C   s    d } d } |  j  | |  d  S)NzsequenceIncludes(x, y)z.You should use 'operator.contains(x, y)' here.)r$   )r   rR   r  r   r   r   test_bare_sequenceIncludes  s    z(Test_operator.test_bare_sequenceIncludesc             C   s    d } d } |  j  | |  d  S)NzisSequenceType(z)z:You should use 'isinstance(z, collections.Sequence)' here.)r$   )r   rR   r  r   r   r   !test_bare_operator_isSequenceType  s    z/Test_operator.test_bare_operator_isSequenceTypec             C   s    d } d } |  j  | |  d  S)NzisMappingType(x)z9You should use 'isinstance(x, collections.Mapping)' here.)r$   )r   rR   r  r   r   r    test_bare_operator_isMappingType  s    z.Test_operator.test_bare_operator_isMappingTypec             C   s    d } d } |  j  | |  d  S)NzisNumberType(y)z4You should use 'isinstance(y, numbers.Number)' here.)r$   )r   rR   r  r   r   r   test_bare_operator_isNumberType  s    z-Test_operator.test_bare_operator_isNumberTypec             C   s    d } d } |  j  | |  d  S)Nzrepeat(x, n)z)You should use 'operator.mul(x, n)' here.)r$   )r   rR   r  r   r   r   test_bare_operator_repeat  s    z'Test_operator.test_bare_operator_repeatc             C   s    d } d } |  j  | |  d  S)Nzirepeat(y, 187)z,You should use 'operator.imul(y, 187)' here.)r$   )r   rR   r  r   r   r   test_bare_operator_irepeat  s    z(Test_operator.test_bare_operator_irepeatN)r4   r'   r5   r   r  r  r  r  r  r  r  r  r  r  r  r   r  r  r   r   r   r   r  e  s   r  c               @   sj   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d S)Test_exitfuncZexitfuncc             C   s    d } d } |  j  | |  d  S)NzI
            import sys
            sys.exitfunc = my_atexit
            ze
            import sys
            import atexit
            atexit.register(my_atexit)
            )r   )r   r8   r9   r   r   r   r     s    zTest_exitfunc.test_simplec             C   s    d } d } |  j  | |  d  S)NzO
            import sys, crumbs
            sys.exitfunc = my_func
            zY
            import sys, crumbs, atexit
            atexit.register(my_func)
            )r   )r   r8   r9   r   r   r   test_names_import  s    zTest_exitfunc.test_names_importc             C   s    d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   test_complex_expression  s    z%Test_exitfunc.test_complex_expressionc             C   s<   d } d } |  j  | |  d } d } |  j  | |  d  S)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   )r   r8   r9   r   r   r   r    s    zTest_exitfunc.test_commentsc             C   s    d } d } |  j  | |  d  S)Nz]
            import sys
            def f():
                sys.exitfunc = func
            zz
            import sys
            import atexit
            def f():
                atexit.register(func)
             )r   )r   r8   r9   r   r   r   test_in_a_function  s    z Test_exitfunc.test_in_a_functionc             C   s)   d } d } d } |  j  | | |  d  S)Nzsys.exitfunc = fzatexit.register(f)zKCan't find sys import; Please add an atexit import at the top of your file.)r#   )r   r8   r9   msgr   r   r   test_no_sys_import  s    z Test_exitfunc.test_no_sys_importc             C   s   d } |  j  |  d  S)Nzf(sys.exitfunc))r"   )r   rR   r   r   r   rc     s    zTest_exitfunc.test_unchangedN)r4   r'   r5   r   r   r  r  r  r  r  rc   r   r   r   r   r    s   r  c               @   s:   e  Z d  Z d Z d d   Z d d   Z d d   Z d S)	Test_assertsZassertsc             C   sU   d d d d d d d d d d d d g } x$ | D] \ } } |  j  | |  q1 Wd  S) 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  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r  )r  r  )r   )r   Ztestsr8   r9   r   r   r   test_deprecated_names$  s    	z"Test_asserts.test_deprecated_namesc             C   s   d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d	 } d
 } |  j  | |  d } d } |  j  | |  d } d } |  j  | |  d  S)Nzeq = self.assertEqualszeq = 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") # foozself.assertEquals (2, 3)zself.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   )r   r8   r9   r   r   r   test_variants6  s*    zTest_asserts.test_variantsc             C   s   |  j  d  |  j  d  d  S)Nzself.assertEqualsOnSaturdayz!self.assertEqualsOnSaturday(3, 5))r"   )r   r   r   r   rc   M  s    zTest_asserts.test_unchangedN)r4   r'   r5   r   r  r  rc   r   r   r   r   r	     s   r	  )G__doc__r  Zunittestr  r   r  r   r
   r   r   r   r   Zlib2to3.testsr   ZTestCaser	   r6   r=   rI   r^   rd   rg   rl   ry   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r)  r,  rU  rW  rg  ro  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r   r   r   r   <module>   s   "9:;1#j3& }.&H/+bn/  4B.N]VpC Y=J":=cX