a
    e[                     @   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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+G d/d0 d0eZ,G d1d2 d2eZ-G d3d4 d4ejZ.d5d6 Z/e0d7kre1  dS )8aF  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.9/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u ddd Z	d	d
 Z
dS )TestPgen2Cachingc                 C   s   t jtjddd d S )NFTZsaveZ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  }zztj|tjtj}t	tj| t
|}t
j|ddd | tj| t| t
j|ddd W t| nt| 0 d S )NTr   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   sz  t  }tj|d}zPt| 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	T}	t|d	(}
| j|	 |
 d
d W d    n1 s20    Y  W d    n1 sR0    Y  W t	| nt	| 0 d S )NZsubdirTr   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@   sD    


H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_datal   s    zFTestPgen2Caching.test_load_packaged_grammar.<locals>.MyLoader.get_dataN)r   r   r   rA   r   r   r   r   MyLoaderk   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   MyModulen   s   rJ   zGrammar.txtr=   )
r   r7   modulesZ
addCleanupoperatordelitemr   Zload_packaged_grammarr   r<   )r   rJ   gr   rH   r   test_load_packaged_grammari   s    z+TestPgen2Caching.test_load_packaged_grammar)r   r   r   r   r/   unittestZskipIfr7   r8   r;   rO   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   validatex   s    zGrammarTest.validatec                 C   s.   z|  | W n ty    Y n
0 tdd S )Nz Syntax shouldn't have been valid)rT   r   AssertionErrorrR   r   r   r   invalid_syntax{   s
    zGrammarTest.invalid_syntaxN)r   r   r   rT   rV   r   r   r   r   rQ   w   s   rQ   c                   @   s   e Zd Zdd ZdS )TestMatrixMultiplicationc                 C   s   |  d |  d d S )Nza @ bza @= brT   r   r   r   r   #test_matrix_multiplication_operator   s    
z<TestMatrixMultiplication.test_matrix_multiplication_operatorN)r   r   r   rY   r   r   r   r   rW      s   rW   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rT   rV   r   r   r   r   test_yield_from   s    

zTestYieldFrom.test_yield_fromN)r   r   r   r\   r   r   r   r   rZ      s   rZ   c                   @   s4   e Zd Zd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]
                      zasync 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   test_await_expr   s    





	



zTestAsyncAwait.test_await_exprc                 C   s"   |  d |  d |  d d S )Nz	async = 1z	await = 1zdef async(): passrX   r   r   r   r   test_async_var   s    

zTestAsyncAwait.test_async_varc                 C   s   |  d d S )NzDasync def foo():
                             async for a in b: passrX   r   r   r   r   test_async_for   s    zTestAsyncAwait.test_async_forc                 C   s   |  d | d d S )Nz@async def foo():
                             async with a: passz@def foo():
                                   async with a: passr[   r   r   r   r   test_async_with   s    
zTestAsyncAwait.test_async_withc                 C   s   |  d |  d d S )NzLasync def foo():
                   return (i * 2 async for i in arange(42))zFdef foo():
                   return (i * 2 async for i in arange(42))rX   r   r   r   r   test_async_generator   s    z#TestAsyncAwait.test_async_generatorN)r   r   r   r^   r_   r`   ra   rb   r   r   r   r   r]      s
   1r]   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raiserX   r   r   r   r   test_2x_style_1   s    z TestRaiseChanges.test_2x_style_1c                 C   s   |  d d S )Nz
raise E, VrX   r   r   r   r   test_2x_style_2   s    z TestRaiseChanges.test_2x_style_2c                 C   s   |  d d S )Nzraise E, V, TrX   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rV   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 E2rX   r   r   r   r   test_3x_style   s    zTestRaiseChanges.test_3x_stylec                 C   s   |  d d S )Nzraise E, V from E1rh   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, E2rh   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, E2rh   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 fromrh   r   r   r   r   test_3x_style_invalid_4   s    z(TestRaiseChanges.test_3x_style_invalid_4N)r   r   r   re   rf   rg   ri   rj   rk   rl   rm   rn   r   r   r   r   rc      s   rc   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d9d: Zd;d< Z d=d> Z!d?d@ Z"dAS )BTestUnpackingGeneralizationsc                 C   s   |  d d S )Nzfunc(1, *(2, 3), 4)rX   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'})rX   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'})rX   r   r   r   r   ,test_double_star_dict_literal_after_keywords  s    zITestUnpackingGeneralizations.test_double_star_dict_literal_after_keywordsc                 C   s   |  d |  d d S )Nzfunc(**{'a':2} or {})zfunc(**() or {})rX   r   r   r   r   test_double_star_expression  s    
z8TestUnpackingGeneralizations.test_double_star_expressionc                 C   s   |  d d S )Nzfunc(*[] or [2])rX   r   r   r   r   test_star_expression  s    z1TestUnpackingGeneralizations.test_star_expressionc                 C   s   |  d d S )Nz[*{2}, 3, *[4]]rX   r   r   r   r   test_list_display  s    z.TestUnpackingGeneralizations.test_list_displayc                 C   s   |  d d S )Nz{*{2}, 3, *[4]}rX   r   r   r   r   test_set_display  s    z-TestUnpackingGeneralizations.test_set_displayc                 C   s   |  d d S )Nz{**{}}rX   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}}rX   r   r   r   r   test_dict_display_2  s    z0TestUnpackingGeneralizations.test_dict_display_2c                 C   s   |  d d S )Nzfunc(* [] or [1])rX   r   r   r   r   test_complex_star_expression  s    z9TestUnpackingGeneralizations.test_complex_star_expressionc                 C   s   |  d d S )Nz5func(**{1: 3} if False else {x: x for x in range(3)})rX   r   r   r   r   #test_complex_double_star_expression  s    z@TestUnpackingGeneralizations.test_complex_double_star_expressionc                 C   s   |  d d S )Nzf(a, *b, *c, d)rX   r   r   r   r   test_argument_unpacking_1!  s    z6TestUnpackingGeneralizations.test_argument_unpacking_1c                 C   s   |  d d S )Nzf(**a, **b)rX   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)rX   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,)rX   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,)rX   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,)rX   r   r   r   r   test_trailing_commas_32  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,)rX   r   r   r   r   test_trailing_commas_46  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,)rX   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,)rX   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,)rX   r   r   r   r   test_trailing_commas_7B  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,)rX   r   r   r   r   test_trailing_commas_8F  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,)rX   r   r   r   r   test_trailing_commas_9J  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,)rX   r   r   r   r   test_trailing_commas_lambda_1N  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,)rX   r   r   r   r   test_trailing_commas_lambda_2R  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,)rX   r   r   r   r   test_trailing_commas_lambda_3V  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,)rX   r   r   r   r   test_trailing_commas_lambda_4Z  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,)rX   r   r   r   r   test_trailing_commas_lambda_5^  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,)rX   r   r   r   r   test_trailing_commas_lambda_6b  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,)rX   r   r   r   r   test_trailing_commas_lambda_7f  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,)rX   r   r   r   r   test_trailing_commas_lambda_8j  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,)rX   r   r   r   r   test_trailing_commas_lambda_9n  s    
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_9N)#r   r   r   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   r   r   r   r   r   r   r   r   r   r   ro      s@   ro   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: passrX   r   r   r   r   test_1u  s    zTestFunctionAnnotations.test_1c                 C   s   |  d d S )Nzdef f(x:int): passrX   r   r   r   r   test_2x  s    zTestFunctionAnnotations.test_2c                 C   s   |  d d S )Nzdef f(*x:str): passrX   r   r   r   r   test_3{  s    zTestFunctionAnnotations.test_3c                 C   s   |  d d S )Nzdef f(**x:float): passrX   r   r   r   r   test_4~  s    zTestFunctionAnnotations.test_4c                 C   s   |  d d S )Nzdef f(x, y:1+2): passrX   r   r   r   r   test_5  s    zTestFunctionAnnotations.test_5c                 C   s   |  d d S )Nzdef f(a, (b:1, c:2, d)): passrX   r   r   r   r   test_6  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): passrX   r   r   r   r   test_7  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: passrX   r   r   r   r   r   test_8  s    zTestFunctionAnnotations.test_8c                 C   s   d}|  | d S )Nzdef f(
          a: str,
          b: int,
          *,
          c: bool = False,
          **kwargs,
        ) -> None:
            call(c=c, **kwargs,)rX   r   r   r   r   test_9  s    zTestFunctionAnnotations.test_9c                 C   s   d}|  | d S )Nz@def f(
          a: str,
        ) -> None:
            call(a,)rX   r   r   r   r   test_10  s    zTestFunctionAnnotations.test_10c                 C   s   d}|  | d S )NzGdef f(
          a: str = '',
        ) -> None:
            call(a=a,)rX   r   r   r   r   test_11  s    zTestFunctionAnnotations.test_11c                 C   s   d}|  | d S )NzHdef f(
          *args: str,
        ) -> None:
            call(*args,)rX   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,)rX   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,)rX   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,)rX   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,)rX   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,)rX   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,)rX   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,)rX   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,)rX   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,)rX   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   t  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 = 5rX   r   r   r   r   r     s    zTestVarAnnotations.test_1c                 C   s   |  d d S )Nzvar2: [int, str]rX   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
rX   r   r   r   r   r     s    zTestVarAnnotations.test_3c                 C   s   |  d d S )Nz$def fbad():
    x: int
    print(x)
rX   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
rX   r   r   r   r   r     s    zTestVarAnnotations.test_5c                 C   s   |  d d S )Nzlst: List[int] = []rX   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:
                yrX   r   r   r   r   test_new  s    zTestExcept.test_newc                 C   s   d}|  | d S )NzN
            try:
                x
            except E, N:
                yrX   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   sH   | j D ]<}dj||d d}| | dj||d d}| | qd S )Nz{p}spamspamspam{s})pr   z{p}{s}{s}eggs{s}{s}{s})prefixesformatrT   )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'}rX   r   r   r   r   r     s    zTestSetLiteral.test_1c                 C   s   |  d d S )Nzx = {'one', 1,}rX   r   r   r   r   r     s    zTestSetLiteral.test_2c                 C   s   |  d d S )Nzx = {'one', 'two', 'three'}rX   r   r   r   r   r   "  s    zTestSetLiteral.test_3c                 C   s   |  d d S )Nzx = {2, 3, 4,}rX   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 )TestIdentifierc                 C   s,   |  d |  d |  d |  d d S )Nu!   Örter = 'places'
grün = 'green'u   蟒 = a蟒 = 锦蛇 = 1u   µ = aµ = µµ = 1uA   𝔘𝔫𝔦𝔠𝔬𝔡𝔢 = a_𝔘𝔫𝔦𝔠𝔬𝔡𝔢 = 1rX   r   r   r   r   test_non_ascii_identifiers,  s    


z)TestIdentifier.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0o7324528887r[   r   r   r   r   test_new_octal_notation4  s    
z+TestNumericLiterals.test_new_octal_notationc                 C   s   |  d | d d S )NZ0b101010Z	0b0101021r[   r   r   r   r   test_new_binary_notation8  s    
z,TestNumericLiterals.test_new_binary_notationN)r   r   r   r   r   r   r   r   r   r   3  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,): passrX   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d ZdS )	TestParserIdempotencyz,A cut-down version of pytree_idempotency.py.c                 C   s2  t jjrtd|  t|d }t|jd }W d    n1 sF0    Y  | |d|  t|d|d}|	 }W d    n1 s0    Y  zt
|}W nX ty   zt|}W n6 ty } z| d||f  W Y d }~n
d }~0 0 Y n0 t|}||kr.tt||| | d|  d S )	NzParse file: r1   r   zcan't detect encoding for %sr)encodingzParseError on file %s (%s)zIdempotency failed: %s)testr   verboseprintr9   r   detect_encodingreadlineZassertIsNotNoner:   r   r   r   r   Zfailstr
diff_texts)r   filepathfpr   sourceZtreeerrnewr   r   r   
parse_fileJ  s(    .&.
z TestParserIdempotency.parse_filec              	   C   sH   t  D ]:}| j|d | | W d    q1 s80    Y  qd S )N)r   )r   Zall_project_filesZsubTestr   )r   r   r   r   r   test_all_project_files_  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_unpackingd  s    


z-TestParserIdempotency.test_extended_unpackingN)r   r   r   __doc__r   r   r   r   r   r   r   r   F  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   dedentr   r   r   r   rT   m  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")
            rX   r   r   r   r   test_multiline_bytes_literalsp  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">
            """
            rX   r   r   r   r   'test_multiline_bytes_tripquote_literalsy  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")
            rX   r   r   r   r   test_multiline_str_literals  s    z(TestLiterals.test_multiline_str_literalsN)r   r   r   rT   r   r   r   r   r   r   r   r   k  s   		r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )TestNamedAssignmentsz"Also known as the walrus operator.c                 C   s   t d d S )Nzif f := x(): pass
r   r   r   r   r   test_named_assignment_if  s    z-TestNamedAssignments.test_named_assignment_ifc                 C   s   t d d S )Nzwhile f := x(): pass
r   r   r   r   r   test_named_assignment_while  s    z0TestNamedAssignments.test_named_assignment_whilec                 C   s   t d d S )Nz0any((lastNum := num) == 1 for num in [1, 2, 3])
r   r   r   r   r   test_named_assignment_generator  s    z4TestNamedAssignments.test_named_assignment_generatorc                 C   s   t d d S )Nz-[(lastNum := num) == 1 for num in [1, 2, 3]]
r   r   r   r   r   test_named_assignment_listcomp  s    z3TestNamedAssignments.test_named_assignment_listcompN)r   r   r   r   r   r   r   r   r   r   r   r   r     s
   r   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestPositionalOnlyArgsc                 C   s   t d d S )Nz!def one_pos_only_arg(a, /): pass
r   r   r   r   r   test_one_pos_only_arg  s    z,TestPositionalOnlyArgs.test_one_pos_only_argc                 C   s   t d d S )Nz4def all_markers(a, b=2, /, c, d=4, *, e=5, f): pass
r   r   r   r   r   test_all_markers  s    z'TestPositionalOnlyArgs.test_all_markersc                 C   s   t d d S )Nzdef all_markers_with_args_and_kwargs(
                           aa, b, /, _cc, d, *args, e, f_f, **kwargs,
                   ):
                       pass
r   r   r   r   r   test_all_with_args_and_kwargs  s    z4TestPositionalOnlyArgs.test_all_with_args_and_kwargsc                 C   s   t d d S )Nz,lambda a, b, /, c, d, *args, e, f, **kw: kw
r   r   r   r   r   test_lambda_soup  s    z'TestPositionalOnlyArgs.test_lambda_soupc                 C   s   t d d S )Nzdef func(a,b,/,*,g,e=3): pass
r   r   r   r   r   test_only_positional_or_keyword  s    z6TestPositionalOnlyArgs.test_only_positional_or_keywordN)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S )TestPickleableExceptionc                 C   s   t ddd d}ttjd D ]h}ttj||d}| |j|j | |j|j | |j	|j	 | |j
|j
 | |j|j qd S )Nr2   r   )r   contextr   )Zprotocol)r   ranger>   ZHIGHEST_PROTOCOLloadsr?   r   argsr2   r   valuer   )r   r   protoZerr2r   r   r   test_ParseError  s    z'TestPickleableException.test_ParseErrorN)r   r   r   r   r   r   r   r   r     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     s    r   __main__)2r   r   r   r   r   r   rD   rL   r!   r>   r%   r6   r7   r   Ztest.supportr   rP   Zlib2to3.pgen2r   r   Zpgen2.parser   Zlib2to3.pygramr	   r   ZTestCaser
   r   rQ   rW   rZ   r]   rc   ro   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   mainr   r   r   r   <module>   sR   		MM va
	%!
