B
    18™\iQ  ã               @   sæ  d Z ddlmZ ddlmZmZ ddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlmZ ddlmZ dd	lmZ dd
lmZ G dd„ dejƒZG dd„ dejƒ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jƒZ(G d-d.„ d.eƒZ)d/d0„ Z*e+d1krâe ,¡  dS )2aF  Test suite for 2to3's parser and grammar files.

This is the place to add tests for changes to 2to3's grammar, such as those
merging the grammars for Python 2 and 3. In addition to specific tests for
parts of the grammar we've changed, we also make sure we can parse the
test_grammar.py files from both Python 2 and Python 3.
é   )Úsupport)ÚdriverÚdriver_no_print_statementé    N)r   )Útokenizeé   )Ú
ParseError)Úpython_symbolsc               @   s   e Zd Zdd„ ZdS )Ú
TestDriverc             C   sJ   d}t  |¡}|  |jd jd jtj¡ |  |jd jd jtj¡ d S )Nzprint 1
print 2
r   r   )r   Úparse_stringÚassertEqualÚchildrenÚtypeÚsymsÚ
print_stmt)ÚselfÚsÚt© r   ú]/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/lib2to3/tests/test_parser.pyÚtest_formfeed"   s    
zTestDriver.test_formfeedN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r
       s   r
   c               @   s>   e Zd Zdd„ Zdd„ Ze ejdkd¡dd„ ƒZ	d	d
„ Z
dS )ÚTestPgen2Cachingc             C   s   t jtjddd d S )NFT)ÚsaveÚforce)Úpgen2_driverÚload_grammarr   Úgrammar_path)r   r   r   r   Útest_load_grammar_from_txt_file*   s    z0TestPgen2Caching.test_load_grammar_from_txt_filec          	   C   sŠ   t  ¡ }zptj |tj tj¡¡}t 	tj|¡ t
 |¡}t
j|ddd |  tj |¡¡ t |¡ t
j|ddd W d t |¡ X d S )NT)r   r   F)ÚtempfileÚmkdtempÚosÚpathÚjoinÚbasenamer   r   ÚshutilÚcopyr   Ú_generate_pickle_namer   Ú
assertTrueÚexistsÚunlinkÚrmtree)r   ÚtmpdirÚgrammar_copyÚpickle_namer   r   r   Útest_load_grammar_from_pickle-   s    

z.TestPgen2Caching.test_load_grammar_from_pickleNzsys.executable requiredc          
   C   sD  t  ¡ }tj |d¡}zt |¡ tj tj¡}tj ||¡}tj ||¡}t	 
tj|¡ t	 
tj|¡ t |¡}t |¡}|  ||¡ tj|ddd |  tj |¡¡ ttjƒ}d|d< tjtjdd|f g|d |  tj |¡¡ t|d	ƒ4}	t|d	ƒ}
| j|	 ¡ |
 ¡ d
d W d Q R X W d Q R X W d t	 |¡ X d S )NÚsubdirT)r   r   ÚrandomZPYTHONHASHSEEDz-cz{
from lib2to3.pgen2 import driver as pgen2_driver
pgen2_driver.load_grammar(%r, save=True, force=True)
                    )ÚenvÚrbzGGrammar caches generated using different hash seeds were not identical.)Úmsg)r!   r"   r#   r$   r%   Úmkdirr&   r   r   r'   r(   r   r)   ÚassertNotEqualr   r*   r+   ÚdictÚenvironÚ
subprocessÚ
check_callÚsysÚ
executableÚopenr   Úreadr-   )r   r.   Z	tmpsubdirZgrammar_baser/   Zgrammar_sub_copyr0   Zpickle_sub_nameZsub_envZ
pickle_f_1Z
pickle_f_2r   r   r   Ú!test_load_grammar_from_subprocess?   s8    



 z2TestPgen2Caching.test_load_grammar_from_subprocessc                sf   t d ‰G dd„ dƒ‰ G ‡ ‡fdd„dƒ}|ƒ tjˆ< |  tjtjˆ¡ t ˆd¡}|  |j	d¡ d S )Nz
.load_testc               @   s   e Zd Zdd„ ZdS )z=TestPgen2Caching.test_load_packaged_grammar.<locals>.MyLoaderc             S   s   t  ddi¡S )NÚelephanté   )ÚpickleÚdumps)r   Úwherer   r   r   Úget_datak   s    zFTestPgen2Caching.test_load_packaged_grammar.<locals>.MyLoader.get_dataN)r   r   r   rG   r   r   r   r   ÚMyLoaderj   s   rH   c                   s    e Zd ZdZej ”” ƒ ¡ZdS )z=TestPgen2Caching.test_load_packaged_grammar.<locals>.MyModuleZparsertestmoduleN)r   r   r   Ú__file__Ú	importlibÚutilÚspec_from_loaderÚ__spec__r   )rH   Úmodnamer   r   ÚMyModulem   s   rO   zGrammar.txtrC   )
r   r=   ÚmodulesÚ
addCleanupÚoperatorÚdelitemr   Úload_packaged_grammarr   rB   )r   rO   Úgr   )rH   rN   r   Útest_load_packaged_grammarh   s    z+TestPgen2Caching.test_load_packaged_grammar)r   r   r   r    r1   ÚunittestÚskipIfr=   r>   rA   rV   r   r   r   r   r   )   s   )r   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚGrammarTestc             C   s   t  |¡ d S )N)r   r   )r   Úcoder   r   r   Úvalidatew   s    zGrammarTest.validatec             C   s0   y|   |¡ W n tk
r"   Y n
X tdƒ‚d S )Nz Syntax shouldn't have been valid)r[   r   ÚAssertionError)r   rZ   r   r   r   Úinvalid_syntaxz   s
    zGrammarTest.invalid_syntaxN)r   r   r   r[   r]   r   r   r   r   rY   v   s   rY   c               @   s   e Zd Zdd„ ZdS )ÚTestMatrixMultiplicationc             C   s   |   d¡ |   d¡ d S )Nza @ bza @= b)r[   )r   r   r   r   Ú#test_matrix_multiplication_operator„   s    
z<TestMatrixMultiplication.test_matrix_multiplication_operatorN)r   r   r   r_   r   r   r   r   r^   ƒ   s   r^   c               @   s   e Zd Zdd„ ZdS )ÚTestYieldFromc             C   s"   |   d¡ |   d¡ |  d¡ d S )Nzyield from xz(yield from x) + yz
yield from)r[   r]   )r   r   r   r   Útest_yield_fromŠ   s    

zTestYieldFrom.test_yield_fromN)r   r   r   ra   r   r   r   r   r`   ‰   s   r`   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestAsyncAwaitc             C   sr   |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |  d	¡ |  d
¡ |  d¡ d S )NzLasync def foo():
                             await x
                      zYasync def foo():
                             [i async for i in b]
                      z¼async def foo():
                             {i for i in b
                                async for i in a if await i
                                  for b in i}
                      zdasync def foo():
                             [await i for i in b if await c]
                      zYasync def foo():
                             [ i for i in b if c]
                      zhasync def foo():

            def foo(): pass

            def foo(): pass

            await x
        zasync def foo(): return await azTdef foo():
            def foo(): pass
            async def foo(): await x
        zawait xz5def foo():
                                   await xzedef foo():
            def foo(): pass
            async def foo(): pass
            await x
        )r[   r]   )r   r   r   r   Útest_await_expr‘   s(    

zTestAsyncAwait.test_await_exprc             C   s"   |   d¡ |   d¡ |   d¡ d S )Nz	async = 1z	await = 1zdef async(): pass)r[   )r   r   r   r   Útest_async_varÂ   s    

zTestAsyncAwait.test_async_varc             C   s   |   d¡ |  d¡ d S )NzDasync def foo():
                             async for a in b: passzDdef foo():
                                   async for a in b: pass)r[   r]   )r   r   r   r   Útest_async_withÇ   s    zTestAsyncAwait.test_async_withc             C   s   |   d¡ |  d¡ d S )Nz@async def foo():
                             async with a: passz@def foo():
                                   async with a: pass)r[   r]   )r   r   r   r   Útest_async_forÎ   s    zTestAsyncAwait.test_async_forN)r   r   r   rc   rd   re   rf   r   r   r   r   rb      s   1rb   c               @   sT   e 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 )ÚTestRaiseChangesc             C   s   |   d¡ d S )NÚraise)r[   )r   r   r   r   Útest_2x_style_1×   s    z TestRaiseChanges.test_2x_style_1c             C   s   |   d¡ d S )Nz
raise E, V)r[   )r   r   r   r   Útest_2x_style_2Ú   s    z TestRaiseChanges.test_2x_style_2c             C   s   |   d¡ d S )Nzraise E, V, T)r[   )r   r   r   r   Útest_2x_style_3Ý   s    z TestRaiseChanges.test_2x_style_3c             C   s   |   d¡ d S )Nzraise E, V, T, Z)r]   )r   r   r   r   Útest_2x_style_invalid_1à   s    z(TestRaiseChanges.test_2x_style_invalid_1c             C   s   |   d¡ d S )Nzraise E1 from E2)r[   )r   r   r   r   Útest_3x_styleã   s    zTestRaiseChanges.test_3x_stylec             C   s   |   d¡ d S )Nzraise E, V from E1)r]   )r   r   r   r   Útest_3x_style_invalid_1æ   s    z(TestRaiseChanges.test_3x_style_invalid_1c             C   s   |   d¡ d S )Nzraise E from E1, E2)r]   )r   r   r   r   Útest_3x_style_invalid_2é   s    z(TestRaiseChanges.test_3x_style_invalid_2c             C   s   |   d¡ d S )Nzraise from E1, E2)r]   )r   r   r   r   Útest_3x_style_invalid_3ì   s    z(TestRaiseChanges.test_3x_style_invalid_3c             C   s   |   d¡ d S )Nzraise E from)r]   )r   r   r   r   Útest_3x_style_invalid_4ï   s    z(TestRaiseChanges.test_3x_style_invalid_4N)r   r   r   ri   rj   rk   rl   rm   rn   ro   rp   rq   r   r   r   r   rg   Ö   s   rg   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d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9S ):ÚTestUnpackingGeneralizationsc             C   s   |   d¡ d S )Nzfunc(1, *(2, 3), 4))r[   )r   r   r   r   Útest_mid_positional_star÷   s    z5TestUnpackingGeneralizations.test_mid_positional_starc             C   s   |   d¡ d S )Nz,func(**{'eggs':'scrambled', 'spam':'fried'}))r[   )r   r   r   r   Útest_double_star_dict_literalú   s    z:TestUnpackingGeneralizations.test_double_star_dict_literalc             C   s   |   d¡ d S )Nz*func(spam='fried', **{'eggs':'scrambled'}))r[   )r   r   r   r   Ú,test_double_star_dict_literal_after_keywordsý   s    zITestUnpackingGeneralizations.test_double_star_dict_literal_after_keywordsc             C   s   |   d¡ d S )Nz[*{2}, 3, *[4]])r[   )r   r   r   r   Útest_list_display   s    z.TestUnpackingGeneralizations.test_list_displayc             C   s   |   d¡ d S )Nz{*{2}, 3, *[4]})r[   )r   r   r   r   Útest_set_display  s    z-TestUnpackingGeneralizations.test_set_displayc             C   s   |   d¡ d S )Nz{**{}})r[   )r   r   r   r   Útest_dict_display_1  s    z0TestUnpackingGeneralizations.test_dict_display_1c             C   s   |   d¡ d S )Nz{**{}, 3:4, **{5:6, 7:8}})r[   )r   r   r   r   Útest_dict_display_2	  s    z0TestUnpackingGeneralizations.test_dict_display_2c             C   s   |   d¡ d S )Nzf(a, *b, *c, d))r[   )r   r   r   r   Útest_argument_unpacking_1  s    z6TestUnpackingGeneralizations.test_argument_unpacking_1c             C   s   |   d¡ d S )Nzf(**a, **b))r[   )r   r   r   r   Útest_argument_unpacking_2  s    z6TestUnpackingGeneralizations.test_argument_unpacking_2c             C   s   |   d¡ d S )Nzf(2, *a, *b, **b, **c, **d))r[   )r   r   r   r   Útest_argument_unpacking_3  s    z6TestUnpackingGeneralizations.test_argument_unpacking_3c             C   s   |   d¡ |   d¡ d S )Nzdef f(a, b): call(a, b)zdef f(a, b,): call(a, b,))r[   )r   r   r   r   Útest_trailing_commas_1  s    
z3TestUnpackingGeneralizations.test_trailing_commas_1c             C   s   |   d¡ |   d¡ d S )Nzdef f(a, *b): call(a, *b)zdef f(a, *b,): call(a, *b,))r[   )r   r   r   r   Útest_trailing_commas_2  s    
z3TestUnpackingGeneralizations.test_trailing_commas_2c             C   s   |   d¡ |   d¡ d S )Nzdef f(a, b=1): call(a, b=1)zdef f(a, b=1,): call(a, b=1,))r[   )r   r   r   r   Útest_trailing_commas_3  s    
z3TestUnpackingGeneralizations.test_trailing_commas_3c             C   s   |   d¡ |   d¡ d S )Nzdef f(a, **b): call(a, **b)zdef f(a, **b,): call(a, **b,))r[   )r   r   r   r   Útest_trailing_commas_4!  s    
z3TestUnpackingGeneralizations.test_trailing_commas_4c             C   s   |   d¡ |   d¡ d S )Nzdef f(*a, b=1): call(*a, b=1)zdef f(*a, b=1,): call(*a, b=1,))r[   )r   r   r   r   Útest_trailing_commas_5%  s    
z3TestUnpackingGeneralizations.test_trailing_commas_5c             C   s   |   d¡ |   d¡ d S )Nzdef f(*a, **b): call(*a, **b)zdef f(*a, **b,): call(*a, **b,))r[   )r   r   r   r   Útest_trailing_commas_6)  s    
z3TestUnpackingGeneralizations.test_trailing_commas_6c             C   s   |   d¡ |   d¡ d S )Nzdef f(*, b=1): call(*b)zdef f(*, b=1,): call(*b,))r[   )r   r   r   r   Útest_trailing_commas_7-  s    
z3TestUnpackingGeneralizations.test_trailing_commas_7c             C   s   |   d¡ |   d¡ d S )Nzdef f(a=1, b=2): call(a=1, b=2)z!def f(a=1, b=2,): call(a=1, b=2,))r[   )r   r   r   r   Útest_trailing_commas_81  s    
z3TestUnpackingGeneralizations.test_trailing_commas_8c             C   s   |   d¡ |   d¡ d S )Nzdef f(a=1, **b): call(a=1, **b)z!def f(a=1, **b,): call(a=1, **b,))r[   )r   r   r   r   Útest_trailing_commas_95  s    
z3TestUnpackingGeneralizations.test_trailing_commas_9c             C   s   |   d¡ |   d¡ d S )Nzf = lambda a, b: call(a, b)zf = lambda a, b,: call(a, b,))r[   )r   r   r   r   Útest_trailing_commas_lambda_19  s    
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_1c             C   s   |   d¡ |   d¡ d S )Nzf = lambda a, *b: call(a, *b)zf = lambda a, *b,: call(a, *b,))r[   )r   r   r   r   Útest_trailing_commas_lambda_2=  s    
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_2c             C   s   |   d¡ |   d¡ d S )Nzf = lambda a, b=1: call(a, b=1)z!f = lambda a, b=1,: call(a, b=1,))r[   )r   r   r   r   Útest_trailing_commas_lambda_3A  s    
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_3c             C   s   |   d¡ |   d¡ d S )Nzf = lambda a, **b: call(a, **b)z!f = lambda a, **b,: call(a, **b,))r[   )r   r   r   r   Útest_trailing_commas_lambda_4E  s    
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_4c             C   s   |   d¡ |   d¡ d S )Nz!f = lambda *a, b=1: call(*a, b=1)z#f = lambda *a, b=1,: call(*a, b=1,))r[   )r   r   r   r   Útest_trailing_commas_lambda_5I  s    
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_5c             C   s   |   d¡ |   d¡ d S )Nz!f = lambda *a, **b: call(*a, **b)z#f = lambda *a, **b,: call(*a, **b,))r[   )r   r   r   r   Útest_trailing_commas_lambda_6M  s    
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_6c             C   s   |   d¡ |   d¡ d S )Nzf = lambda *, b=1: call(*b)zf = lambda *, b=1,: call(*b,))r[   )r   r   r   r   Útest_trailing_commas_lambda_7Q  s    
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_7c             C   s   |   d¡ |   d¡ d S )Nz#f = lambda a=1, b=2: call(a=1, b=2)z%f = lambda a=1, b=2,: call(a=1, b=2,))r[   )r   r   r   r   Útest_trailing_commas_lambda_8U  s    
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_8c             C   s   |   d¡ |   d¡ d S )Nz#f = lambda a=1, **b: call(a=1, **b)z%f = lambda a=1, **b,: call(a=1, **b,))r[   )r   r   r   r   Útest_trailing_commas_lambda_9Y  s    
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_9N)r   r   r   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r€   r   r‚   rƒ   r„   r…   r†   r‡   rˆ   r‰   rŠ   r‹   rŒ   r   rŽ   r   r   r   r   rr   ö   s8   rr   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d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd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 ),ÚTestFunctionAnnotationsc             C   s   |   d¡ d S )Nzdef f(x) -> list: pass)r[   )r   r   r   r   Útest_1`  s    zTestFunctionAnnotations.test_1c             C   s   |   d¡ d S )Nzdef f(x:int): pass)r[   )r   r   r   r   Útest_2c  s    zTestFunctionAnnotations.test_2c             C   s   |   d¡ d S )Nzdef f(*x:str): pass)r[   )r   r   r   r   Útest_3f  s    zTestFunctionAnnotations.test_3c             C   s   |   d¡ d S )Nzdef f(**x:float): pass)r[   )r   r   r   r   Útest_4i  s    zTestFunctionAnnotations.test_4c             C   s   |   d¡ d S )Nzdef f(x, y:1+2): pass)r[   )r   r   r   r   Útest_5l  s    zTestFunctionAnnotations.test_5c             C   s   |   d¡ d S )Nzdef f(a, (b:1, c:2, d)): pass)r[   )r   r   r   r   Útest_6o  s    zTestFunctionAnnotations.test_6c             C   s   |   d¡ d S )Nz/def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6): pass)r[   )r   r   r   r   Útest_7r  s    zTestFunctionAnnotations.test_7c             C   s   d}|   |¡ d S )Nzgdef f(a, (b:1, c:2, d), e:3=4, f=5,
                        *g:6, h:7, i=8, j:9=10, **k:11) -> 12: pass)r[   )r   r   r   r   r   Útest_8u  s    zTestFunctionAnnotations.test_8c             C   s   d}|   |¡ d S )Nzšdef f(
          a: str,
          b: int,
          *,
          c: bool = False,
          **kwargs,
        ) -> None:
            call(c=c, **kwargs,))r[   )r   r   r   r   r   Útest_9z  s    zTestFunctionAnnotations.test_9c             C   s   d}|   |¡ d S )Nz@def f(
          a: str,
        ) -> None:
            call(a,))r[   )r   r   r   r   r   Útest_10…  s    zTestFunctionAnnotations.test_10c             C   s   d}|   |¡ d S )NzGdef f(
          a: str = '',
        ) -> None:
            call(a=a,))r[   )r   r   r   r   r   Útest_11Œ  s    zTestFunctionAnnotations.test_11c             C   s   d}|   |¡ d S )NzHdef f(
          *args: str,
        ) -> None:
            call(*args,))r[   )r   r   r   r   r   Útest_12“  s    zTestFunctionAnnotations.test_12c             C   s   |   d¡ |   d¡ d S )Nz)def f(a: str, b: int) -> None: call(a, b)z+def f(a: str, b: int,) -> None: call(a, b,))r[   )r   r   r   r   Útest_13š  s    
zTestFunctionAnnotations.test_13c             C   s   |   d¡ |   d¡ d S )Nz+def f(a: str, *b: int) -> None: call(a, *b)z-def f(a: str, *b: int,) -> None: call(a, *b,))r[   )r   r   r   r   Útest_14ž  s    
zTestFunctionAnnotations.test_14c             C   s   |   d¡ |   d¡ d S )Nz-def f(a: str, b: int=1) -> None: call(a, b=1)z/def f(a: str, b: int=1,) -> None: call(a, b=1,))r[   )r   r   r   r   Útest_15¢  s    
zTestFunctionAnnotations.test_15c             C   s   |   d¡ |   d¡ d S )Nz-def f(a: str, **b: int) -> None: call(a, **b)z/def f(a: str, **b: int,) -> None: call(a, **b,))r[   )r   r   r   r   Útest_16¦  s    
zTestFunctionAnnotations.test_16c             C   s   |   d¡ |   d¡ d S )Nz/def f(*a: str, b: int=1) -> None: call(*a, b=1)z1def f(*a: str, b: int=1,) -> None: call(*a, b=1,))r[   )r   r   r   r   Útest_17ª  s    
zTestFunctionAnnotations.test_17c             C   s   |   d¡ |   d¡ d S )Nz/def f(*a: str, **b: int) -> None: call(*a, **b)z1def f(*a: str, **b: int,) -> None: call(*a, **b,))r[   )r   r   r   r   Útest_18®  s    
zTestFunctionAnnotations.test_18c             C   s   |   d¡ |   d¡ d S )Nz$def f(*, b: int=1) -> None: call(*b)z&def f(*, b: int=1,) -> None: call(*b,))r[   )r   r   r   r   Útest_19²  s    
zTestFunctionAnnotations.test_19c             C   s   |   d¡ |   d¡ d S )Nz2def f(a: str='', b: int=2) -> None: call(a=a, b=2)z4def f(a: str='', b: int=2,) -> None: call(a=a, b=2,))r[   )r   r   r   r   Útest_20¶  s    
zTestFunctionAnnotations.test_20c             C   s   |   d¡ |   d¡ d S )Nz2def f(a: str='', **b: int) -> None: call(a=a, **b)z4def f(a: str='', **b: int,) -> None: call(a=a, **b,))r[   )r   r   r   r   Útest_21º  s    
zTestFunctionAnnotations.test_21N)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               @   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 )ÚTestVarAnnotationsc             C   s   |   d¡ d S )Nzvar1: int = 5)r[   )r   r   r   r   r   Á  s    zTestVarAnnotations.test_1c             C   s   |   d¡ d S )Nzvar2: [int, str])r[   )r   r   r   r   r‘   Ä  s    zTestVarAnnotations.test_2c             C   s   |   d¡ d S )NzCdef f():
    st: str = 'Hello'
    a.b: int = (1, 2)
    return st
)r[   )r   r   r   r   r’   Ç  s    zTestVarAnnotations.test_3c             C   s   |   d¡ d S )Nz$def fbad():
    x: int
    print(x)
)r[   )r   r   r   r   r“   Í  s    zTestVarAnnotations.test_4c             C   s   |   d¡ d S )Nzeclass C:
    x: int
    s: str = 'attr'
    z = 2
    def __init__(self, x):
        self.x: int = x
)r[   )r   r   r   r   r”   Ò  s    zTestVarAnnotations.test_5c             C   s   |   d¡ d S )Nzlst: List[int] = [])r[   )r   r   r   r   r•   Ú  s    zTestVarAnnotations.test_6N)	r   r   r   r   r‘   r’   r“   r”   r•   r   r   r   r   r¥   À  s   r¥   c               @   s   e Zd Zdd„ Zdd„ ZdS )Ú
TestExceptc             C   s   d}|   |¡ d S )NzP
            try:
                x
            except E as N:
                y)r[   )r   r   r   r   r   Útest_newß  s    zTestExcept.test_newc             C   s   d}|   |¡ d S )NzN
            try:
                x
            except E, N:
                y)r[   )r   r   r   r   r   Útest_oldç  s    zTestExcept.test_oldN)r   r   r   r§   r¨   r   r   r   r   r¦   Þ  s   r¦   c               @   s   e Zd ZdZdd„ ZdS )ÚTestStringLiterals)*ú'ú"zr'zr"zR'zR"zu'zu"zU'zU"zb'zb"zB'zB"zf'zf"zF'zF"zur'zur"zUr'zUr"zuR'zuR"zUR'zUR"zbr'zbr"zBr'zBr"zbR'zbR"zBR'zBR"zrb'zrb"zRb'zRb"zrB'zrB"zRB'zRB"c             C   sL   xF| j D ]<}dj||d d}|  |¡ dj||d d}|  |¡ qW d S )Nz{p}spamspamspam{s}éÿÿÿÿ)Úpr   z{p}{s}{s}eggs{s}{s}{s})ÚprefixesÚformatr[   )r   ÚpreÚsingleÚtripler   r   r   Útest_litý  s
    
zTestStringLiterals.test_litN)r   r   r   r®   r³   r   r   r   r   r©   ð  s   r©   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestSetLiteralc             C   s   |   d¡ d S )Nzx = {'one'})r[   )r   r   r   r   r     s    zTestSetLiteral.test_1c             C   s   |   d¡ d S )Nzx = {'one', 1,})r[   )r   r   r   r   r‘   
  s    zTestSetLiteral.test_2c             C   s   |   d¡ d S )Nzx = {'one', 'two', 'three'})r[   )r   r   r   r   r’     s    zTestSetLiteral.test_3c             C   s   |   d¡ d S )Nzx = {2, 3, 4,})r[   )r   r   r   r   r“     s    zTestSetLiteral.test_4N)r   r   r   r   r‘   r’   r“   r   r   r   r   r´     s   r´   c               @   s   e Zd Zdd„ ZdS )ÚTestIdentfierc             C   s,   |   d¡ |   d¡ |   d¡ |   d¡ d S )Nu!   Ã–rter = 'places'
grÃ¼n = 'green'u   èŸ’ = aèŸ’ = é”¦è›‡ = 1u   Âµ = aÂµ = ÂµÂµ = 1uA   ð”˜ð”«ð”¦ð” ð”¬ð”¡ð”¢ = a_ð”˜ð”«ð”¦ð” ð”¬ð”¡ð”¢ = 1)r[   )r   r   r   r   Útest_non_ascii_identifiers  s    


z(TestIdentfier.test_non_ascii_identifiersN)r   r   r   r¶   r   r   r   r   rµ     s   rµ   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚTestNumericLiteralsc             C   s   |   d¡ |  d¡ d S )NZ0o7777777777777Z0o7324528887)r[   r]   )r   r   r   r   Útest_new_octal_notation  s    
z+TestNumericLiterals.test_new_octal_notationc             C   s   |   d¡ |  d¡ d S )NZ0b101010Z	0b0101021)r[   r]   )r   r   r   r   Útest_new_binary_notation#  s    
z,TestNumericLiterals.test_new_binary_notationN)r   r   r   r¸   r¹   r   r   r   r   r·     s   r·   c               @   s   e Zd Zdd„ ZdS )ÚTestClassDefc             C   s6   |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ d S )Nzclass B(t=7): passzclass B(t, *args): passzclass B(t, **kwargs): passz!class B(t, *args, **kwargs): passz'class B(t, y=9, *args, **kwargs,): pass)r[   )r   r   r   r   Útest_new_syntax)  s
    



zTestClassDef.test_new_syntaxN)r   r   r   r»   r   r   r   r   rº   (  s   rº   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestParserIdempotencyz,A cut-down version of pytree_idempotency.py.c             C   s  xþt  ¡ D ]ò}t|dƒ}t |j¡d }W d Q R X |  |d| ¡ t|d|d}| ¡ }W d Q R X yt 	|¡}W nX t
k
rÌ   yt 	|¡}W n4 t
k
rÆ } z|  d||f ¡ W d d }~X Y nX Y nX t|ƒ}||kr
tt|||ƒƒ |  d| ¡ q
W d S )Nr5   r   zcan't detect encoding for %sÚr)ÚencodingzParseError on file %s (%s)zIdempotency failed: %s)r   Úall_project_filesr?   r   Údetect_encodingÚreadlineÚassertIsNotNoner@   r   r   r   r   ÚfailÚstrÚprintÚ
diff_texts)r   ÚfilepathÚfpr¾   ÚsourceÚtreeÚerrÚnewr   r   r   Útest_all_project_files5  s$    
*z,TestParserIdempotency.test_all_project_filesc             C   s,   t  d¡ t  d¡ t  d¡ t  d¡ d S )Nza, *b, c = x
z[*a, b] = x
z(z, *y, w) = m
zfor *z, m in d: pass
)r   r   )r   r   r   r   Útest_extended_unpackingI  s    


z-TestParserIdempotency.test_extended_unpackingN)r   r   r   Ú__doc__rÍ   rÎ   r   r   r   r   r¼   1  s   r¼   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTestLiteralsc             C   s   t  t |¡d ¡ d S )Nz

)r   r   r   Údedent)r   r   r   r   r   r[   R  s    zTestLiterals.validatec             C   s   d}|   |¡ d S )Nuâ   
            md5test(b"Âª" * 80,
                    (b"Test Using Larger Than Block-Size Key "
                     b"and Larger Than One Block-Size Data"),
                    "6f630fad67cda0ee1fb1f562db3aa53e")
            )r[   )r   r   r   r   r   Útest_multiline_bytes_literalsU  s    z*TestLiterals.test_multiline_bytes_literalsc             C   s   d}|   |¡ d S )Nz¬
            b"""
            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN">
            """
            )r[   )r   r   r   r   r   Ú'test_multiline_bytes_tripquote_literals^  s    z4TestLiterals.test_multiline_bytes_tripquote_literalsc             C   s   d}|   |¡ d S )Nuß   
            md5test("Âª" * 80,
                    ("Test Using Larger Than Block-Size Key "
                     "and Larger Than One Block-Size Data"),
                    "6f630fad67cda0ee1fb1f562db3aa53e")
            )r[   )r   r   r   r   r   Útest_multiline_str_literalsg  s    z(TestLiterals.test_multiline_str_literalsN)r   r   r   r[   rÒ   rÓ   rÔ   r   r   r   r   rÐ   P  s   		rÐ   c          	   C   s(   |   ¡ } |  ¡ }tj| |||ddddS )Nz
(original)z(reserialized)Ú )Úlineterm)Ú
splitlinesÚdifflibÚunified_diff)ÚaÚbÚfilenamer   r   r   rÆ   q  s
    rÆ   Ú__main__)-rÏ   rÕ   r   r   r   rØ   rJ   rR   r#   rD   r'   r;   r=   r!   rW   Zlib2to3.pgen2r   r   Zpgen2.parser   Zlib2to3.pygramr	   r   ÚTestCaser
   r   rY   r^   r`   rb   rg   rr   r   r¥   r¦   r©   r´   rµ   r·   rº   r¼   rÐ   rÆ   r   Úmainr   r   r   r   Ú<module>   sJ   	MF ia
	!
