o
    JAf                    @   s  	 d dl Z d dlmZ d dlmZ d dlmZmZ d dlm	Z	 G dd de	j
ZG dd	 d	eZG d
d deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZG d&d' d'eZG d(d) d)eZG d*d+ d+eZG d,d- d-eZG d.d/ d/eZG d0d1 d1eZ G d2d3 d3Z!G d4d5 d5ee!Z"G d6d7 d7ee!Z#G d8d9 d9ee!Z$G d:d; d;eZ%G d<d= d=eZ&G d>d? d?eZ'G d@dA dAeZ(G dBdC dCeZ)G dDdE dEeZ*G dFdG dGeZ+G dHdI dIeZ,G dJdK dKeZ-G dLdM dMeZ.G dNdO dOeZ/G dPdQ dQeZ0G dRdS dSeZ1G dTdU dUeZ2G dVdW dWeZ3G dXdY dYeZ4G dZd[ d[eZ5G d\d] d]eZ6G d^d_ d_eZ7G d`da daeZ8G dbdc dceZ9G ddde deeZ:G dfdg dgeZ;G dhdi dieZ<G djdk dkeZ=G dldm dmeZ>G dndo doeZ?G dpdq dqeZ@G drds dseZAdS )t    N)chain)
itemgetter)pygram
fixer_util)supportc                   @   sL   e Zd Z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   sP   |d u r| j g}t|||| _g | _d| _t| jj| jjD ]}| j|_	qd S )Nz<string>)
fixerr   get_refactorerrefactor	fixer_logfilenamer   Z	pre_orderZ
post_orderlog)selfZfix_listZ	fixer_pkgoptionsr	    r   0/usr/lib/python3.10/lib2to3/tests/test_fixers.pysetUp   s   
zFixerTestCase.setUpc                 C   s8   t |}t |}| 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   s2   |  ||}| |j |s| | jg  d S d S r   )r   
assertTruewas_changedr   r   )r   r   r   ignore_warningsr   r   r   r   check#   s
   zFixerTestCase.checkc                 C   s8   |  ||}| |d| j |s| |j d S 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 )NTr"   r#   )r   r   r!   r   r   r   warns_unchanged/   s   zFixerTestCase.warns_unchangedc                 C   s&   |  || |s| | jg  d S d S r   )r   r   r   )r   r   r   r   r   r   r"   2   s   zFixerTestCase.unchangedc                 G   s   | j g}|| td|}| \}}d| j  }|r'|d jj|r'd S |r6|d jj|r6|s6d S | dd	dd || D |f  d S )Nr   Zfix_z5Fixer run order (%s) is incorrect; %s should be last., c                 S   s   g | ]}|j jqS r   )	__class__
__module__).0xr   r   r   
<listcomp>D       z3FixerTestCase.assert_runs_after.<locals>.<listcomp>)
r	   extendr   r
   Z
get_fixersr)   r*   endswithZfailr    )r   namesfixesrpreZpostnr   r   r   assert_runs_after7   s   


zFixerTestCase.assert_runs_after)Nr   N)F)
__name__r*   __qualname__r   r   r   r#   r&   r"   r6   r   r   r   r   r      s    



r   c                   @   (   e Zd ZdZdd Zdd Zdd ZdS )	Test_nenec                 C      d}d}|  || d S )Nzif x <> y:
            passzif x != y:
            passr   r   bar   r   r   
test_basicI      zTest_ne.test_basicc                 C   r<   )Nzif x<>y:
            passzif x!=y:
            passr=   r>   r   r   r   test_no_spacesQ   rB   zTest_ne.test_no_spacesc                 C   r<   )Nzif x<>y<>z:
            passzif x!=y!=z:
            passr=   r>   r   r   r   test_chainedY   rB   zTest_ne.test_chainedN)r7   r*   r8   r	   rA   rC   rD   r   r   r   r   r:   F   s
    r:   c                   @   sh   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   r<   )Nz$x = d.has_key("x") or d.has_key("y")zx = "x" in d or "y" in dr=   r>   r   r   r   test_1d      zTest_has_key.test_1c                 C   r<   )Nzx = a.b.c.d.has_key("x") ** 3zx = ("x" in a.b.c.d) ** 3r=   r>   r   r   r   test_2i   rG   zTest_has_key.test_2c                 C   r<   )Nz!x = a.b.has_key(1 + 2).__repr__()zx = (1 + 2 in a.b).__repr__()r=   r>   r   r   r   test_3n   rG   zTest_has_key.test_3c                 C   r<   )Nz,x = a.b.has_key(1 + 2).__repr__() ** -3 ** 4z(x = (1 + 2 in a.b).__repr__() ** -3 ** 4r=   r>   r   r   r   test_4s   rG   zTest_has_key.test_4c                 C   r<   )Nzx = a.has_key(f or g)zx = (f or g) in ar=   r>   r   r   r   test_5x   rG   zTest_has_key.test_5c                 C   r<   )Nzx = a + b.has_key(c)zx = a + (c in b)r=   r>   r   r   r   test_6}   rG   zTest_has_key.test_6c                 C   r<   )Nzx = a.has_key(lambda: 12)zx = (lambda: 12) in ar=   r>   r   r   r   test_7   rG   zTest_has_key.test_7c                 C   r<   )Nzx = a.has_key(a for a in b)zx = (a for a in b) in ar=   r>   r   r   r   test_8   rG   zTest_has_key.test_8c                 C   r<   )Nzif not a.has_key(b): passzif b not in a: passr=   r>   r   r   r   test_9   rG   zTest_has_key.test_9c                 C   r<   )Nz$if not a.has_key(b).__repr__(): passz if not (b in a).__repr__(): passr=   r>   r   r   r   test_10   rG   zTest_has_key.test_10c                 C   r<   )Nzif not a.has_key(b) ** 2: passzif not (b in a) ** 2: passr=   r>   r   r   r   test_11   rG   zTest_has_key.test_11N)r7   r*   r8   r	   rF   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   r   r   r   r   rE   a   s    rE   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d0d1 Zd2d3 Zd4d5 Zd6S )7
Test_applyZapplyc                 C   r<   )Nzx = apply(f, g + h)zx = f(*g + h)r=   r>   r   r   r   rF      rG   zTest_apply.test_1c                 C   r<   )Nzy = apply(f, g, h)zy = f(*g, **h)r=   r>   r   r   r   rH      rG   zTest_apply.test_2c                 C   r<   )Nz z = apply(fs[0], g or h, h or g)zz = fs[0](*g or h, **h or g)r=   r>   r   r   r   rI      rG   zTest_apply.test_3c                 C   r<   )Nzapply(f, (x, y) + t)zf(*(x, y) + t)r=   r>   r   r   r   rJ      rG   zTest_apply.test_4c                 C   r<   )Nzapply(f, args,)f(*args)r=   r>   r   r   r   rK      rG   zTest_apply.test_5c                 C   r<   )Nzapply(f, args, kwds,)f(*args, **kwds)r=   r>   r   r   r   rL      rG   zTest_apply.test_6c                 C   r<   )Nzx = apply(f+g, args)zx = (f+g)(*args)r=   r>   r   r   r   test_complex_1   rG   zTest_apply.test_complex_1c                 C   r<   )Nzx = apply(f*g, args)zx = (f*g)(*args)r=   r>   r   r   r   test_complex_2   rG   zTest_apply.test_complex_2c                 C   r<   )Nzx = apply(f**g, args)zx = (f**g)(*args)r=   r>   r   r   r   test_complex_3   rG   zTest_apply.test_complex_3c                 C   r<   )Nzx = apply(f.g, args)zx = f.g(*args)r=   r>   r   r   r   test_dotted_name   rG   zTest_apply.test_dotted_namec                 C   r<   )Nzx = apply(f[x], args)zx = f[x](*args)r=   r>   r   r   r   test_subscript   rG   zTest_apply.test_subscriptc                 C   r<   )Nzx = apply(f(), args)zx = f()(*args)r=   r>   r   r   r   	test_call   rG   zTest_apply.test_callc                 C   r<   )Nz"x = apply(a.b.c.d.e.f, args, kwds)zx = a.b.c.d.e.f(*args, **kwds)r=   r>   r   r   r   test_extreme   rG   zTest_apply.test_extremec                 C   r<   )Nz1apply(   # foo
          f, # bar
          args)rS   r=   r>   r   r   r   test_weird_comments   s   zTest_apply.test_weird_commentsc                 C      d}|  | d S )Nzapply()r$   r   sr   r   r   test_unchanged_1      zTest_apply.test_unchanged_1c                 C   r]   )Nzapply(f)r$   r^   r   r   r   test_unchanged_2   ra   zTest_apply.test_unchanged_2c                 C   r]   )Nz	apply(f,)r$   r^   r   r   r   test_unchanged_3   ra   zTest_apply.test_unchanged_3c                 C   r]   )Nzapply(f, args, kwds, extras)r$   r^   r   r   r   test_unchanged_4   ra   zTest_apply.test_unchanged_4c                 C   r]   )Nzapply(f, *args, **kwds)r$   r^   r   r   r   test_unchanged_5   ra   zTest_apply.test_unchanged_5c                 C   r]   )Nzapply(f, *args)r$   r^   r   r   r   test_unchanged_6  ra   zTest_apply.test_unchanged_6c                 C   r]   )Nzapply(f, **kwds)r$   r^   r   r   r   test_unchanged_6b  ra   zTest_apply.test_unchanged_6bc                 C   r]   )Nz#apply(func=f, args=args, kwds=kwds)r$   r^   r   r   r   test_unchanged_7
  ra   zTest_apply.test_unchanged_7c                 C   r]   )Nzapply(f, args=args, kwds=kwds)r$   r^   r   r   r   test_unchanged_8  ra   zTest_apply.test_unchanged_8c                 C   r]   )Nzapply(f, args, kwds=kwds)r$   r^   r   r   r   test_unchanged_9  ra   zTest_apply.test_unchanged_9c                 C   r<   )Nzapply(  f,  args,   kwds)rT   r=   r   r@   r?   r   r   r   test_space_1  rG   zTest_apply.test_space_1c                 C   r<   )Nzapply(  f  ,args,kwds   )rT   r=   rk   r   r   r   test_space_2  rG   zTest_apply.test_space_2N)r7   r*   r8   r	   rF   rH   rI   rJ   rK   rL   rU   rV   rW   rX   rY   rZ   r[   r\   r`   rb   rc   rd   re   rf   rg   rh   ri   rj   rl   rm   r   r   r   r   rR      s8    	rR   c                   @   0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )Test_reloadreloadc                 C   r<   )Nz	reload(a)z$import importlib
importlib.reload(a)r=   r>   r   r   r   test#  rG   zTest_reload.testc                 C   ,   d}d}|  || d}d}|  || d S )Nzreload( a ) # commentz0import importlib
importlib.reload( a ) # commentzreload( a )  # commentz1import importlib
importlib.reload( a )  # commentr=   r>   r   r   r   test_comment(  s   zTest_reload.test_commentc                 C   @   d}d}|  || d}d}|  || d}d}|  || d S )Nzreload( a )z&import importlib
importlib.reload( a )z
reload( a)z%import importlib
importlib.reload( a)z
reload(a )z%import importlib
importlib.reload(a )r=   r>   r   r   r   
test_space2     zTest_reload.test_spacec                 C   s   d}|  | d}|  | d}|  | d}|  | d}|  | d}|  | d}|  | d}|  | d	}|  | 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^   r   r   r   test_unchanged?  s$   







zTest_reload.test_unchangedN)r7   r*   r8   r	   rq   rs   ru   rw   r   r   r   r   ro      s    
ro   c                   @   r9   )	Test_interninternc                 C   rt   )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>   r   r   r   test_prefix_preservation^  s   z$Test_intern.test_prefix_preservationc                 C   rt   )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>   r   r   r   rq   m  rv   zTest_intern.testc                 C   J   d}|  | d}|  | d}|  | d}|  | d}|  | d S )Nzintern(a=1)zintern(f, g)z
intern(*h)zintern(**i)zintern()r$   r^   r   r   r   rw   |     



zTest_intern.test_unchangedN)r7   r*   r8   r	   rz   rq   rw   r   r   r   r   rx   [  s
    rx   c                   @   rn   )Test_reducereducec                 C   r<   )Nzreduce(a, b, c)z,from functools import reduce
reduce(a, b, c)r=   r>   r   r   r   test_simple_call  rG   zTest_reduce.test_simple_callc                 C   r<   )Nzdef x(arg): reduce(sum, [])z8from functools import reduce
def x(arg): reduce(sum, [])r=   r>   r   r   r   test_bug_7253     zTest_reduce.test_bug_7253c                 C   r<   )Nzreduce(lambda x, y: x + y, seq)z<from functools import reduce
reduce(lambda x, y: x + y, seq)r=   r>   r   r   r   test_call_with_lambda  rG   z!Test_reduce.test_call_with_lambdac                 C   r{   )Nz	reduce(a)zreduce(a, b=42)zreduce(a, b, c, d)zreduce(**c)zreduce()r$   r^   r   r   r   rw     r|   zTest_reduce.test_unchangedN)r7   r*   r8   r	   r   r   r   rw   r   r   r   r   r}     s    r}   c                   @      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   r<   )Nzprint 1,   1+1,   1+1+1zprint(1,   1+1,   1+1+1)r=   r>   r   r   r   rz     rG   z#Test_print.test_prefix_preservationc                 C       d}|  | d}|  | d S )Nprint()	print('')r$   r^   r   r   r   test_idempotency  s   
zTest_print.test_idempotencyc                 C   s:   t j| jj_d}| | d}| | d}| | d S )Nprint(1, 1+1, 1+1+1)r   r   )r   Z!python_grammar_no_print_statementr   ZdriverZgrammarr"   r^   r   r   r   "test_idempotency_print_as_function  s   

z-Test_print.test_idempotency_print_as_functionc                 C   r<   )Nzprint 1, 1+1, 1+1+1r   r=   r>   r   r   r   rF     rG   zTest_print.test_1c                 C   r<   )Nz
print 1, 2zprint(1, 2)r=   r>   r   r   r   rH     rG   zTest_print.test_2c                 C   r<   )Nr   r   r=   r>   r   r   r   rI     rG   zTest_print.test_3c                 C   r<   )Nzprint whatever; printzprint(whatever); print()r=   r>   r   r   r   rJ     r   zTest_print.test_4c                 C   r<   )Nzprint; print whatever;zprint(); print(whatever);r=   r>   r   r   r   rK     rG   zTest_print.test_5c                 C   r<   )Nzprint (a, b, c)zprint((a, b, c))r=   r>   r   r   r   
test_tuple  rG   zTest_print.test_tuplec                 C   r<   )Nzprint 1, 2, 3,zprint(1, 2, 3, end=' ')r=   r>   r   r   r   test_trailing_comma_1  rG   z Test_print.test_trailing_comma_1c                 C   r<   )Nzprint 1, 2,zprint(1, 2, end=' ')r=   r>   r   r   r   test_trailing_comma_2  rG   z Test_print.test_trailing_comma_2c                 C   r<   )Nzprint 1,zprint(1, end=' ')r=   r>   r   r   r   test_trailing_comma_3  rG   z Test_print.test_trailing_comma_3c                 C   r<   )Nzprint >>sys.stderr, 1, 2, 3zprint(1, 2, 3, file=sys.stderr)r=   r>   r   r   r   !test_vargs_without_trailing_comma  rG   z,Test_print.test_vargs_without_trailing_commac                 C   r<   )Nzprint >>sys.stderr, 1, 2,z%print(1, 2, end=' ', file=sys.stderr)r=   r>   r   r   r   test_with_trailing_comma   rG   z#Test_print.test_with_trailing_commac                 C   r<   )Nzprint >>sys.stderr, 1+1zprint(1+1, file=sys.stderr)r=   r>   r   r   r   test_no_trailing_comma  rG   z!Test_print.test_no_trailing_commac                 C   r<   )Nzprint >>  sys.stderrzprint(file=sys.stderr)r=   r>   r   r   r   test_spaces_before_file
  rG   z"Test_print.test_spaces_before_filec                 C   s&   d}|  | d}d}| || d S )Nz<from __future__ import print_function
print('Hai!', end=' ')zprint 'Hello, world!'zprint('Hello, world!')r"   r   )r   r_   r?   r@   r   r   r   test_with_future_print_function  s
   
z*Test_print.test_with_future_print_functionN)r7   r*   r8   r	   rz   r   r   rF   rH   rI   rJ   rK   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s&    r   c                   @   `   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   r<   )Nz  exec code in ns1,   ns2z  exec(code, ns1,   ns2)r=   r>   r   r   r   rz     rG   z"Test_exec.test_prefix_preservationc                 C   r<   )Nz	exec code
exec(code)r=   r>   r   r   r   rA   !  rG   zTest_exec.test_basicc                 C   r<   )Nzexec code in nsexec(code, ns)r=   r>   r   r   r   test_with_globals&  rG   zTest_exec.test_with_globalsc                 C   r<   )Nzexec code in ns1, ns2exec(code, ns1, ns2)r=   r>   r   r   r   test_with_globals_locals+  rG   z"Test_exec.test_with_globals_localsc                 C   r<   )Nzexec (a.b()) in nszexec((a.b()), ns)r=   r>   r   r   r   rU   0  rG   zTest_exec.test_complex_1c                 C   r<   )Nzexec a.b() + c in nszexec(a.b() + c, ns)r=   r>   r   r   r   rV   5  rG   zTest_exec.test_complex_2c                 C   r]   )Nr   r$   r^   r   r   r   r`   <  ra   zTest_exec.test_unchanged_1c                 C   r]   )Nzexec (code)r$   r^   r   r   r   rb   @  ra   zTest_exec.test_unchanged_2c                 C   r]   )Nr   r$   r^   r   r   r   rc   D  ra   zTest_exec.test_unchanged_3c                 C   r]   )Nr   r$   r^   r   r   r   rd   H  ra   zTest_exec.test_unchanged_4N)r7   r*   r8   r	   rz   rA   r   r   rU   rV   r`   rb   rc   rd   r   r   r   r   r     s    r   c                   @   H   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   r<   )Nzx =   `1 + 2`zx =   repr(1 + 2)r=   r>   r   r   r   rz   O  rG   z"Test_repr.test_prefix_preservationc                 C   r<   )Nzx = `1 + 2`zx = repr(1 + 2)r=   r>   r   r   r   test_simple_1T  rG   zTest_repr.test_simple_1c                 C   r<   )Nzy = `x`zy = repr(x)r=   r>   r   r   r   test_simple_2Y  rG   zTest_repr.test_simple_2c                 C   r<   )Nzz = `y`.__repr__()zz = repr(y).__repr__()r=   r>   r   r   r   test_complex^  rG   zTest_repr.test_complexc                 C   r<   )Nzx = `1, 2, 3`zx = repr((1, 2, 3))r=   r>   r   r   r   r   c  rG   zTest_repr.test_tuplec                 C   r<   )Nzx = `1 + `2``zx = repr(1 + repr(2))r=   r>   r   r   r   test_nestedh  rG   zTest_repr.test_nestedc                 C   r<   )Nzx = `1, 2 + `3, 4``zx = repr((1, 2 + repr((3, 4))))r=   r>   r   r   r   test_nested_tuplesm  rG   zTest_repr.test_nested_tuplesN)r7   r*   r8   r	   rz   r   r   r   r   r   r   r   r   r   r   r   L  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   r<   )Nzq
            try:
                pass
            except (RuntimeError, ImportError),    e:
                passzs
            try:
                pass
            except (RuntimeError, ImportError) as    e:
                passr=   r>   r   r   r   rz   u     z$Test_except.test_prefix_preservationc                 C   r<   )NzV
            try:
                pass
            except Foo, e:
                passX
            try:
                pass
            except Foo as e:
                passr=   r>   r   r   r   test_simple  r   zTest_except.test_simplec                 C   r<   )NzU
            try:
                pass
            except Foo,e:
                passr   r=   r>   r   r   r   "test_simple_no_space_before_target  r   z.Test_except.test_simple_no_space_before_targetc                 C   r<   )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:
                    passr=   r>   r   r   r   test_tuple_unpack  s   		zTest_except.test_tuple_unpackc                 C   r<   )Nzn
            try:
                pass
            except (RuntimeError, ImportError), e:
                passzp
            try:
                pass
            except (RuntimeError, ImportError) as e:
                passr=   r>   r   r   r   test_multi_class  s   zTest_except.test_multi_classc                 C   r<   )Nza
            try:
                pass
            except Exception, [a, b]:
                passz
            try:
                pass
            except Exception as xxx_todo_changeme:
                [a, b] = xxx_todo_changeme.args
                passr=   r>   r   r   r   test_list_unpack     zTest_except.test_list_unpackc                 C   r<   )Nz_
            try:
                pass
            except Exception, d[5]:
                passz
            try:
                pass
            except Exception as xxx_todo_changeme:
                d[5] = xxx_todo_changeme
                passr=   r>   r   r   r   test_weird_target_1  r   zTest_except.test_weird_target_1c                 C   r<   )Nz`
            try:
                pass
            except Exception, a.foo:
                passz
            try:
                pass
            except Exception as xxx_todo_changeme:
                a.foo = xxx_todo_changeme
                passr=   r>   r   r   r   test_weird_target_2  r   zTest_except.test_weird_target_2c                 C   r<   )Nzb
            try:
                pass
            except Exception, a().foo:
                passz
            try:
                pass
            except Exception as xxx_todo_changeme:
                a().foo = xxx_todo_changeme
                passr=   r>   r   r   r   test_weird_target_3  r   zTest_except.test_weird_target_3c                 C   r<   )Nz
            try:
                pass
            except Exception, a:
                pass
            except:
                passz
            try:
                pass
            except Exception as a:
                pass
            except:
                passr=   r>   r   r   r   test_bare_except  s   zTest_except.test_bare_exceptc                 C   r<   )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:
                passr=   r>   r   r   r   !test_bare_except_and_else_finally  s   z-Test_except.test_bare_except_and_else_finallyc                 C   r<   )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:
                passr=   r>   r   r   r   +test_multi_fixed_excepts_before_bare_except'  s   
	z7Test_except.test_multi_fixed_excepts_before_bare_exceptc                 C   T   d}d}|  || d}d}|  || d}d}|  || d}d}|  || 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>   r   r   r   test_one_line_suites=  s   z Test_except.test_one_line_suitesc                 C   r]   )NzO
            try:
                pass
            except:
                passr$   r^   r   r   r   r`   m     zTest_except.test_unchanged_1c                 C   r]   )NzY
            try:
                pass
            except Exception:
                passr$   r^   r   r   r   rb   u  r   zTest_except.test_unchanged_2c                 C   r]   )Nzg
            try:
                pass
            except (Exception, SystemExit):
                passr$   r^   r   r   r   rc   }  r   zTest_except.test_unchanged_3N)r7   r*   r8   r	   rz   r   r   r   r   r   r   r   r   r   r   r   r   r`   rb   rc   r   r   r   r   r   r  s$    0r   c                   @   r   )%
Test_raiseraisec                 C   r<   )Nzraise Exception, 5raise Exception(5)r=   r>   r   r   r   rA     rG   zTest_raise.test_basicc                 C   rr   )Nzraise Exception,5r   zraise   Exception,    5zraise   Exception(5)r=   r>   r   r   r   rz        z#Test_raise.test_prefix_preservationc                 C   rt   )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) # foor=   r>   r   r   r   test_with_comments  s   zTest_raise.test_with_commentsc                 C   r<   )Nzraise Exception(5), None, tbz%raise Exception(5).with_traceback(tb)r=   r>   r   r   r   test_None_value  rG   zTest_raise.test_None_valuec                 C   r<   )Nzraise Exception, (5, 6, 7)zraise Exception(5, 6, 7)r=   r>   r   r   r   test_tuple_value  rG   zTest_raise.test_tuple_valuec                 C   r<   )Nzraise E, (5, 6) % (a, b)zraise E((5, 6) % (a, b))r=   r>   r   r   r   test_tuple_detection  rG   zTest_raise.test_tuple_detectionc                 C   r<   )Nzraise (((E1, E2), E3), E4), Vraise E1(V)r=   r>   r   r   r   test_tuple_exc_1  rG   zTest_raise.test_tuple_exc_1c                 C   r<   )Nzraise (E1, (E2, E3), E4), Vr   r=   r>   r   r   r   test_tuple_exc_2  rG   zTest_raise.test_tuple_exc_2c                 C      d}|  |d d S )Nzraise 'foo'+Python 3 does not support string exceptionsr&   r^   r   r   r   test_string_exc     zTest_raise.test_string_excc                 C   r   )Nzraise "foo", 5r   r   r^   r   r   r   test_string_exc_val  r   zTest_raise.test_string_exc_valc                 C   r   )Nzraise "foo", 5, 6r   r   r^   r   r   r   test_string_exc_val_tb  r   z!Test_raise.test_string_exc_val_tbc                 C   r<   )Nz4def foo():
                    raise Exception, 5, 6Cdef foo():
                    raise Exception(5).with_traceback(6)r=   r>   r   r   r   	test_tb_1     zTest_raise.test_tb_1c                 C   r<   )Nzhdef foo():
                    a = 5
                    raise Exception, 5, 6
                    b = 6wdef foo():
                    a = 5
                    raise Exception(5).with_traceback(6)
                    b = 6r=   r>   r   r   r   	test_tb_2     zTest_raise.test_tb_2c                 C   r<   )Nz2def foo():
                    raise Exception,5,6r   r=   r>   r   r   r   	test_tb_3  r   zTest_raise.test_tb_3c                 C   r<   )Nzfdef foo():
                    a = 5
                    raise Exception,5,6
                    b = 6r   r=   r>   r   r   r   	test_tb_4  r   zTest_raise.test_tb_4c                 C   r<   )Nz<def foo():
                    raise Exception, (5, 6, 7), 6zIdef foo():
                    raise Exception(5, 6, 7).with_traceback(6)r=   r>   r   r   r   	test_tb_5  r   zTest_raise.test_tb_5c                 C   r<   )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 = 6r=   r>   r   r   r   	test_tb_6  r   zTest_raise.test_tb_6N)r7   r*   r8   r	   rA   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s&    	r   c                   @      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   r<   )Nzg.throw(Exception, 5)g.throw(Exception(5))r=   r>   r   r   r   rF     rG   zTest_throw.test_1c                 C   r<   )Nzg.throw(Exception,5)r   r=   r>   r   r   r   rH     rG   zTest_throw.test_2c                 C   r<   )Nzg.throw(Exception, (5, 6, 7))zg.throw(Exception(5, 6, 7))r=   r>   r   r   r   rI     rG   zTest_throw.test_3c                 C   r<   )Nz5 + g.throw(Exception, 5)z5 + g.throw(Exception(5))r=   r>   r   r   r   rJ     rG   zTest_throw.test_4c                 C   r   )Nzg.throw("foo")r   r   r^   r   r   r   test_warn_1  r   zTest_throw.test_warn_1c                 C   r   )Nzg.throw("foo", 5)r   r   r^   r   r   r   test_warn_2!  r   zTest_throw.test_warn_2c                 C   r   )Nzg.throw("foo", 5, 6)r   r   r^   r   r   r   test_warn_3%  r   zTest_throw.test_warn_3c                 C   r]   )Nzg.throw(Exception)r$   r^   r   r   r   test_untouched_1+  ra   zTest_throw.test_untouched_1c                 C   r]   )Nzg.throw(Exception(5, 6))r$   r^   r   r   r   test_untouched_2/  ra   zTest_throw.test_untouched_2c                 C   r]   )Nz5 + g.throw(Exception(5, 6))r$   r^   r   r   r   test_untouched_33  ra   zTest_throw.test_untouched_3c                 C   r<   )Nz7def foo():
                    g.throw(Exception, 5, 6)Fdef foo():
                    g.throw(Exception(5).with_traceback(6))r=   r>   r   r   r   r   9  r   zTest_throw.test_tb_1c                 C   r<   )Nzkdef foo():
                    a = 5
                    g.throw(Exception, 5, 6)
                    b = 6zdef foo():
                    a = 5
                    g.throw(Exception(5).with_traceback(6))
                    b = 6r=   r>   r   r   r   r   @  r   zTest_throw.test_tb_2c                 C   r<   )Nz5def foo():
                    g.throw(Exception,5,6)r   r=   r>   r   r   r   r   K  r   zTest_throw.test_tb_3c                 C   r<   )Nzidef foo():
                    a = 5
                    g.throw(Exception,5,6)
                    b = 6r   r=   r>   r   r   r   r   R  r   zTest_throw.test_tb_4c                 C   r<   )Nz?def foo():
                    g.throw(Exception, (5, 6, 7), 6)zLdef foo():
                    g.throw(Exception(5, 6, 7).with_traceback(6))r=   r>   r   r   r   r   ]  r   zTest_throw.test_tb_5c                 C   r<   )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 = 6r=   r>   r   r   r   r   d  r   zTest_throw.test_tb_6c                 C   r<   )Nz;def foo():
                    a + g.throw(Exception, 5, 6)zJdef foo():
                    a + g.throw(Exception(5).with_traceback(6))r=   r>   r   r   r   	test_tb_7o  r   zTest_throw.test_tb_7c                 C   r<   )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 = 6r=   r>   r   r   r   	test_tb_8v  r   zTest_throw.test_tb_8N)r7   r*   r8   r	   rF   rH   rI   rJ   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s(    r   c                   @   8   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   r<   )Nzx = long(x)z
x = int(x)r=   r>   r   r   r   rF     rG   zTest_long.test_1c                 C   r<   )Nzy = isinstance(x, long)zy = isinstance(x, int)r=   r>   r   r   r   rH     rG   zTest_long.test_2c                 C   r<   )Nzz = type(x) in (int, long)zz = type(x) in (int, int)r=   r>   r   r   r   rI     rG   zTest_long.test_3c                 C   sf   d}|  | d}|  | d}|  | d}|  | d}|  | d}|  | d}|  | 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): passr$   r^   r   r   r   rw     s   





zTest_long.test_unchangedc                 C   r<   )Nzx =   long(  x  )zx =   int(  x  )r=   r>   r   r   r   rz     rG   z"Test_long.test_prefix_preservationN)	r7   r*   r8   r	   rF   rH   rI   rw   rz   r   r   r   r   r     s    r   c                   @       e Zd ZdZdd Zdd ZdS )Test_execfileZexecfilec                 C   s|   d}d}|  || d}d}|  || d}d}|  || d}d}|  || d	}d
}|  || d}d}|  || d S )Nzexecfile("fn")z4exec(compile(open("fn", "rb").read(), "fn", 'exec'))zexecfile("fn", glob)z:exec(compile(open("fn", "rb").read(), "fn", 'exec'), glob)zexecfile("fn", glob, loc)z?exec(compile(open("fn", "rb").read(), "fn", 'exec'), glob, loc)zexecfile("fn", globals=glob)zBexec(compile(open("fn", "rb").read(), "fn", 'exec'), globals=glob)zexecfile("fn", locals=loc)z@exec(compile(open("fn", "rb").read(), "fn", 'exec'), locals=loc)z(execfile("fn", globals=glob, locals=loc)zNexec(compile(open("fn", "rb").read(), "fn", 'exec'), globals=glob, locals=loc)r=   r>   r   r   r   test_conversion  $   zTest_execfile.test_conversionc                 C   rr   )Nzexecfile( "fn" )z6exec(compile(open( "fn", "rb" ).read(), "fn", 'exec'))zexecfile("fn",  globals = glob)zEexec(compile(open("fn", "rb").read(), "fn", 'exec'),  globals = glob)r=   r>   r   r   r   test_spacing  r   zTest_execfile.test_spacingN)r7   r*   r8   r	   r   r   r   r   r   r   r     s    r   c                   @   r9   )	Test_isinstance
isinstancec                 C   r   )	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>   r   r   r   test_remove_multiple_items     z*Test_isinstance.test_remove_multiple_itemsc                 C   r<   )Nz4if    isinstance(  foo(), (  bar, bar, baz )) : passz/if    isinstance(  foo(), (  bar, baz )) : passr=   r>   r   r   r   rz     rG   z(Test_isinstance.test_prefix_preservationc                 C      |  d d S )Nzisinstance(x, (str, int))r$   r   r   r   r   rw        zTest_isinstance.test_unchangedN)r7   r*   r8   r	   r   rz   rw   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d0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBdC Z$dDdE Z%dFdG Z&dHS )I	Test_dictdictc                 C   s|   d}d}|  || d}d}|  || d}d}|  || d}d}|  || d	}d
}|  || d}d}|  || 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>   r   r   r   rz     r   z"Test_dict.test_prefix_preservationc                 C   s|   d}d}|  || d}d}|  || d}d}|  || d}d}|  || d}d}|  || d	}d}|  || 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()  # foor=   r>   r   r   r   test_trailing_comment  s$   zTest_dict.test_trailing_commentc                 C   sF   t jD ]}d| }| | d| }| | d| }| | qd S )Nzs = %s(d.keys())zs = %s(d.values())zs = %s(d.items())r   Zconsuming_callsr"   )r   wrapperr_   r   r   r   rw   *     


zTest_dict.test_unchangedc                 C   rr   )Nd.keys()list(d.keys())za[0].foo().keys()zlist(a[0].foo().keys())r=   r>   r   r   r   test_015  r   zTest_dict.test_01c                 C   r<   )N	d.items()zlist(d.items())r=   r>   r   r   r   test_02>  rG   zTest_dict.test_02c                 C   r<   )N
d.values()zlist(d.values())r=   r>   r   r   r   test_03C  rG   zTest_dict.test_03c                 C   r<   )Nzd.iterkeys()iter(d.keys())r=   r>   r   r   r   test_04H  rG   zTest_dict.test_04c                 C   r<   )Nzd.iteritems()ziter(d.items())r=   r>   r   r   r   test_05M  rG   zTest_dict.test_05c                 C   r<   )Nzd.itervalues()ziter(d.values())r=   r>   r   r   r   test_06R  rG   zTest_dict.test_06c                 C   r]   )Nr   r$   r^   r   r   r   test_07W  ra   zTest_dict.test_07c                 C   r]   )Nsorted(d.keys())r$   r^   r   r   r   test_08[  ra   zTest_dict.test_08c                 C   r<   )Nr   ziter(list(d.keys()))r=   r>   r   r   r   test_09_  rG   zTest_dict.test_09c                 C   r<   )Nzfoo(d.keys())zfoo(list(d.keys()))r=   r>   r   r   r   rP   d  rG   zTest_dict.test_10c                 C   r<   )Nfor i in d.keys(): print iz for i in list(d.keys()): print ir=   r>   r   r   r   rQ   i  rG   zTest_dict.test_11c                 C   r<   )Nzfor i in d.iterkeys(): print ir  r=   r>   r   r   r   test_12n  rG   zTest_dict.test_12c                 C   r<   )N[i for i in d.keys()]z[i for i in list(d.keys())]r=   r>   r   r   r   test_13s  rG   zTest_dict.test_13c                 C   r<   )Nz[i for i in d.iterkeys()]r	  r=   r>   r   r   r   test_14x  rG   zTest_dict.test_14c                 C   r<   )N(i for i in d.keys())z(i for i in list(d.keys()))r=   r>   r   r   r   test_15}  rG   zTest_dict.test_15c                 C   r<   )Nz(i for i in d.iterkeys())r  r=   r>   r   r   r   test_16  rG   zTest_dict.test_16c                 C   r<   )Nziter(d.iterkeys())r   r=   r>   r   r   r   test_17  rG   zTest_dict.test_17c                 C   r<   )Nzlist(d.iterkeys())r   r=   r>   r   r   r   test_18  rG   zTest_dict.test_18c                 C   r<   )Nzsorted(d.iterkeys())r  r=   r>   r   r   r   test_19  rG   zTest_dict.test_19c                 C   r<   )Nzfoo(d.iterkeys())zfoo(iter(d.keys()))r=   r>   r   r   r   test_20  rG   zTest_dict.test_20c                 C   r<   )Nzprint h.iterkeys().next()zprint iter(h.keys()).next()r=   r>   r   r   r   test_21  rG   zTest_dict.test_21c                 C   r<   )Nzprint h.keys()[0]zprint list(h.keys())[0]r=   r>   r   r   r   test_22  rG   zTest_dict.test_22c                 C   r<   )Nzprint list(h.iterkeys().next())z!print list(iter(h.keys()).next())r=   r>   r   r   r   test_23  rG   zTest_dict.test_23c                 C   r<   )Nzfor x in h.keys()[0]: print xz#for x in list(h.keys())[0]: print xr=   r>   r   r   r   test_24  rG   zTest_dict.test_24c                 C   r<   )Nzd.viewkeys()r   r=   r>   r   r   r   test_25  rG   zTest_dict.test_25c                 C   r<   )Nzd.viewitems()r   r=   r>   r   r   r   test_26  rG   zTest_dict.test_26c                 C   r<   )Nzd.viewvalues()r   r=   r>   r   r   r   test_27  rG   zTest_dict.test_27c                 C   r<   )Nz[i for i in d.viewkeys()]r	  r=   r>   r   r   r   test_28  rG   zTest_dict.test_28c                 C   r<   )Nz(i for i in d.viewkeys())r  r=   r>   r   r   r   test_29  rG   zTest_dict.test_29c                 C   r<   )Nziter(d.viewkeys())r   r=   r>   r   r   r   test_30  rG   zTest_dict.test_30c                 C   r<   )Nzlist(d.viewkeys())r   r=   r>   r   r   r   test_31  rG   zTest_dict.test_31c                 C   r<   )Nzsorted(d.viewkeys())r  r=   r>   r   r   r   test_32  rG   zTest_dict.test_32N)'r7   r*   r8   r	   rz   r   rw   r   r   r   r   r  r  r  r  r  rP   rQ   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     sJ    	r   c                   @   sX   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   rt   )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>   r   r   r   rz     rv   z$Test_xrange.test_prefix_preservationc                 C   r<   )Nzx = xrange(10)zx = range(10)r=   r>   r   r   r   test_single_arg  rG   zTest_xrange.test_single_argc                 C   r<   )Nzx = xrange(1, 10)zx = range(1, 10)r=   r>   r   r   r   test_two_args  rG   zTest_xrange.test_two_argsc                 C   r<   )Nzx = xrange(0, 10, 2)zx = range(0, 10, 2)r=   r>   r   r   r   test_three_args  rG   zTest_xrange.test_three_argsc                 C   sh   d}d}|  || d}d}|  || d}d}|  || d}d}|  || d	}d
}|  || 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>   r   r   r   test_wrap_in_list  s   zTest_xrange.test_wrap_in_listc                 C   rr   )Nzfor i in xrange(10):
    j=izfor i in range(10):
    j=iz[i for i in xrange(10)][i for i in range(10)]r=   r>   r   r   r   test_xrange_in_for  r   zTest_xrange.test_xrange_in_forc                 C      |  d |  d d S )Nzfor i in range(10): passr%  r$   r   r   r   r   test_range_in_for     
zTest_xrange.test_range_in_forc                 C   r   )Nzx in range(10, 3, 9)r$   r   r   r   r   test_in_contains_test  r   z!Test_xrange.test_in_contains_testc                 C   s   t jD ]	}| d|  qd S )Nza = %s(range(10))r   )r   callr   r   r   test_in_consuming_context  s   
z%Test_xrange.test_in_consuming_contextN)r7   r*   r8   r	   rz   r!  r"  r#  r$  r&  r(  r*  r,  r   r   r   r   r    s    	r  c                       $   e Zd Z fddZdd Z  ZS )Test_xrange_with_reducec                    s   t t| ddg d S )Nr   r~   )superr.  r   r   r)   r   r   r   !  s   zTest_xrange_with_reduce.setUpc                 C   r<   )Nzreduce(x, xrange(5))z0from functools import reduce
reduce(x, range(5))r=   r>   r   r   r   test_double_transform$     z-Test_xrange_with_reduce.test_double_transform)r7   r*   r8   r   r1  __classcell__r   r   r0  r   r.    s    r.  c                   @   P   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   rr   )Nzx =    raw_input(   )zx =    input(   )zx = raw_input(   ''   )x = input(   ''   )r=   r>   r   r   r   rz   -  r   z'Test_raw_input.test_prefix_preservationc                 C   r<   )Nzx = raw_input()x = input()r=   r>   r   r   r   rF   6  rG   zTest_raw_input.test_1c                 C   r<   )Nzx = raw_input('')x = input('')r=   r>   r   r   r   rH   ;  rG   zTest_raw_input.test_2c                 C   r<   )Nzx = raw_input('prompt')x = input('prompt')r=   r>   r   r   r   rI   @  rG   zTest_raw_input.test_3c                 C   r<   )Nzx = raw_input(foo(a) + 6)zx = input(foo(a) + 6)r=   r>   r   r   r   rJ   E  rG   zTest_raw_input.test_4c                 C   r<   )Nzx = raw_input(invite).split()zx = input(invite).split()r=   r>   r   r   r   rK   J  rG   zTest_raw_input.test_5c                 C   r<   )Nz x = raw_input(invite) . split ()zx = input(invite) . split ()r=   r>   r   r   r   rL   O  rG   zTest_raw_input.test_6c                 C   r<   )Nzx = int(raw_input())zx = int(input())r=   r>   r   r   r   rN   T  rG   zTest_raw_input.test_8N)r7   r*   r8   r	   rz   rF   rH   rI   rJ   rK   rL   rN   r   r   r   r   r5  *  s    	r5  c                   @   (   e Zd ZdZg dZdd Zdd ZdS )Test_funcattrsZ	funcattrs)Zclosuredocnamedefaultscodeglobalsr   c                 C   sH   | j D ]}d| }d| }| || d| }d| }| || qd S )Nz	a.func_%sa.__%s__zself.foo.func_%s.foo_barself.foo.__%s__.foo_barattrsr   r   attrr?   r@   r   r   r   rq   ^  s   
zTest_funcattrs.testc                 C   F   | j D ]}d| }| | d| }| | d| }| | qd S )Nzfoo(func_%s + 5)f(foo.__%s__)f(foo.__%s__.foo)rD  r"   r   rF  r_   r   r   r   rw   h  r   zTest_funcattrs.test_unchangedNr7   r*   r8   r	   rD  rq   rw   r   r   r   r   r;  Y  s
    
r;  c                   @   r9   )	Test_xreadlinesZ
xreadlinesc                 C   rt   )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()): passr=   r>   r   r   r   rZ   v  rv   zTest_xreadlines.test_callc                 C   rt   )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>   r   r   r   test_attr_ref  rv   zTest_xreadlines.test_attr_refc                 C   <   d}|  | d}|  | d}|  | d}|  | 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^   r   r   r   rw        


zTest_xreadlines.test_unchangedN)r7   r*   r8   r	   rZ   rN  rw   r   r   r   r   rM  s  s
    rM  c                   @   s<   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   sP   | j  D ] \}}d| }d| }| || d| }d| }| || qd S )N	import %szimport foo, %s, barmodulesitemsr   r   oldnewr?   r@   r   r   r   test_import_module     z$ImportsFixerTests.test_import_modulec                 C   sl   | j  D ].\}}d| }d| }| || d| }d| }| || d| }d| }| || qd S )Nzfrom %s import foozfrom %s import foo, barzfrom %s import (yes, no)rS  rV  r   r   r   test_import_from  s   z"ImportsFixerTests.test_import_fromc                 C   sP   | j  D ] \}}d| }d| }| || d| }d| }| || qd S )Nzimport %s as foo_barrS  rV  r   r   r   test_import_module_as  rZ  z'ImportsFixerTests.test_import_module_asc                 C   4   | j  D ]\}}d| }d| }| || qd S )Nzfrom %s import foo as barrS  rV  r   r   r   test_import_from_as  
   z%ImportsFixerTests.test_import_from_asc                 C   r]  )Nfrom %s import *rS  rV  r   r   r   	test_star  r_  zImportsFixerTests.test_starc                 C   s   | j  D ]X\}}d||f }d||f }| || d||f }d||f }| || d|f }| | d|||f }d|||f }| || d||f }d||f }| || qd 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
                )rT  rU  r   r"   )r   rW  rX  r?   r@   r_   r   r   r   test_import_module_usage  sD   
z*ImportsFixerTests.test_import_module_usageN)	r7   r*   r8   rY  r[  r\  r^  ra  rb  r   r   r   r   rQ    s    

rQ  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   r<   )Nzimport urlparse, cStringIOzimport urllib.parse, ior=   r>   r   r   r   test_multiple_imports  rG   z"Test_imports.test_multiple_importsc                 C   r<   )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>   r   r   r   test_multiple_imports_as	  r   z%Test_imports.test_multiple_imports_asN)	r7   r*   r8   r	   fixes.fix_importsrg  rT  rh  ri  r   r   r   r   rc     s
    rc  c                   @   s   e Zd ZdZddlmZ dS )Test_imports2imports2re  rf  N)r7   r*   r8   r	   fixes.fix_imports2rg  rT  r   r   r   r   rk    s    rk  c                       r-  )Test_imports_fixer_orderc                    sR   t t| ddg ddlm} | | _ddlm} dD ]	}|| | j|< qd S )Nrd  rl  re  rf  )dbhashdumbdbmdbmgdbm)r/  rn  r   rm  rg  copyrT  rj  )r   Zmapping2Zmapping1keyr0  r   r   r     s   
zTest_imports_fixer_order.setUpc                 C   s   dD ]
}|| _ | d qd S )N)rd  rl  import)r	   r6   )r   Zfixr   r   r   $test_after_local_imports_refactoring$  s   z=Test_imports_fixer_order.test_after_local_imports_refactoring)r7   r*   r8   r   rv  r3  r   r   r0  r   rn    s    rn  c                   @   s\   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d ZdS )Test_urlliburllibre  rf  c                 C   sD   | j  D ]\}}d| }ddttd| }| || qd S )NrR  r(   r   )rT  rU  r    mapr   r   )r   rW  changesr?   r@   r   r   r   rY  .  s
   zTest_urllib.test_import_modulec           
      C   s   | j  D ]o\}}g }|D ]M\}}|D ]"}|| d||f }d||f }| || d| }	| |	 qd|d|f }d|d|f }| || dd| }	| |	 qd|d|f }ddd |D }| || qd S )Nfrom %s import %sfrom foo import %sr(   
c                 S   s"   g | ]\}}d |d |f qS )r{  r(   )r    )r+   rX  membersr   r   r   r-   J  s    z0Test_urllib.test_import_from.<locals>.<listcomp>)rT  rU  appendr   r"   r    )
r   rW  rz  Zall_membersrX  r~  memberr?   r@   r_   r   r   r   r[  4  s*   

zTest_urllib.test_import_fromc                 C   $   | j D ]}d| }| |d qd S )Nzimport %s as fooz#This module is now multiple modulesrT  r&   r   rW  r_   r   r   r   r\  N     
z!Test_urllib.test_import_module_asc                 C   s|   | j  D ]6\}}|D ]/\}}|D ](}d||f }d||f }| || d|||f }d|||f }| || qqqd S )Nfrom %s import %s as foo_barzfrom %s import %s as blah, %srS  )r   rW  rz  rX  r~  r  r?   r@   r   r   r   r^  S  s   zTest_urllib.test_import_from_asc                 C   r  )Nr`  zCannot handle star importsr  r  r   r   r   ra  ^  r  zTest_urllib.test_starc                 C   rr   )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>   r   r   r   test_indentedc  s   zTest_urllib.test_indentedc                 C   r<   )Nzfrom urllib import getproxiesz%from urllib.request import getproxiesr=   r>   r   r   r   test_single_import|  r2  zTest_urllib.test_single_importc           	   	   C   s   | j  D ]I\}}|D ]B\}}|D ];}ddd | j | D }d|||f }d|||f }| || d|||||f }d|||||f }| || qqqd S )Nr(   c                 S   s   g | ]\}}|qS r   r   )r+   r5   Zmemsr   r   r   r-     r.   z8Test_urllib.test_import_module_usage.<locals>.<listcomp>z^
                        import %s
                        foo(%s.%s)
                        z`
                        import %s
                        %s.%s(%s.%s)
                        )rT  rU  r    r   )	r   rW  rz  rX  r~  r  Z
new_importr?   r@   r   r   r   rb    s.   
z$Test_urllib.test_import_module_usageN)r7   r*   r8   r	   Zfixes.fix_urllibrg  rT  rY  r[  r\  r^  ra  r  r  rb  r   r   r   r   rw  *  s    rw  c                   @   r   )
Test_inputinputc                 C   rr   )Nzx =   input(   )zx =   eval(input(   ))r6  zx = eval(input(   ''   ))r=   r>   r   r   r   rz     r   z#Test_input.test_prefix_preservationc                 C   r<   )Nzx = input()  #  foozx = eval(input())  #  foor=   r>   r   r   r   r     rG   z Test_input.test_trailing_commentc                 C   .   d}|  | d}|  | d}|  | d S )Nx = eval(input())x = eval(input(''))x = eval(input(foo(5) + 9))r$   r^   r   r   r   r        

zTest_input.test_idempotencyc                 C   r<   )Nr7  r  r=   r>   r   r   r   rF     rG   zTest_input.test_1c                 C   r<   )Nr8  r  r=   r>   r   r   r   rH     rG   zTest_input.test_2c                 C   r<   )Nr9  zx = eval(input('prompt'))r=   r>   r   r   r   rI     rG   zTest_input.test_3c                 C   r<   )Nzx = input(foo(5) + 9)r  r=   r>   r   r   r   rJ     rG   zTest_input.test_4N)r7   r*   r8   r	   rz   r   r   rF   rH   rI   rJ   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   r]   )Nzdef foo(): passr$   r^   r   r   r   r`     ra   z"Test_tuple_params.test_unchanged_1c                 C   r]   )Nzdef foo(a, b, c): passr$   r^   r   r   r   rb     ra   z"Test_tuple_params.test_unchanged_2c                 C   r]   )Nzdef foo(a=3, b=4, c=5): passr$   r^   r   r   r   rc     ra   z"Test_tuple_params.test_unchanged_3c                 C   r<   )Nz8
            def foo(((a, b), c)):
                x = 5zn
            def foo(xxx_todo_changeme):
                ((a, b), c) = xxx_todo_changeme
                x = 5r=   r>   r   r   r   rF     r   zTest_tuple_params.test_1c                 C   r<   )Nz;
            def foo(((a, b), c), d):
                x = 5zq
            def foo(xxx_todo_changeme, d):
                ((a, b), c) = xxx_todo_changeme
                x = 5r=   r>   r   r   r   rH     r   zTest_tuple_params.test_2c                 C   r<   )Nz@
            def foo(((a, b), c), d) -> e:
                x = 5zv
            def foo(xxx_todo_changeme, d) -> e:
                ((a, b), c) = xxx_todo_changeme
                x = 5r=   r>   r   r   r   rI     r   zTest_tuple_params.test_3c                 C   r<   )Nz/
            def foo(((a, b), c)): x = 5; y = 7zV
            def foo(xxx_todo_changeme): ((a, b), c) = xxx_todo_changeme; x = 5; y = 7r=   r>   r   r   r   test_semicolon  rB   z Test_tuple_params.test_semicolonc                 C   r<   )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 = 5r=   r>   r   r   r   test_keywords  r   zTest_tuple_params.test_keywordsc                 C   r<   )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 = 5r=   r>   r   r   r   test_varargs  r   zTest_tuple_params.test_varargsc                 C   r<   )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 = 5r=   r>   r   r   r   test_multi_1     zTest_tuple_params.test_multi_1c                 C   r<   )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 = 5r=   r>   r   r   r   test_multi_2%  r  zTest_tuple_params.test_multi_2c                 C   r<   )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 = 5r=   r>   r   r   r   test_docstring1     z Test_tuple_params.test_docstringc                 C   r]   )Nlambda x: x + 5r$   r^   r   r   r   test_lambda_no_change?  ra   z'Test_tuple_params.test_lambda_no_changec                 C   T   d}d}|  || d}d}|  || d}d}|  || d}d}|  || d S )Nzlambda (x): x + 5r  zlambda(x): x + 5zlambda ((((x)))): x + 5zlambda((((x)))): x + 5r=   r>   r   r   r   test_lambda_parens_single_argC  r   z/Test_tuple_params.test_lambda_parens_single_argc                 C   r  )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>   r   r   r   test_lambda_simpleT  r   z$Test_tuple_params.test_lambda_simplec                 C   ,   d}d}|  || d}d}|  || d S )Nzlambda (x,): x + f(x)zlambda x1: x1[0] + f(x1[0])zlambda (((x,))): x + f(x)r=   r>   r   r   r   test_lambda_one_tuplee  r   z'Test_tuple_params.test_lambda_one_tuplec                 C   r<   )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>   r   r   r   test_lambda_simple_multi_usen  rG   z.Test_tuple_params.test_lambda_simple_multi_usec                 C   r<   )Nzlambda (x, y): y + xzlambda x_y: x_y[1] + x_y[0]r=   r>   r   r   r   test_lambda_simple_reverses  rG   z,Test_tuple_params.test_lambda_simple_reversec                 C   r  )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 + zr=   r>   r   r   r   test_lambda_nestedx  r   z$Test_tuple_params.test_lambda_nestedc                 C   r<   )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>   r   r   r   test_lambda_nested_multi_use  rG   z.Test_tuple_params.test_lambda_nested_multi_useN)r7   r*   r8   r	   r`   rb   rc   rF   rH   rI   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r    s,    		r  c                   @   r:  )Test_methodattrsZmethodattrs)funcr   classc                 C   sd   | j D ],}d| }|dkrd}nd| }| || d| }|dkr%d}nd| }| || qd S )Nza.im_%sr  za.__self__.__class__rA  zself.foo.im_%s.foo_barz#self.foo.__self__.__class__.foo_barrB  rC  rE  r   r   r   rq     s   
zTest_methodattrs.testc                 C   rG  )Nzfoo(im_%s + 5)rH  rI  rJ  rK  r   r   r   rw     r   zTest_methodattrs.test_unchangedNrL  r   r   r   r   r    s
    r  c                   @   sx  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d0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBdC Z$dDdE Z%dFdG Z&dHdI Z'dJdK Z(dLdM Z)dNdO Z*dPdQ Z+dRdS Z,dTdU Z-dVdW Z.dXdY Z/dZd[ Z0d\S )]	Test_nextnextc                 C   r<   )Nz	it.next()znext(it)r=   r>   r   r   r   rF     rG   zTest_next.test_1c                 C   r<   )Nza.b.c.d.next()znext(a.b.c.d)r=   r>   r   r   r   rH     rG   zTest_next.test_2c                 C   r<   )Nz(a + b).next()znext((a + b))r=   r>   r   r   r   rI     rG   zTest_next.test_3c                 C   r<   )Nz
a().next()z	next(a())r=   r>   r   r   r   rJ     rG   zTest_next.test_4c                 C   r<   )Nza().next() + bznext(a()) + br=   r>   r   r   r   rK     rG   zTest_next.test_5c                 C   r<   )Nzc(      a().next() + b)zc(      next(a()) + b)r=   r>   r   r   r   rL     rG   zTest_next.test_6c                 C   r<   )NzU
            for a in b:
                foo(a)
                a.next()
            zT
            for a in b:
                foo(a)
                next(a)
            r=   r>   r   r   r   test_prefix_preservation_1  r   z$Test_next.test_prefix_preservation_1c                 C   r<   )Nzq
            for a in b:
                foo(a) # abc
                # def
                a.next()
            zp
            for a in b:
                foo(a) # abc
                # def
                next(a)
            r=   r>   r   r   r   test_prefix_preservation_2  r   z$Test_next.test_prefix_preservation_2c                 C      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__()
            Tr   r=   r>   r   r   r   test_prefix_preservation_3     z$Test_next.test_prefix_preservation_3c                 C   r  )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__()
            Tr  r=   r>   r   r   r   test_prefix_preservation_4  s   z$Test_next.test_prefix_preservation_4c                 C   r  )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__())
            Tr  r=   r>   r   r   r   test_prefix_preservation_5	  r  z$Test_next.test_prefix_preservation_5c                 C   r<   )Nze
            for a in b:
                foo(foo(a), # abc
                    a.next())
            zd
            for a in b:
                foo(foo(a), # abc
                    next(a))
            r=   r>   r   r   r   test_prefix_preservation_6	  r   z$Test_next.test_prefix_preservation_6c                 C   r<   )Nz[
            class A:
                def next(self):
                    pass
            z_
            class A:
                def __next__(self):
                    pass
            r=   r>   r   r   r   test_method_1	  r   zTest_next.test_method_1c                 C   r<   )Nzc
            class A(object):
                def next(self):
                    pass
            zg
            class A(object):
                def __next__(self):
                    pass
            r=   r>   r   r   r   test_method_2,	  r   zTest_next.test_method_2c                 C   r<   )NzX
            class A:
                def next(x):
                    pass
            z\
            class A:
                def __next__(x):
                    pass
            r=   r>   r   r   r   test_method_39	  r   zTest_next.test_method_3c                 C   r<   )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>   r   r   r   test_method_4F	  s   zTest_next.test_method_4c                 C   r]   )Nza
            class A:
                def next(self, a, b):
                    pass
            r$   r^   r   r   r   test_method_unchanged_	  r   zTest_next.test_method_unchangedc                 C   r   )Nzy
            next = foo

            class A:
                def next(self, a, b):
                    pass
            )Calls to builtin next() possibly shadowedr   r^   r   r   r   test_shadowing_assign_simpleg	     z&Test_next.test_shadowing_assign_simplec                 C   r   )Nz~
            (next, a) = foo

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_shadowing_assign_tuple_1q	  r  z'Test_next.test_shadowing_assign_tuple_1c                 C   r   )Nz
            (a, (b, (next, c)), a) = foo

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_shadowing_assign_tuple_2{	  r  z'Test_next.test_shadowing_assign_tuple_2c                 C   r   )Nz~
            [next, a] = foo

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_shadowing_assign_list_1	  r  z&Test_next.test_shadowing_assign_list_1c                 C   r   )Nz
            [a, [b, [next, c]], a] = foo

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_shadowing_assign_list_2	  r  z&Test_next.test_shadowing_assign_list_2c                 C   r   )Nz
            def foo():
                __builtin__.next = foo

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_builtin_assign	     zTest_next.test_builtin_assignc                 C   r   )Nz
            def foo():
                (a, __builtin__.next) = foo

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_builtin_assign_in_tuple	  r  z&Test_next.test_builtin_assign_in_tuplec                 C   r   )Nz
            def foo():
                [a, __builtin__.next] = foo

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_builtin_assign_in_list	  r  z%Test_next.test_builtin_assign_in_listc                 C   r]   )Nz
            def foo():
                A.next = foo

            class A:
                def next(self, a, b):
                    pass
            r$   r^   r   r   r   test_assign_to_next	     zTest_next.test_assign_to_nextc                 C   r]   )Nz
            def foo():
                (a, A.next) = foo

            class A:
                def next(self, a, b):
                    pass
            r$   r^   r   r   r   test_assign_to_next_in_tuple	  r  z&Test_next.test_assign_to_next_in_tuplec                 C   r]   )Nz
            def foo():
                [a, A.next] = foo

            class A:
                def next(self, a, b):
                    pass
            r$   r^   r   r   r   test_assign_to_next_in_list	  r  z%Test_next.test_assign_to_next_in_listc                 C   r   )Nz
            import foo.bar as next

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_shadowing_import_1	  r  z!Test_next.test_shadowing_import_1c                 C   r   )Nz
            import bar, bar.foo as next

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_shadowing_import_2	  r  z!Test_next.test_shadowing_import_2c                 C   r   )Nz
            import bar, bar.foo as next, baz

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_shadowing_import_3	  r  z!Test_next.test_shadowing_import_3c                 C   r   )Nz
            from x import next

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_shadowing_import_from_1	  r  z&Test_next.test_shadowing_import_from_1c                 C   r   )Nz
            from x.a import next

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_shadowing_import_from_2
  r  z&Test_next.test_shadowing_import_from_2c                 C   r   )Nz
            from x import a, next, b

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_shadowing_import_from_3
  r  z&Test_next.test_shadowing_import_from_3c                 C   r   )Nz
            from x.a import a, next, b

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_shadowing_import_from_4
  r  z&Test_next.test_shadowing_import_from_4c                 C   r   )Nz
            def next(a):
                pass

            class A:
                def next(self, a, b):
                    pass
            r  r   r^   r   r   r   test_shadowing_funcdef_1!
  r  z"Test_next.test_shadowing_funcdef_1c                 C   s   d}d}|  ||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__()
            r  r%   r>   r   r   r   test_shadowing_funcdef_2,
  s   

z"Test_next.test_shadowing_funcdef_2c                 C   r   )NzW
            def f():
                global next
                next = 5
            r  r   r^   r   r   r   test_shadowing_global_1C
     z!Test_next.test_shadowing_global_1c                 C   r   )Nz]
            def f():
                global a, next, b
                next = 5
            r  r   r^   r   r   r   test_shadowing_global_2K
  r  z!Test_next.test_shadowing_global_2c                 C   r   )Nze
            for next in it():
                pass

            b = 5
            c = 6
            r  r   r^   r   r   r   test_shadowing_for_simpleS
  r  z#Test_next.test_shadowing_for_simplec                 C   r   )Nzh
            for next, b in it():
                pass

            b = 5
            c = 6
            r  r   r^   r   r   r   test_shadowing_for_tuple_1]
  r  z$Test_next.test_shadowing_for_tuple_1c                 C   r   )Nzp
            for a, (next, c), b in it():
                pass

            b = 5
            c = 6
            r  r   r^   r   r   r   test_shadowing_for_tuple_2g
  r  z$Test_next.test_shadowing_for_tuple_2c                 C   r<   )Nzgnext = g.nextzgnext = g.__next__r=   r>   r   r   r   test_noncall_access_1q
  rG   zTest_next.test_noncall_access_1c                 C   r<   )Nzf(g.next + 5)zf(g.__next__ + 5)r=   r>   r   r   r   test_noncall_access_2v
  rG   zTest_next.test_noncall_access_2c                 C   r<   )Nzf(g().next + 5)zf(g().__next__ + 5)r=   r>   r   r   r   test_noncall_access_3{
  rG   zTest_next.test_noncall_access_3N)1r7   r*   r8   r	   rF   rH   rI   rJ   rK   rL   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  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r    s^    














r  c                   @   r   )Test_nonzerononzeroc                 C   r<   )Nzb
            class A:
                def __nonzero__(self):
                    pass
            z_
            class A:
                def __bool__(self):
                    pass
            r=   r>   r   r   r   rF   
  r   zTest_nonzero.test_1c                 C   r<   )Nzj
            class A(object):
                def __nonzero__(self):
                    pass
            g
            class A(object):
                def __bool__(self):
                    pass
            r=   r>   r   r   r   rH   
  r   zTest_nonzero.test_2c                 C   r]   )Nr  r$   r^   r   r   r   r`   
  r   zTest_nonzero.test_unchanged_1c                 C   r]   )Nzm
            class A(object):
                def __nonzero__(self, a):
                    pass
            r$   r^   r   r   r   rb   
  r   zTest_nonzero.test_unchanged_2c                 C   r]   )NzE
            def __nonzero__(self):
                pass
            r$   r^   r   r   r   test_unchanged_func
  s   z Test_nonzero.test_unchanged_funcN)	r7   r*   r8   r	   rF   rH   r`   rb   r  r   r   r   r   r  
  s    r  c                   @   sx   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   r<   )NZ07550o755r=   r>   r   r   r   test_octal_1
  rG   zTest_numliterals.test_octal_1c                 C   r<   )Nza = 12La = 12r=   r>   r   r   r   test_long_int_1
  rG   z Test_numliterals.test_long_int_1c                 C   r<   )Nza = 12lr  r=   r>   r   r   r   test_long_int_2
  rG   z Test_numliterals.test_long_int_2c                 C   r<   )Nz	b = 0x12lzb = 0x12r=   r>   r   r   r   test_long_hex
  rG   zTest_numliterals.test_long_hexc                 C   rr   )Nzb =   0x12Lz
b =   0x12zb = 0755 # spamzb = 0o755 # spamr=   r>   r   r   r   test_comments_and_spacing
  r   z*Test_numliterals.test_comments_and_spacingc                 C   r]   )N5r$   r^   r   r   r   test_unchanged_int
  ra   z#Test_numliterals.test_unchanged_intc                 C   r]   )Nz5.0r$   r^   r   r   r   test_unchanged_float
  ra   z%Test_numliterals.test_unchanged_floatc                 C   r]   )Nr  r$   r^   r   r   r   test_unchanged_octal
  ra   z%Test_numliterals.test_unchanged_octalc                 C   r]   )NZ0xABCr$   r^   r   r   r   test_unchanged_hex
  ra   z#Test_numliterals.test_unchanged_hexc                 C   r]   )Nz5.0e10r$   r^   r   r   r   test_unchanged_exp
  ra   z#Test_numliterals.test_unchanged_expc                 C   r]   )Nz5 + 4jr$   r^   r   r   r   test_unchanged_complex_int
  ra   z+Test_numliterals.test_unchanged_complex_intc                 C   r]   )Nz
5.4 + 4.9jr$   r^   r   r   r   test_unchanged_complex_float
  ra   z-Test_numliterals.test_unchanged_complex_floatc                 C   r   )NZ4jz4.4jr$   r^   r   r   r   test_unchanged_complex_bare
  s   
z,Test_numliterals.test_unchanged_complex_bareN)r7   r*   r8   r	   r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r  
  s    	r  c                   @   s8   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)Zmaxintmaxsizec                 C   sV   t | j D ]!\}\}}d||f }d||f }| || d| }| | qd S )Nr{  r|  )listrT  rU  r   r"   )r   modrW  rX  r?   r@   r_   r   r   r   r[  
  s   zTest_renames.test_import_fromc                 C   sD   t | j D ]\}\}}d||f }d||f }| || qd S )Nr  r  rT  rU  r   r   r  rW  rX  r?   r@   r   r   r   r^    s
   z Test_renames.test_import_from_asc                 C   sL   t | j D ]\}\}}d||||f }d||||f }| || qd S )NzJ
                import %s
                foo(%s, %s.%s)
                r  r  r   r   r   rb    s   

z%Test_renames.test_import_module_usagec                 C   sL   t | j D ]\}\}}d||||f }d||||f }| || qd S )NzO
                from %s import %s
                foo(%s, %s)
                r  r  r   r   r   XXX_test_from_import_usage  s   

z'Test_renames.XXX_test_from_import_usageN)	r7   r*   r8   r	   rT  r[  r^  rb  r  r   r   r   r   r  
  s    	r  c                   @   r   )Test_unicodeunicodec                 C   rt   )Nzunicode( x)zstr( x)z unicode(x )z str(x )z u'h'z 'h'r=   r>   r   r   r   test_whitespace'  rv   zTest_unicode.test_whitespacec                 C   r<   )Nzunicode(x, y, z)zstr(x, y, z)r=   r>   r   r   r   test_unicode_call4  rG   zTest_unicode.test_unicode_callc                 C   r<   )Nzunichr(u'h')zchr('h')r=   r>   r   r   r   test_unichr9  rG   zTest_unicode.test_unichrc                 C   r<   )Nzu"x"z"x"r=   r>   r   r   r   test_unicode_literal_1>  rG   z#Test_unicode.test_unicode_literal_1c                 C   r<   )Nzur'x'zr'x'r=   r>   r   r   r   test_unicode_literal_2C  rG   z#Test_unicode.test_unicode_literal_2c                 C   r<   )Nz
UR'''x''' z	R'''x''' r=   r>   r   r   r   test_unicode_literal_3H  rG   z#Test_unicode.test_unicode_literal_3c                 C   s,   d}d}|  || d}d}|  || d S )N'\\\u20ac\U0001d121\\u20ac'z'\\\\u20ac\\U0001d121\\u20ac'r'\\\u20ac\U0001d121\\u20ac'r=   r>   r   r   r   test_native_literal_escape_uM  r   z)Test_unicode.test_native_literal_escape_uc                 C   s,   d}d}|  || d}d}|  || d S )Nzb'\\\u20ac\U0001d121\\u20ac'zbr'\\\u20ac\U0001d121\\u20ac'r=   r>   r   r   r   test_bytes_literal_escape_uV  r   z(Test_unicode.test_bytes_literal_escape_uc                 C   rr   )Nzu'\\\u20ac\U0001d121\\u20ac'r  zur'\\\u20ac\U0001d121\\u20ac'r  r=   r>   r   r   r   test_unicode_literal_escape_u_  r   z*Test_unicode.test_unicode_literal_escape_uc                 C   s@   d}|d }|d }|  || |d }|d }|  || d S )Nz(from __future__ import unicode_literals
r  r  r=   )r   fr?   r@   r   r   r   $test_native_unicode_literal_escape_uh  s   z1Test_unicode.test_native_unicode_literal_escape_uN)r7   r*   r8   r	   r  r  r  r  r  r  r  r   r  r  r   r   r   r   r  $  s    			r  c                   @   r   )Test_filterfilterc                 C   rr   )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>   r   r   r   rz   v  r   z$Test_filter.test_prefix_preservationc                 C   sh   d}d}|  || d}d}|  || d}d}|  || d}d}|  || d}d	}|  || 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))z5filter(lambda x: True if x > 2 else False, [1, 2, 3])z4[x for x in [1, 2, 3] if (True if x > 2 else False)]r=   r>   r   r   r   test_filter_basic  s   zTest_filter.test_filter_basicc                 C   sT   d}d}|  || d}d}|  || d}d}|  || d}d}|  || d S )Nzx = filter(None, 'abc')[0]z!x = [_f for _f in 'abc' if _f][0]zx = len(filter(f, 'abc')[0])z"x = len(list(filter(f, 'abc'))[0])z,x = filter(lambda x: x%2 == 0, range(10))[0]z)x = [x for x in range(10) if x%2 == 0][0]z.x = filter(lambda (x): x%2 == 0, range(10))[0]r=   r>   r   r   r   test_filter_trailers  s   z Test_filter.test_filter_trailersc                 C     d}|  | d}|  | d}|  | d}|  | d}|  | d}|  | d}|  | d}|  | d	}|  | d
}|  | d}|  | d}|  | d}|  | d}|  | d}|  | d}|  | d}|  | d}|  | d}|  | 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   r@   r   r   r   test_filter_nochange  L   

















z Test_filter.test_filter_nochangec                 C   4   d}|  | d}d}| || d}|  | 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   rk   r   r   r   test_future_builtins     
z Test_filter.test_future_builtinsN)	r7   r*   r8   r	   rz   r  r  r
  r  r   r   r   r   r  s  s    	(r  c                       sX   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
dd Z  ZS )Test_mapry  c                    &   |  d| | tt| || d S )Nz!from future_builtins import map; )r"   r/  r  r   r>   r0  r   r   r        zTest_map.checkc                 C   r<   )Nzx =    map(   f,    'abc'   )z#x =    list(map(   f,    'abc'   ))r=   r>   r   r   r   rz     rG   z!Test_map.test_prefix_preservationc                 C   r   )	Nzx = map(f, 'abc')[0]zx = list(map(f, 'abc'))[0]zx = map(None, l)[0]zx = list(l)[0]zx = map(lambda x:x, l)[0]zx = [x for x in l][0]zx = map(f, 'abc')[0][1]zx = list(map(f, 'abc'))[0][1]r=   r>   r   r   r   test_map_trailers  r   zTest_map.test_map_trailersc                 C   r<   )Nzx = map(f, 'abc')   #   fooz!x = list(map(f, 'abc'))   #   foor=   r>   r   r   r   r     rG   zTest_map.test_trailing_commentc                 C   r   )Nzx = map(None, a, b, c)z5cannot convert map(None, ...) with multiple argumentsr   r^   r   r   r   !test_None_with_multiple_arguments  r   z*Test_map.test_None_with_multiple_argumentsc                 C   s~   d}d}|  || d}d}|  || d}d}|  || d}d}|  || d	}d}|  || d
}d}| ||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>   r   r   r   test_map_basic  s$   zTest_map.test_map_basicc                 C   r  )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	  r   r   r   test_map_nochange$  r  zTest_map.test_map_nochangec                 C   r  )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   rk   r   r   r   r  L  r  zTest_map.test_future_builtins)r7   r*   r8   r	   r   rz   r  r   r  r  r  r  r3  r   r   r0  r   r    s    "(r  c                       s@   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Z  Z	S )Test_zipzipc                    r  )Nz!from future_builtins import zip; )r"   r/  r  r   r>   r0  r   r   r   Z  r  zTest_zip.checkc                 C   rt   )Nz	x = zip()zx = list(zip())z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>   r   r   r   test_zip_basic^  rv   zTest_zip.test_zip_basicc                 C   rr   )Nzx = zip(a, b, c)[0]zx = list(zip(a, b, c))[0]zx = zip(a, b, c)[0][1]zx = list(zip(a, b, c))[0][1]r=   r>   r   r   r   test_zip_trailersk  r   zTest_zip.test_zip_trailersc                 C   r  )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	  r   r   r   test_zip_nochanget  r  zTest_zip.test_zip_nochangec                 C   r  )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   rk   r   r   r   r    r  zTest_zip.test_future_builtins)
r7   r*   r8   r	   r   r  r  r  r  r3  r   r   r0  r   r  W  s    	(r  c                   @      e Zd ZdZdd ZdS )Test_standarderrorZstandarderrorc                 C   rt   )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>   r   r   r   rq     rv   zTest_standarderror.testN)r7   r*   r8   r	   rq   r   r   r   r   r        r  c                   @   r  )
Test_typestypesc                 C   s   d}d}|  || d}d}|  || d}d}|  || d}d}|  || d	}d}|  || d
}d}|  || d}d}|  || d S )Nztypes.StringTypebytesztypes.DictTyper   ztypes . IntTypeintztypes.ListTyper  ztypes.LongTypeztypes.NoneTypez
type(None)ztypes.StringTypesz(str,)r=   r>   r   r   r   test_basic_types_convert  s*   z#Test_types.test_basic_types_convertN)r7   r*   r8   r	   r"  r   r   r   r   r    r  r  c                   @   r   )'Test_idiomsZidiomsc                 C   rt   )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>   r   r   r   
test_while  s   zTest_idioms.test_whilec                 C   rO  )Nzwhile 11: foo()zwhile 0: foo()zwhile foo(): foo()zwhile []: foo()r$   r^   r   r   r   test_while_unchanged  rP  z Test_idioms.test_while_unchangedc                 C   rr   )Nztype(x) == Tisinstance(x, T)zif   type(x) == T: passif   isinstance(x, T): passr=   r>   r   r   r   test_eq_simple  r   zTest_idioms.test_eq_simplec                 C   rr   )NzT == type(x)r&  zif   T == type(x): passr'  r=   r>   r   r   r   test_eq_reverse  r   zTest_idioms.test_eq_reversec                 C   rr   )Nztype(x+y) == d.get('T')isinstance(x+y, d.get('T'))ztype(   x  +  y) == d.get('T')isinstance(x  +  y, d.get('T'))r=   r>   r   r   r   test_eq_expression  r   zTest_idioms.test_eq_expressionc                 C   rr   )Nztype(x) is Tr&  zif   type(x) is T: passr'  r=   r>   r   r   r   test_is_simple  r   zTest_idioms.test_is_simplec                 C   rr   )NzT is type(x)r&  zif   T is type(x): passr'  r=   r>   r   r   r   test_is_reverse  r   zTest_idioms.test_is_reversec                 C   rr   )Nztype(x+y) is d.get('T')r*  ztype(   x  +  y) is d.get('T')r+  r=   r>   r   r   r   test_is_expression'  r   zTest_idioms.test_is_expressionc                 C   rr   )Nztype(x) is not Tnot isinstance(x, T)zif   type(x) is not T: passif   not isinstance(x, T): passr=   r>   r   r   r   test_is_not_simple0  r   zTest_idioms.test_is_not_simplec                 C   rr   )NzT is not type(x)r0  zif   T is not type(x): passr1  r=   r>   r   r   r   test_is_not_reverse9  r   zTest_idioms.test_is_not_reversec                 C   rr   )Nztype(x+y) is not d.get('T')not isinstance(x+y, d.get('T'))z"type(   x  +  y) is not d.get('T')#not isinstance(x  +  y, d.get('T'))r=   r>   r   r   r   test_is_not_expressionB  r   z"Test_idioms.test_is_not_expressionc                 C   rr   )Nztype(x) != Tr0  zif   type(x) != T: passr1  r=   r>   r   r   r   test_ne_simpleK  r   zTest_idioms.test_ne_simplec                 C   rr   )NzT != type(x)r0  zif   T != type(x): passr1  r=   r>   r   r   r   test_ne_reverseT  r   zTest_idioms.test_ne_reversec                 C   rr   )Nztype(x+y) != d.get('T')r4  ztype(   x  +  y) != d.get('T')r5  r=   r>   r   r   r   test_ne_expression]  r   zTest_idioms.test_ne_expressionc                 C   r]   )Nztype(x).__name__r$   r	  r   r   r   test_type_unchangedf  ra   zTest_idioms.test_type_unchangedc                 C   s   d}d}|  || d}d}|  || d}d}|  || d}d}|  || d	}d
}|  || d}d}|  || d}d}|  || d}d}|  || d S )NzM
            v = list(t)
            v.sort()
            foo(v)
            :
            v = sorted(t)
            foo(v)
            zV
            v = list(foo(b) + d)
            v.sort()
            foo(v)
            C
            v = sorted(foo(b) + d)
            foo(v)
            zn
            while x:
                v = list(t)
                v.sort()
                foo(v)
            W
            while x:
                v = sorted(t)
                foo(v)
            z_
            v = list(t)
            # foo
            v.sort()
            foo(v)
            L
            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 commentsr=   r>   r   r   r   test_sort_list_callj  s0   zTest_idioms.test_sort_list_callc                 C      d}d}|  || d}d}|  || d}d}|  || d}d}|  || d	}d
}|  || d}d}|  || d}d}|  || d S )NzG
            v = t
            v.sort()
            foo(v)
            r;  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)
            r<  zh
            while x:
                v = t
                v.sort()
                foo(v)
            r=  zY
            v = t
            # foo
            v.sort()
            foo(v)
            r>  zI
            v =   t
            v.sort()
            foo(v)
            z<
            v =   sorted(t)
            foo(v)
            r=   r>   r   r   r   test_sort_simple_expr  s*   z!Test_idioms.test_sort_simple_exprc                 C   r   )NzM
            v = list(t)
            w.sort()
            foo(w)
            zN
            v = list(t)
            v.sort(u)
            foo(v)
            r$   r^   r   r   r   test_sort_unchanged   s   
zTest_idioms.test_sort_unchangedN)r7   r*   r8   r	   r$  r%  r(  r)  r,  r-  r.  r/  r2  r3  r6  r7  r8  r9  r:  r?  rA  rB  r   r   r   r   r#    s(    												dRr#  c                   @   r  )Test_basestring
basestringc                 C   r<   )Nzisinstance(x, basestring)zisinstance(x, str)r=   r>   r   r   r   test_basestring2  rG   zTest_basestring.test_basestringN)r7   r*   r8   r	   rE  r   r   r   r   rC  /  r  rC  c                   @   r   )Test_bufferbufferc                 C   r<   )Nzx = buffer(y)zx = memoryview(y)r=   r>   r   r   r   test_buffer:  rG   zTest_buffer.test_bufferc                 C   r<   )Nzbuffer(y)[4:5]zmemoryview(y)[4:5]r=   r>   r   r   r   test_slicing?  rG   zTest_buffer.test_slicingN)r7   r*   r8   r	   rH  rI  r   r   r   r   rF  7  s    rF  c                   @   r   )Test_futurefuturec                 C   rt   )Nzfrom __future__ import bracesr   z'# comment
from __future__ import bracesz
# comment
z'from __future__ import braces
# commentz

# commentr=   r>   r   r   r   test_futureG  rv   zTest_future.test_futurec                 C   r   )Nr   r6   r   r   r   r   test_run_orderT  r   zTest_future.test_run_orderN)r7   r*   r8   r	   rL  rN  r   r   r   r   rJ  D  s    rJ  c                   @   r4  )Test_itertools	itertoolsc                 C   s<   dD ]}dD ]}||d |  }|| }|  || qqd S )N)z
itertools.r   )ry  r  r  ir=   )r   r   r   rQ  r  r?   r@   r   r   r   checkallZ  s   zTest_itertools.checkallc                 C   r<   )Nzitertools.izip(a, b)z	zip(a, b)r=   r>   r   r   r   test_0d  s   zTest_itertools.test_0c                 C      d}d}|  || d S )Nz%s(f, a)rR  r>   r   r   r   rF   k  rG   zTest_itertools.test_1c                 C   rr   )Nzitertools.ifilterfalse(a, b)zitertools.filterfalse(a, b)zitertools.izip_longest(a, b)zitertools.zip_longest(a, b)r=   r>   r   r   r   test_qualifiedp  r   zTest_itertools.test_qualifiedc                 C   rr   )Nzifilterfalse(a, b)zfilterfalse(a, b)zizip_longest(a, b)zzip_longest(a, b)r=   r>   r   r   r   rH   y  r   zTest_itertools.test_2c                 C   rT  )Nz    %s(f, a)rU  r>   r   r   r   rl     rG   zTest_itertools.test_space_1c                 C   rr   )Nz     itertools.ifilterfalse(a, b)z    itertools.filterfalse(a, b)z     itertools.izip_longest(a, b)z    itertools.zip_longest(a, b)r=   r>   r   r   r   rm     r   zTest_itertools.test_space_2c                 C   s   |  ddd d S )Nry  r  r  rM  r   r   r   r   rN    s   zTest_itertools.test_run_orderN)r7   r*   r8   r	   rR  rS  rF   rV  rH   rl   rm   rN  r   r   r   r   rO  W  s    
			rO  c                   @   r   )Test_itertools_importsZitertools_importsc                 C   rt   )Nz%from itertools import imap, izip, foo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 chainr=   r>   r   r   r   test_reduced  rv   z#Test_itertools_imports.test_reducedc                 C   r<   )Nz%#foo
from itertools import imap, izipz#foo
r=   r>   r   r   r   test_comments  rG   z$Test_itertools_imports.test_commentsc                 C   r  )Nz from itertools import imap, izipr   zfrom itertools import izipr=   r>   r   r   r   	test_none  r   z Test_itertools_imports.test_nonec                 C   sb   d}d}|  || d}d}|  || d}d}|  || d}d}|  || d}| | 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   r?   r@   r_   r   r   r   test_import_as  s   z%Test_itertools_imports.test_import_asc                 C   sn   dD ]2}d|f }d|f }|  || d|f }d|f }|  || d|f }d|f }|  || qd 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, foor=   )r   r=  r?   r@   r   r   r   test_ifilter_and_zip_longest  s   





z3Test_itertools_imports.test_ifilter_and_zip_longestc                 C   r]   )Nzfrom itertools import *r$   r^   r   r   r   test_import_star  ra   z'Test_itertools_imports.test_import_starc                 C   r]   )NrX  r$   r^   r   r   r   rw     ra   z%Test_itertools_imports.test_unchangedN)r7   r*   r8   r	   rY  rZ  r[  r\  r_  r`  rw   r   r   r   r   rW    s    	rW  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  ZS )(Test_importru  c                    sD   t t   g  _t  _d _ fdd}ddlm} ||_	d S )NTc                    s    j |   jp|  jv S r   )files_checkedr  always_existspresent_filesr=  r   r   r   fake_exists  s   z&Test_import.setUp.<locals>.fake_existsr   
fix_import)
r/  ra  r   rb  setrd  rc  lib2to3.fixesrh  exists)r   rf  rh  r0  r   r   r     s   
zTest_import.setUpc                 C   s   ddl m} tjj|_d S )Nr   rg  )rj  rh  ospathrk  )r   rh  r   r   r   tearDown  s   zTest_import.tearDownc                    s2   d| _ tt| || d| _ tt| | d S )NTF)rc  r/  ra  r   r"   r>   r0  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}|D ]7 g | _ | _| d tj	 r>tj	 d  nd t fdd|D }|
d | t| j| q"d S )Nc                 S   s   t jj| dS )N/)rl  rm  pathsepr    split)rm  r   r   r   p  s   z)Test_import.test_files_checked.<locals>.pF__init__.pyz.pyz.pycz.soz.slz.pydz/spam/eggs.pyzni.pyz../../shrubbery.pyz
import jamz/jamZjamc                 3   s    | ]} | V  qd S r   r   )r+   extre  r   r   	<genexpr>  s    z1Test_import.test_files_checked.<locals>.<genexpr>)rc  ri  rd  rl  rm  seprb  r   r"   dirnameaddr   )r   rs  Zexpected_extensionsZnames_to_testZexpected_checksr   re  r   test_files_checked  s    

zTest_import.test_files_checkedc                 C   s$   d}d| _ tdg| _| | d S )N
import barFbar.pyrc  ri  rd  r"   r^   r   r   r   test_not_in_package  s   zTest_import.test_not_in_packagec                 C   s&   d}d| _ tddg| _| | d S )Nz1from __future__ import absolute_import
import barFrt  r|  r}  r^   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| _| || d S )Nr{  from . import barFrt  r|  )rc  ri  rd  r   r>   r   r   r   test_in_package  s
   zTest_import.test_in_packagec                 C   s4   d}d}d| _ tddtjj g| _| || d S )Nr{  r  Frt  Zbar)rc  ri  rl  rm  rw  rd  r   r>   r   r   r   test_import_from_package$  s
   z$Test_import.test_import_from_packagec                 C   r]   )Nr  r$   r^   r   r   r   test_already_relative_import+  ra   z(Test_import.test_already_relative_importc                 C   r<   )Nzimport bar # Foozfrom . import bar # Foor=   r>   r   r   r   test_comments_and_indent/  rG   z$Test_import.test_comments_and_indentc                 C   rt   )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)ro  r>   r   r   r   	test_from4  rv   zTest_import.test_fromc                 C   r<   )Nzfrom green.eggs import hamzfrom .green.eggs import hamr  r>   r   r   r   test_dotted_fromA  rG   zTest_import.test_dotted_fromc                 C   r<   )Nz"from green.eggs import ham as spamz#from .green.eggs import ham as spamr  r>   r   r   r   test_from_asF  rG   zTest_import.test_from_asc                 C   r   )	Nz
import foozfrom . import fooimport foo, barzfrom . import foo, barzimport foo, bar, xzfrom . import foo, bar, xzimport x, y, zzfrom . import x, y, zr  r>   r   r   r   test_importK  r   zTest_import.test_importc                 C   rr   )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 dr  r>   r   r   r   r\  \  r   zTest_import.test_import_asc                 C   s(   d| _ tddg| _d}| |d d S )NFzfoo.pyrt  r  z#absolute and local imports together)rc  ri  rd  r&   r^   r   r   r   test_local_and_absolutee  s   z#Test_import.test_local_and_absolutec                 C   r<   )Nzimport foo.barzfrom . import foo.barr  r>   r   r   r   test_dotted_importl  rG   zTest_import.test_dotted_importc                 C   r<   )Nzimport foo.bar as bangzfrom . import foo.bar as bangr  r>   r   r   r   test_dotted_import_asq  rG   z!Test_import.test_dotted_import_asc                 C   r<   )Nz1
        # prefix
        import foo.bar
        z8
        # prefix
        from . import foo.bar
        r  r>   r   r   r   test_prefixv  r   zTest_import.test_prefix)r7   r*   r8   r	   r   rn  ro  rz  r~  r  r  r  r  r  r  r  r  r  r\  r  r  r  r  r3  r   r   r0  r   ra    s*    	ra  c                   @   r   )Test_set_literalZset_literalc                 C   s   d}d}|  || d}d}|  || d}d}|  || d}|  || d}d}|  || d	}|  || d
}d}|  || d}d}|  || d}d}|  || d S )Nzset([1, 2, 3])z	{1, 2, 3}zset((1, 2, 3))z	set((1,)){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>   r   r   r   rA     s2   zTest_set_literal.test_basicc                 C   r   )	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>   r   r   r   test_listcomps  r   zTest_set_literal.test_listcompsc                 C   r@  )Nzset( [1, 2])z{1, 2}zset([1 ,  2])z{1 ,  2}z
set([ 1 ])z{ 1 }z
set( [1] )r  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>   r   r   r   r    s*   z Test_set_literal.test_whitespacec                 C   rr   )Nzset((1, 2)) # Hiz{1, 2} # HizZ
            # Foo
            set( # Bar
               (1, 2)
            )
            z2
            # Foo
            {1, 2}
            r=   r>   r   r   r   rZ    s   zTest_set_literal.test_commentsc                 C   sX   d}|  | d}|  | d}|  | d}|  | d}|  | d}|  | 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^   r   r   r   rw     s   




zTest_set_literal.test_unchangedN)	r7   r*   r8   r	   rA   r  r  rZ  rw   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   r<   )Nzsys.exc_typezsys.exc_info()[0]r=   r>   r   r   r   rS    rG   zTest_sys_exc.test_0c                 C   r<   )Nzsys.exc_valuezsys.exc_info()[1]r=   r>   r   r   r   rF   	  rG   zTest_sys_exc.test_1c                 C   r<   )Nzsys.exc_tracebackzsys.exc_info()[2]r=   r>   r   r   r   rH     rG   zTest_sys_exc.test_2c                 C   r<   )Nzsys.exc_type # Foozsys.exc_info()[0] # Foor=   r>   r   r   r   rI     rG   zTest_sys_exc.test_3c                 C   r<   )Nzsys.  exc_typezsys.  exc_info()[0]r=   r>   r   r   r   rJ     rG   zTest_sys_exc.test_4c                 C   r<   )Nzsys  .exc_typezsys  .exc_info()[0]r=   r>   r   r   r   rK     rG   zTest_sys_exc.test_5N)
r7   r*   r8   r	   rS  rF   rH   rI   rJ   rK   r   r   r   r   r    s    r  c                   @   sp   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   r<   )Nz[i for i in 1, 2 ]z[i for i in (1, 2) ]r=   r>   r   r   r   rS  &  rG   zTest_paren.test_0c                 C   r<   )Nz[i for i in 1, 2, ]z[i for i in (1, 2,) ]r=   r>   r   r   r   rF   +  rG   zTest_paren.test_1c                 C   r<   )Nz[i for i  in     1, 2 ]z[i for i  in     (1, 2) ]r=   r>   r   r   r   rH   0  rG   zTest_paren.test_2c                 C   r<   )Nz[i for i in 1, 2 if i]z[i for i in (1, 2) if i]r=   r>   r   r   r   rI   5  rG   zTest_paren.test_3c                 C   r<   )Nz[i for i in 1,    2    ]z[i for i in (1,    2)    ]r=   r>   r   r   r   rJ   :  rG   zTest_paren.test_4c                 C   r<   )Nz(i for i in 1, 2)(i for i in (1, 2))r=   r>   r   r   r   rK   ?  rG   zTest_paren.test_5c                 C   r<   )Nz(i for i in 1   ,2   if i)z(i for i in (1   ,2)   if i)r=   r>   r   r   r   rL   D  rG   zTest_paren.test_6c                 C   r]   )Nz[i for i in (1, 2)]r$   r^   r   r   r   test_unchanged_0I  ra   zTest_paren.test_unchanged_0c                 C   r]   )Nz[i for i in foo()]r$   r^   r   r   r   r`   M  ra   zTest_paren.test_unchanged_1c                 C   r]   )Nz[i for i in (1, 2) if nothing]r$   r^   r   r   r   rb   Q  ra   zTest_paren.test_unchanged_2c                 C   r]   )Nr  r$   r^   r   r   r   rc   U  ra   zTest_paren.test_unchanged_3c                 C   r]   )Nz[i for i in m]r$   r^   r   r   r   rd   Y  ra   zTest_paren.test_unchanged_4N)r7   r*   r8   r	   rS  rF   rH   rI   rJ   rK   rL   r  r`   rb   rc   rd   r   r   r   r   r  #  s    r  c                   @   r9   )	Test_metaclass	metaclassc                 C   sf   |  d |  d |  d |  d |  d |  d |  d d}|  | d	}|  | 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^   r   r   r   rw   a  s   







zTest_metaclass.test_unchangedc                 C   rr   )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>   r   r   r   rZ  v  s   zTest_metaclass.test_commentsc                 C   s   d}d}|  || d}d}|  || d}d}|  || d}d}|  || d	}d}|  || d
}d}|  || d}d}|  || d}d}|  || d}d}|  || d}d}|  || d}d}|  || 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>   r   r   r   	test_meta  sB   zTest_metaclass.test_metaN)r7   r*   r8   r	   rw   rZ  r  r   r   r   r   r  ]  s
    r  c                   @   r   )Test_getcwduZgetcwduc                 C   r   )	Nz
os.getcwduz	os.getcwdzos.getcwdu()os.getcwd()zmeth = os.getcwduzmeth = os.getcwdzos.getcwdu(args)zos.getcwd(args)r=   r>   r   r   r   rA     r   zTest_getcwdu.test_basicc                 C   r<   )Nzos.getcwdu() # Foozos.getcwd() # Foor=   r>   r   r   r   rs     rG   zTest_getcwdu.test_commentc                 C   r  )Nr  z	getcwdu()zos.getcwdb()r$   r^   r   r   r   rw     r  zTest_getcwdu.test_unchangedc                 C   r<   )Nz<
            if 1:
                os.getcwdu()
            z;
            if 1:
                os.getcwd()
            r=   r>   r   r   r   test_indentation&  r   zTest_getcwdu.test_indentationc                 C   rt   )Nzos .getcwdu()zos .getcwd()zos.  getcwduzos.  getcwdzos.getcwdu (  )zos.getcwd (  )r=   r>   r   r   r   test_multilation1  rv   zTest_getcwdu.test_multilationN)	r7   r*   r8   r	   rA   rs   rw   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   r<   )Nzoperator.isCallable(x)zcallable(x)r=   r>   r   r   r   test_operator_isCallableC  rG   z&Test_operator.test_operator_isCallablec                 C   rt   )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>   r   r   r   test_operator_sequenceIncludesH  rv   z,Test_operator.test_operator_sequenceIncludesc                 C   r<   )Nzoperator.isSequenceType(x)z>import collections.abc
isinstance(x, collections.abc.Sequence)r=   r>   r   r   r   test_operator_isSequenceTypeU  rG   z*Test_operator.test_operator_isSequenceTypec                 C   r<   )Nzoperator.isMappingType(x)z=import collections.abc
isinstance(x, collections.abc.Mapping)r=   r>   r   r   r   test_operator_isMappingTypeZ  rG   z)Test_operator.test_operator_isMappingTypec                 C   r<   )Nzoperator.isNumberType(x)z,import numbers
isinstance(x, numbers.Number)r=   r>   r   r   r   test_operator_isNumberType_  rG   z(Test_operator.test_operator_isNumberTypec                 C   rt   )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>   r   r   r   test_operator_repeatd  rv   z"Test_operator.test_operator_repeatc                 C   rt   )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>   r   r   r   test_operator_irepeatq  rv   z#Test_operator.test_operator_irepeatc                 C   r<   )NzisCallable(x)z"You should use 'callable(x)' here.r   r   r_   tr   r   r   test_bare_isCallable~  rG   z"Test_operator.test_bare_isCallablec                 C   r<   )NzsequenceIncludes(x, y)z.You should use 'operator.contains(x, y)' here.r   r  r   r   r   test_bare_sequenceIncludes  rG   z(Test_operator.test_bare_sequenceIncludesc                 C   r<   )NzisSequenceType(z)z>You should use 'isinstance(z, collections.abc.Sequence)' here.r   r  r   r   r   !test_bare_operator_isSequenceType  rG   z/Test_operator.test_bare_operator_isSequenceTypec                 C   r<   )NzisMappingType(x)z=You should use 'isinstance(x, collections.abc.Mapping)' here.r   r  r   r   r    test_bare_operator_isMappingType  rG   z.Test_operator.test_bare_operator_isMappingTypec                 C   r<   )NzisNumberType(y)z4You should use 'isinstance(y, numbers.Number)' here.r   r  r   r   r   test_bare_operator_isNumberType  rG   z-Test_operator.test_bare_operator_isNumberTypec                 C   r<   )Nzrepeat(x, n)z)You should use 'operator.mul(x, n)' here.r   r  r   r   r   test_bare_operator_repeat  rG   z'Test_operator.test_bare_operator_repeatc                 C   r<   )Nzirepeat(y, 187)z,You should use 'operator.imul(y, 187)' here.r   r  r   r   r   test_bare_operator_irepeat  rG   z(Test_operator.test_bare_operator_irepeatN)r7   r*   r8   r	   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r  ?  s     r  c                   @   r   )Test_exitfuncZexitfuncc                 C   r<   )NzI
            import sys
            sys.exitfunc = my_atexit
            ze
            import sys
            import atexit
            atexit.register(my_atexit)
            r=   r>   r   r   r   r     r  zTest_exitfunc.test_simplec                 C   r<   )NzO
            import sys, crumbs
            sys.exitfunc = my_func
            zY
            import sys, crumbs, atexit
            atexit.register(my_func)
            r=   r>   r   r   r   test_names_import  r   zTest_exitfunc.test_names_importc                 C   r<   )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>   r   r   r   test_complex_expression  r  z%Test_exitfunc.test_complex_expressionc                 C   rr   )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>   r   r   r   rZ    s   zTest_exitfunc.test_commentsc                 C   r<   )Nz]
            import sys
            def f():
                sys.exitfunc = func
            zz
            import sys
            import atexit
            def f():
                atexit.register(func)
             r=   r>   r   r   r   test_in_a_function  r  z Test_exitfunc.test_in_a_functionc                 C   s   d}d}d}|  ||| 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   r?   r@   msgr   r   r   test_no_sys_import  s   z Test_exitfunc.test_no_sys_importc                 C   r]   )Nzf(sys.exitfunc)r$   r^   r   r   r   rw     ra   zTest_exitfunc.test_unchangedN)r7   r*   r8   r	   r   r  r  rZ  r  r  rw   r   r   r   r   r    s    r  c                   @   r9   )	Test_assertsZassertsc                 C   s&   g d}|D ]
\}}|  || qd S )N))zself.assert_(True)self.assertTrue(True))zself.assertEquals(2, 2)self.assertEqual(2, 2))zself.assertNotEquals(2, 3)self.assertNotEqual(2, 3))zself.assertAlmostEquals(2, 3)self.assertAlmostEqual(2, 3))z self.assertNotAlmostEquals(2, 8)self.assertNotAlmostEqual(2, 8))zself.failUnlessEqual(2, 2)r  )zself.failIfEqual(2, 3)r  )z self.failUnlessAlmostEqual(2, 3)r  )zself.failIfAlmostEqual(2, 8)r  )zself.failUnless(True)r  )zself.failUnlessRaises(foo)zself.assertRaises(foo))zself.failIf(False)zself.assertFalse(False)r=   )r   Ztestsr?   r@   r   r   r   test_deprecated_names  s   z"Test_asserts.test_deprecated_namesc                 C   r@  )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>   r   r   r   test_variants  s*   zTest_asserts.test_variantsc                 C   r'  )Nzself.assertEqualsOnSaturdayz!self.assertEqualsOnSaturday(3, 5)r$   r   r   r   r   rw   '  r)  zTest_asserts.test_unchangedN)r7   r*   r8   r	   r  r  rw   r   r   r   r   r    s
    r  )Brl  rP  r   r  r   r   r   r   Zlib2to3.testsr   ZTestCaser   r:   rE   rR   ro   rx   r}   r   r   r   r   r   r   r   r   r   r   r  r.  r5  r;  rM  rQ  rc  rk  rn  rw  r  r  r  r  r  r  r  r  r  r  r  r  r  r#  rC  rF  rJ  rO  rW  ra  r  r  r  r  r  r  r  r  r   r   r   r   <module>   s    9: ;1#j3&  }.& gH/+br/ <    ]4B.Oh|P   Z=J %": &=cX