B
    Ç S]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ÚassertEqualZchildrenÚtypeÚsymsZ
print_stmt)ÚselfÚsÚt© r   ú*lib/python3.7/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 )NZsubdirT)r   r   Z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'   ZassertNotEqualr   r(   r)   ÚdictÚenvironÚ
subprocessZ
check_callÚsysÚ
executableÚopenr   Úreadr+   )r   r,   Z	tmpsubdirZgrammar_baser-   Zgrammar_sub_copyr.   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   rA   r   r   r   r   ÚMyLoaderj   s   rB   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   )rB   Úmodnamer   r   ÚMyModulem   s   rI   zGrammar.txtr=   )
r   r7   ÚmodulesZ
addCleanupÚoperatorÚdelitemr   Zload_packaged_grammarr   r<   )r   rI   Úgr   )rB   rH   r   Útest_load_packaged_grammarh   s    z+TestPgen2Caching.test_load_packaged_grammar)r   r   r   r   r/   ÚunittestZskipIfr7   r8   r;   rN   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)rR   r   ÚAssertionError)r   rQ   r   r   r   Úinvalid_syntaxz   s
    zGrammarTest.invalid_syntaxN)r   r   r   rR   rT   r   r   r   r   rP   v   s   rP   c               @   s   e Zd Zdd„ ZdS )ÚTestMatrixMultiplicationc             C   s   |   d¡ |   d¡ d S )Nza @ bza @= b)rR   )r   r   r   r   Ú#test_matrix_multiplication_operator„   s    
z<TestMatrixMultiplication.test_matrix_multiplication_operatorN)r   r   r   rV   r   r   r   r   rU   ƒ   s   rU   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)rR   rT   )r   r   r   r   Útest_yield_fromŠ   s    

zTestYieldFrom.test_yield_fromN)r   r   r   rX   r   r   r   r   rW   ‰   s   rW   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
        )rR   rT   )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)rR   )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)rR   rT   )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)rR   rT   )r   r   r   r   Útest_async_forÎ   s    zTestAsyncAwait.test_async_forN)r   r   r   rZ   r[   r\   r]   r   r   r   r   rY      s   1rY   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)rR   )r   r   r   r   Útest_2x_style_1×   s    z TestRaiseChanges.test_2x_style_1c             C   s   |   d¡ d S )Nz
raise E, V)rR   )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)rR   )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)rT   )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)rR   )r   r   r   r   Útest_3x_styleã   s    zTestRaiseChanges.test_3x_stylec             C   s   |   d¡ d S )Nzraise E, V from E1)rT   )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)rT   )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)rT   )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)rT   )r   r   r   r   Útest_3x_style_invalid_4ï   s    z(TestRaiseChanges.test_3x_style_invalid_4N)r   r   r   r`   ra   rb   rc   rd   re   rf   rg   rh   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d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd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))rR   )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'}))rR   )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'}))rR   )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]])rR   )r   r   r   r   Útest_list_display   s    z.TestUnpackingGeneralizations.test_list_displayc             C   s   |   d¡ d S )Nz{*{2}, 3, *[4]})rR   )r   r   r   r   Útest_set_display  s    z-TestUnpackingGeneralizations.test_set_displayc             C   s   |   d¡ d S )Nz{**{}})rR   )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}})rR   )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))rR   )r   r   r   r   Útest_argument_unpacking_1  s    z6TestUnpackingGeneralizations.test_argument_unpacking_1c             C   s   |   d¡ d S )Nzf(**a, **b))rR   )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))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )r   r   r   r   Útest_trailing_commas_lambda_9Y  s    
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_9N)r   r   r   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r€   r   r‚   rƒ   r„   r…   r   r   r   r   ri   ö   s8   ri   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)rR   )r   r   r   r   Útest_1`  s    zTestFunctionAnnotations.test_1c             C   s   |   d¡ d S )Nzdef f(x:int): pass)rR   )r   r   r   r   Útest_2c  s    zTestFunctionAnnotations.test_2c             C   s   |   d¡ d S )Nzdef f(*x:str): pass)rR   )r   r   r   r   Útest_3f  s    zTestFunctionAnnotations.test_3c             C   s   |   d¡ d S )Nzdef f(**x:float): pass)rR   )r   r   r   r   Útest_4i  s    zTestFunctionAnnotations.test_4c             C   s   |   d¡ d S )Nzdef f(x, y:1+2): pass)rR   )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)rR   )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)rR   )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)rR   )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,))rR   )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,))rR   )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,))rR   )r   r   r   r   r   Útest_11Œ  s    zTestFunctionAnnotations.test_11c             C   s   d}|   |¡ d S )NzHdef f(
          *args: str,
        ) -> None:
            call(*args,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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,))rR   )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)rR   )r   r   r   r   r‡   Á  s    zTestVarAnnotations.test_1c             C   s   |   d¡ d S )Nzvar2: [int, str])rR   )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
)rR   )r   r   r   r   r‰   Ç  s    zTestVarAnnotations.test_3c             C   s   |   d¡ d S )Nz$def fbad():
    x: int
    print(x)
)rR   )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
)rR   )r   r   r   r   r‹   Ò  s    zTestVarAnnotations.test_5c             C   s   |   d¡ d S )Nzlst: List[int] = [])rR   )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)rR   )r   r   r   r   r   Útest_newß  s    zTestExcept.test_newc             C   s   d}|   |¡ d S )NzN
            try:
                x
            except E, N:
                y)rR   )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ÚformatrR   )r   ZpreZsingleZ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'})rR   )r   r   r   r   r‡     s    zTestSetLiteral.test_1c             C   s   |   d¡ d S )Nzx = {'one', 1,})rR   )r   r   r   r   rˆ   
  s    zTestSetLiteral.test_2c             C   s   |   d¡ d S )Nzx = {'one', 'two', 'three'})rR   )r   r   r   r   r‰     s    zTestSetLiteral.test_3c             C   s   |   d¡ d S )Nzx = {2, 3, 4,})rR   )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)rR   )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)rR   rT   )r   r   r   r   Útest_new_octal_notation  s    
z+TestNumericLiterals.test_new_octal_notationc             C   s   |   d¡ |  d¡ d S )NZ0b101010Z	0b0101021)rR   rT   )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)rR   )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 )Nr1   r   zcan't detect encoding for %sÚr)ÚencodingzParseError on file %s (%s)zIdempotency failed: %s)r   Zall_project_filesr9   r   Údetect_encodingÚreadlineZassertIsNotNoner:   r   r   r   r   ZfailÚstrÚprintÚ
diff_texts)r   ÚfilepathÚfpr²   ÚsourceZ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   rR   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")
            )rR   )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">
            """
            )rR   )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")
            )rR   )r   r   r   r   r   Útest_multiline_str_literalsg  s    z(TestLiterals.test_multiline_str_literalsN)r   r   r   rR   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)Ú )Zlineterm)Ú
splitlinesÚdifflibZunified_diff)ÚaÚbÚfilenamer   r   r   r·   q  s
    r·   Ú__main__)-r¿   rÅ   r   r   r   rÇ   rD   rK   r!   r>   r%   r6   r7   r   rO   Zlib2to3.pgen2r   r   Zpgen2.parser   Zlib2to3.pygramr	   r   ZTestCaser
   r   rP   rU   rW   rY   r^   ri   r†   rœ   r   r    r¨   r©   r«   r®   r°   rÀ   r·   r   Úmainr   r   r   r   Ú<module>   sJ   	MF ia
	!
