o
    JAfg\                     @   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 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                   @      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symsZ
print_stmt)selfst r   0/usr/lib/python3.10/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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  }z>tj|tjtj}t	tj| t
|}t
j|ddd | tj| t| t
j|ddd W t| d S t| w )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   s  t  }tj|d}zt| 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< d|f }	d}
tjd|
 d	d
|	g}tj||d | tj| t|d)}t|d}| j| | dd W d    n1 sw   Y  W d    n1 sw   Y  W t	| d S W t	| d S t	| w )NZsubdirTr   randomZPYTHONHASHSEEDzs
from lib2to3.pgen2 import driver as pgen2_driver
pgen2_driver.load_grammar(%r, save=True, force=True)
            zGlib2to3 package is deprecated and may not be able to parse Python 3.10+z	-Wignore:z:PendingDeprecationWarningz-c)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sys
executable
subprocess
check_callopenr   readr/   )r   r0   Z	tmpsubdirZgrammar_baser1   Zgrammar_sub_copyr2   Zpickle_sub_nameZsub_envcoder7   cmdZ
pickle_f_1Z
pickle_f_2r   r   r   !test_load_grammar_from_subprocess@   sT   



 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                   @   r
   )z=TestPgen2Caching.test_load_packaged_grammar.<locals>.MyLoaderc                 S   s   t ddiS )Nelephant   )pickledumps)r   wherer   r   r   get_datap      zFTestPgen2Caching.test_load_packaged_grammar.<locals>.MyLoader.get_dataN)r   r   r   rI   r   r   r   r   MyLoadero       rK   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   rK   modnamer   r   MyModuler   s    rT   zGrammar.txtrE   )
r   r;   modulesZ
addCleanupoperatordelitemr   Zload_packaged_grammarr   rD   )r   rT   gr   rR   r   test_load_packaged_grammarm   s   z+TestPgen2Caching.test_load_packaged_grammar)r   r   r   r"   r3   unittestZskipIfr;   r<   rC   rY   r   r   r   r   r   *   s    
,r   c                   @      e Zd Zdd Zdd ZdS )GrammarTestc                 C   s   t | d S )N)r   r   r   rA   r   r   r   validate|   rJ   zGrammarTest.validatec                 C   s*   z
|  | W td ty   Y d S w )Nz Syntax shouldn't have been valid)r^   r   AssertionErrorr]   r   r   r   invalid_syntax   s   zGrammarTest.invalid_syntaxN)r   r   r   r^   r`   r   r   r   r   r\   {   s    r\   c                   @   r
   )TestMatrixMultiplicationc                 C      |  d |  d d S )Nza @ bza @= br^   r!   r   r   r   #test_matrix_multiplication_operator      
z<TestMatrixMultiplication.test_matrix_multiplication_operatorN)r   r   r   rd   r   r   r   r   ra      rL   ra   c                   @   r
   )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      

zTestYieldFrom.test_yield_fromN)r   r   r   rh   r   r   r   r   rf      rL   rf   c                   @   4   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
        rg   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(): passrc   r!   r   r   r   test_async_var   ri   zTestAsyncAwait.test_async_varc                 C      |  d d S )NzDasync def foo():
                             async for a in b: passrc   r!   r   r   r   test_async_for   rJ   zTestAsyncAwait.test_async_forc                 C      |  d | d d S )Nz@async def foo():
                             async with a: passz@def foo():
                                   async with a: passrg   r!   r   r   r   test_async_with   s   
zTestAsyncAwait.test_async_withc                 C   rb   )NzLasync def foo():
                   return (i * 2 async for i in arange(42))zFdef foo():
                   return (i * 2 async for i in arange(42))rc   r!   r   r   r   test_async_generator   s   z#TestAsyncAwait.test_async_generatorN)r   r   r   rl   rm   ro   rq   rr   r   r   r   r   rk      s    1rk   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   rn   )Nraiserc   r!   r   r   r   test_2x_style_1   rJ   z TestRaiseChanges.test_2x_style_1c                 C   rn   )Nz
raise E, Vrc   r!   r   r   r   test_2x_style_2   rJ   z TestRaiseChanges.test_2x_style_2c                 C   rn   )Nzraise E, V, Trc   r!   r   r   r   test_2x_style_3   rJ   z TestRaiseChanges.test_2x_style_3c                 C   rn   )Nzraise E, V, T, Zr`   r!   r   r   r   test_2x_style_invalid_1   rJ   z(TestRaiseChanges.test_2x_style_invalid_1c                 C   rn   )Nzraise E1 from E2rc   r!   r   r   r   test_3x_style   rJ   zTestRaiseChanges.test_3x_stylec                 C   rn   )Nzraise E, V from E1rx   r!   r   r   r   test_3x_style_invalid_1   rJ   z(TestRaiseChanges.test_3x_style_invalid_1c                 C   rn   )Nzraise E from E1, E2rx   r!   r   r   r   test_3x_style_invalid_2   rJ   z(TestRaiseChanges.test_3x_style_invalid_2c                 C   rn   )Nzraise from E1, E2rx   r!   r   r   r   test_3x_style_invalid_3   rJ   z(TestRaiseChanges.test_3x_style_invalid_3c                 C   rn   )Nzraise E fromrx   r!   r   r   r   test_3x_style_invalid_4   rJ   z(TestRaiseChanges.test_3x_style_invalid_4N)r   r   r   ru   rv   rw   ry   rz   r{   r|   r}   r~   r   r   r   r   rs      s    rs   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   rn   )Nzfunc(1, *(2, 3), 4)rc   r!   r   r   r   test_mid_positional_star  rJ   z5TestUnpackingGeneralizations.test_mid_positional_starc                 C   rn   )Nz,func(**{'eggs':'scrambled', 'spam':'fried'})rc   r!   r   r   r   test_double_star_dict_literal  rJ   z:TestUnpackingGeneralizations.test_double_star_dict_literalc                 C   rn   )Nz*func(spam='fried', **{'eggs':'scrambled'})rc   r!   r   r   r   ,test_double_star_dict_literal_after_keywords	  rJ   zITestUnpackingGeneralizations.test_double_star_dict_literal_after_keywordsc                 C   rb   )Nzfunc(**{'a':2} or {})zfunc(**() or {})rc   r!   r   r   r   test_double_star_expression  re   z8TestUnpackingGeneralizations.test_double_star_expressionc                 C   rn   )Nzfunc(*[] or [2])rc   r!   r   r   r   test_star_expression  rJ   z1TestUnpackingGeneralizations.test_star_expressionc                 C   rn   )Nz[*{2}, 3, *[4]]rc   r!   r   r   r   test_list_display  rJ   z.TestUnpackingGeneralizations.test_list_displayc                 C   rn   )Nz{*{2}, 3, *[4]}rc   r!   r   r   r   test_set_display  rJ   z-TestUnpackingGeneralizations.test_set_displayc                 C   rn   )Nz{**{}}rc   r!   r   r   r   test_dict_display_1  rJ   z0TestUnpackingGeneralizations.test_dict_display_1c                 C   rn   )Nz{**{}, 3:4, **{5:6, 7:8}}rc   r!   r   r   r   test_dict_display_2  rJ   z0TestUnpackingGeneralizations.test_dict_display_2c                 C   rn   )Nzfunc(* [] or [1])rc   r!   r   r   r   test_complex_star_expression  rJ   z9TestUnpackingGeneralizations.test_complex_star_expressionc                 C   rn   )Nz5func(**{1: 3} if False else {x: x for x in range(3)})rc   r!   r   r   r   #test_complex_double_star_expression"  rJ   z@TestUnpackingGeneralizations.test_complex_double_star_expressionc                 C   rn   )Nzf(a, *b, *c, d)rc   r!   r   r   r   test_argument_unpacking_1%  rJ   z6TestUnpackingGeneralizations.test_argument_unpacking_1c                 C   rn   )Nzf(**a, **b)rc   r!   r   r   r   test_argument_unpacking_2(  rJ   z6TestUnpackingGeneralizations.test_argument_unpacking_2c                 C   rn   )Nzf(2, *a, *b, **b, **c, **d)rc   r!   r   r   r   test_argument_unpacking_3+  rJ   z6TestUnpackingGeneralizations.test_argument_unpacking_3c                 C   rb   )Nzdef f(a, b): call(a, b)zdef f(a, b,): call(a, b,)rc   r!   r   r   r   test_trailing_commas_1.  re   z3TestUnpackingGeneralizations.test_trailing_commas_1c                 C   rb   )Nzdef f(a, *b): call(a, *b)zdef f(a, *b,): call(a, *b,)rc   r!   r   r   r   test_trailing_commas_22  re   z3TestUnpackingGeneralizations.test_trailing_commas_2c                 C   rb   )Nzdef f(a, b=1): call(a, b=1)zdef f(a, b=1,): call(a, b=1,)rc   r!   r   r   r   test_trailing_commas_36  re   z3TestUnpackingGeneralizations.test_trailing_commas_3c                 C   rb   )Nzdef f(a, **b): call(a, **b)zdef f(a, **b,): call(a, **b,)rc   r!   r   r   r   test_trailing_commas_4:  re   z3TestUnpackingGeneralizations.test_trailing_commas_4c                 C   rb   )Nzdef f(*a, b=1): call(*a, b=1)zdef f(*a, b=1,): call(*a, b=1,)rc   r!   r   r   r   test_trailing_commas_5>  re   z3TestUnpackingGeneralizations.test_trailing_commas_5c                 C   rb   )Nzdef f(*a, **b): call(*a, **b)zdef f(*a, **b,): call(*a, **b,)rc   r!   r   r   r   test_trailing_commas_6B  re   z3TestUnpackingGeneralizations.test_trailing_commas_6c                 C   rb   )Nzdef f(*, b=1): call(*b)zdef f(*, b=1,): call(*b,)rc   r!   r   r   r   test_trailing_commas_7F  re   z3TestUnpackingGeneralizations.test_trailing_commas_7c                 C   rb   )Nzdef f(a=1, b=2): call(a=1, b=2)z!def f(a=1, b=2,): call(a=1, b=2,)rc   r!   r   r   r   test_trailing_commas_8J  re   z3TestUnpackingGeneralizations.test_trailing_commas_8c                 C   rb   )Nzdef f(a=1, **b): call(a=1, **b)z!def f(a=1, **b,): call(a=1, **b,)rc   r!   r   r   r   test_trailing_commas_9N  re   z3TestUnpackingGeneralizations.test_trailing_commas_9c                 C   rb   )Nzf = lambda a, b: call(a, b)zf = lambda a, b,: call(a, b,)rc   r!   r   r   r   test_trailing_commas_lambda_1R  re   z:TestUnpackingGeneralizations.test_trailing_commas_lambda_1c                 C   rb   )Nzf = lambda a, *b: call(a, *b)zf = lambda a, *b,: call(a, *b,)rc   r!   r   r   r   test_trailing_commas_lambda_2V  re   z:TestUnpackingGeneralizations.test_trailing_commas_lambda_2c                 C   rb   )Nzf = lambda a, b=1: call(a, b=1)z!f = lambda a, b=1,: call(a, b=1,)rc   r!   r   r   r   test_trailing_commas_lambda_3Z  re   z:TestUnpackingGeneralizations.test_trailing_commas_lambda_3c                 C   rb   )Nzf = lambda a, **b: call(a, **b)z!f = lambda a, **b,: call(a, **b,)rc   r!   r   r   r   test_trailing_commas_lambda_4^  re   z:TestUnpackingGeneralizations.test_trailing_commas_lambda_4c                 C   rb   )Nz!f = lambda *a, b=1: call(*a, b=1)z#f = lambda *a, b=1,: call(*a, b=1,)rc   r!   r   r   r   test_trailing_commas_lambda_5b  re   z:TestUnpackingGeneralizations.test_trailing_commas_lambda_5c                 C   rb   )Nz!f = lambda *a, **b: call(*a, **b)z#f = lambda *a, **b,: call(*a, **b,)rc   r!   r   r   r   test_trailing_commas_lambda_6f  re   z:TestUnpackingGeneralizations.test_trailing_commas_lambda_6c                 C   rb   )Nzf = lambda *, b=1: call(*b)zf = lambda *, b=1,: call(*b,)rc   r!   r   r   r   test_trailing_commas_lambda_7j  re   z:TestUnpackingGeneralizations.test_trailing_commas_lambda_7c                 C   rb   )Nz#f = lambda a=1, b=2: call(a=1, b=2)z%f = lambda a=1, b=2,: call(a=1, b=2,)rc   r!   r   r   r   test_trailing_commas_lambda_8n  re   z:TestUnpackingGeneralizations.test_trailing_commas_lambda_8c                 C   rb   )Nz#f = lambda a=1, **b: call(a=1, **b)z%f = lambda a=1, **b,: call(a=1, **b,)rc   r!   r   r   r   test_trailing_commas_lambda_9r  re   z:TestUnpackingGeneralizations.test_trailing_commas_lambda_9N)#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     sB    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+S ),TestFunctionAnnotationsc                 C   rn   )Nzdef f(x) -> list: passrc   r!   r   r   r   test_1y  rJ   zTestFunctionAnnotations.test_1c                 C   rn   )Nzdef f(x:int): passrc   r!   r   r   r   test_2|  rJ   zTestFunctionAnnotations.test_2c                 C   rn   )Nzdef f(*x:str): passrc   r!   r   r   r   test_3  rJ   zTestFunctionAnnotations.test_3c                 C   rn   )Nzdef f(**x:float): passrc   r!   r   r   r   test_4  rJ   zTestFunctionAnnotations.test_4c                 C   rn   )Nzdef f(x, y:1+2): passrc   r!   r   r   r   test_5  rJ   zTestFunctionAnnotations.test_5c                 C   rn   )Nzdef f(a, (b:1, c:2, d)): passrc   r!   r   r   r   test_6  rJ   zTestFunctionAnnotations.test_6c                 C   rn   )Nz/def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6): passrc   r!   r   r   r   test_7  rJ   zTestFunctionAnnotations.test_7c                 C      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: passrc   r   r   r   r   r   test_8  s   zTestFunctionAnnotations.test_8c                 C   r   )Nzdef f(
          a: str,
          b: int,
          *,
          c: bool = False,
          **kwargs,
        ) -> None:
            call(c=c, **kwargs,)rc   r   r   r   r   test_9  s   zTestFunctionAnnotations.test_9c                 C   r   )Nz@def f(
          a: str,
        ) -> None:
            call(a,)rc   r   r   r   r   test_10     zTestFunctionAnnotations.test_10c                 C   r   )NzGdef f(
          a: str = '',
        ) -> None:
            call(a=a,)rc   r   r   r   r   test_11  r   zTestFunctionAnnotations.test_11c                 C   r   )NzHdef f(
          *args: str,
        ) -> None:
            call(*args,)rc   r   r   r   r   test_12  r   zTestFunctionAnnotations.test_12c                 C   rb   )Nz)def f(a: str, b: int) -> None: call(a, b)z+def f(a: str, b: int,) -> None: call(a, b,)rc   r!   r   r   r   test_13  re   zTestFunctionAnnotations.test_13c                 C   rb   )Nz+def f(a: str, *b: int) -> None: call(a, *b)z-def f(a: str, *b: int,) -> None: call(a, *b,)rc   r!   r   r   r   test_14  re   zTestFunctionAnnotations.test_14c                 C   rb   )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,)rc   r!   r   r   r   test_15  re   zTestFunctionAnnotations.test_15c                 C   rb   )Nz-def f(a: str, **b: int) -> None: call(a, **b)z/def f(a: str, **b: int,) -> None: call(a, **b,)rc   r!   r   r   r   test_16  re   zTestFunctionAnnotations.test_16c                 C   rb   )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,)rc   r!   r   r   r   test_17  re   zTestFunctionAnnotations.test_17c                 C   rb   )Nz/def f(*a: str, **b: int) -> None: call(*a, **b)z1def f(*a: str, **b: int,) -> None: call(*a, **b,)rc   r!   r   r   r   test_18  re   zTestFunctionAnnotations.test_18c                 C   rb   )Nz$def f(*, b: int=1) -> None: call(*b)z&def f(*, b: int=1,) -> None: call(*b,)rc   r!   r   r   r   test_19  re   zTestFunctionAnnotations.test_19c                 C   rb   )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,)rc   r!   r   r   r   test_20  re   zTestFunctionAnnotations.test_20c                 C   rb   )Nz2def f(a: str='', **b: int) -> None: call(a=a, **b)z4def f(a: str='', **b: int,) -> None: call(a=a, **b,)rc   r!   r   r   r   test_21  re   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   x  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   rn   )Nzvar1: int = 5rc   r!   r   r   r   r     rJ   zTestVarAnnotations.test_1c                 C   rn   )Nzvar2: [int, str]rc   r!   r   r   r   r     rJ   zTestVarAnnotations.test_2c                 C   rn   )NzCdef f():
    st: str = 'Hello'
    a.b: int = (1, 2)
    return st
rc   r!   r   r   r   r     rJ   zTestVarAnnotations.test_3c                 C   rn   )Nz$def fbad():
    x: int
    print(x)
rc   r!   r   r   r   r     rJ   zTestVarAnnotations.test_4c                 C   rn   )Nzeclass C:
    x: int
    s: str = 'attr'
    z = 2
    def __init__(self, x):
        self.x: int = x
rc   r!   r   r   r   r     rJ   zTestVarAnnotations.test_5c                 C   rn   )Nzlst: List[int] = []rc   r!   r   r   r   r     rJ   zTestVarAnnotations.test_6N)	r   r   r   r   r   r   r   r   r   r   r   r   r   r     s    r   c                   @   r[   )
TestExceptc                 C   r   )NzP
            try:
                x
            except E as N:
                yrc   r   r   r   r   test_new     zTestExcept.test_newc                 C   r   )NzN
            try:
                x
            except E, N:
                yrc   r   r   r   r   test_old   r   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formatr^   )r   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                   @   ,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestSetLiteralc                 C   rn   )Nzx = {'one'}rc   r!   r   r   r   r      rJ   zTestSetLiteral.test_1c                 C   rn   )Nzx = {'one', 1,}rc   r!   r   r   r   r   #  rJ   zTestSetLiteral.test_2c                 C   rn   )Nzx = {'one', 'two', 'three'}rc   r!   r   r   r   r   &  rJ   zTestSetLiteral.test_3c                 C   rn   )Nzx = {2, 3, 4,}rc   r!   r   r   r   r   )  rJ   zTestSetLiteral.test_4N)r   r   r   r   r   r   r   r   r   r   r   r     s
    r   c                   @   r
   )TestIdentifierc                 C   s,   |  d |  d |  d |  d d S )Nu!   Örter = 'places'
grün = 'green'u   蟒 = a蟒 = 锦蛇 = 1u   µ = aµ = µµ = 1uA   𝔘𝔫𝔦𝔠𝔬𝔡𝔢 = a_𝔘𝔫𝔦𝔠𝔬𝔡𝔢 = 1rc   r!   r   r   r   test_non_ascii_identifiers0     


z)TestIdentifier.test_non_ascii_identifiersN)r   r   r   r   r   r   r   r   r   /  rL   r   c                   @   r[   )TestNumericLiteralsc                 C   rp   )NZ0o7777777777777Z0o7324528887rg   r!   r   r   r   test_new_octal_notation8  re   z+TestNumericLiterals.test_new_octal_notationc                 C   rp   )NZ0b101010Z	0b0101021rg   r!   r   r   r   test_new_binary_notation<  re   z,TestNumericLiterals.test_new_binary_notationN)r   r   r   r   r   r   r   r   r   r   7  s    r   c                   @   r
   )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,): passrc   r!   r   r   r   test_new_syntaxB  s
   



zTestClassDef.test_new_syntaxN)r   r   r   r   r   r   r   r   r   A  rL   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   s4  t jjrtd|  t|d}t|jd }W d    n1 s#w   Y  | |d|  t|d|d}|	 }W d    n1 sFw   Y  zt
|}W n, ty~   zt|}W n ty{ } z| d||f  W Y d }~nd }~ww Y nw t|}||krtt||| | d|  d S d S )	NzParse file: r6   r   zcan't detect encoding for %sr)encodingzParseError on file %s (%s)zIdempotency failed: %s)testr   verboseprintr?   r   detect_encodingreadlineZassertIsNotNoner@   r   r   r   r   Zfailstr
diff_texts)r   filepathfpr   sourceZtreeerrnewr   r   r   
parse_fileN  s6   
z TestParserIdempotency.parse_filec              	   C   sH   t  D ]}| j|d | | W d    n1 sw   Y  qd S )N)r   )r   Zall_project_filesZsubTestr   )r   r   r   r   r   test_all_project_filesc  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_unpackingh  r   z-TestParserIdempotency.test_extended_unpackingN)r   r   r   __doc__r   r   r   r   r   r   r   r   J  s
    r   c                   @   r   )
TestLiteralsc                 C   s   t t|d  d S )Nz

)r   r   r   dedentr   r   r   r   r^   q  s   zTestLiterals.validatec                 C   r   )Nu   
            md5test(b"ª" * 80,
                    (b"Test Using Larger Than Block-Size Key "
                     b"and Larger Than One Block-Size Data"),
                    "6f630fad67cda0ee1fb1f562db3aa53e")
            rc   r   r   r   r   test_multiline_bytes_literalst     z*TestLiterals.test_multiline_bytes_literalsc                 C   r   )Nz
            b"""
            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN">
            """
            rc   r   r   r   r   'test_multiline_bytes_tripquote_literals}  r   z4TestLiterals.test_multiline_bytes_tripquote_literalsc                 C   r   )Nu   
            md5test("ª" * 80,
                    ("Test Using Larger Than Block-Size Key "
                     "and Larger Than One Block-Size Data"),
                    "6f630fad67cda0ee1fb1f562db3aa53e")
            rc   r   r   r   r   test_multiline_str_literals  r   z(TestLiterals.test_multiline_str_literalsN)r   r   r   r^   r   r   r   r   r   r   r   r   o  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      t d d S )Nzif f := x(): pass
r   r!   r   r   r   test_named_assignment_if  rJ   z-TestNamedAssignments.test_named_assignment_ifc                 C   r   )Nzwhile f := x(): pass
r   r!   r   r   r   test_named_assignment_while  rJ   z0TestNamedAssignments.test_named_assignment_whilec                 C   r   )Nz0any((lastNum := num) == 1 for num in [1, 2, 3])
r   r!   r   r   r   test_named_assignment_generator  rJ   z4TestNamedAssignments.test_named_assignment_generatorc                 C   r   )Nz-[(lastNum := num) == 1 for num in [1, 2, 3]]
r   r!   r   r   r   test_named_assignment_listcomp  rJ   z3TestNamedAssignments.test_named_assignment_listcompN)r   r   r   r   r   r   r   r   r   r   r   r   r     s    r   c                   @   rj   )TestPositionalOnlyArgsc                 C   r   )Nz!def one_pos_only_arg(a, /): pass
r   r!   r   r   r   test_one_pos_only_arg  rJ   z,TestPositionalOnlyArgs.test_one_pos_only_argc                 C   r   )Nz4def all_markers(a, b=2, /, c, d=4, *, e=5, f): pass
r   r!   r   r   r   test_all_markers     z'TestPositionalOnlyArgs.test_all_markersc                 C   r   )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  r   z4TestPositionalOnlyArgs.test_all_with_args_and_kwargsc                 C   r   )Nz,lambda a, b, /, c, d, *args, e, f, **kw: kw
r   r!   r   r   r   test_lambda_soup  r   z'TestPositionalOnlyArgs.test_lambda_soupc                 C   r   )Nzdef func(a,b,/,*,g,e=3): pass
r   r!   r   r   r   test_only_positional_or_keyword  rJ   z6TestPositionalOnlyArgs.test_only_positional_or_keywordN)r   r   r   r   r   r   r   r   r   r   r   r   r     s    r   c                   @   r
   )TestPickleableExceptionc                 C   s   t ddd d}ttjd D ]4}ttj||d}| |j|j | |j|j | |j	|j	 | |j
|j
 | |j|j qd S )Nr7   r   )r   contextr   )protocol)r   rangerF   HIGHEST_PROTOCOLloadsrG   r   argsr7   r   valuer   )r   r   protoZerr2r   r   r   test_ParseError  s   z'TestPickleableException.test_ParseErrorN)r   r   r   r  r   r   r   r   r     rL   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  rN   rV   r%   rF   r)   r=   r;   r#   Ztest.supportr   rZ   Zlib2to3.pgen2r   r   Zpgen2.parser   Zlib2to3.pygramr	   r   ZTestCaser   r   r\   ra   rf   rk   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   mainr   r   r   r   <module>   sV    		QM va
	%!
