
    <ea                         d 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 ZdZ	dZ
dZdZdZd	Zd
ZdZdZdZdZdZdZdZ G d dej                  Z G d de          Z G d de          Z G d de          Zedk    r ej                     dS dS )z>Tests for the unparse.py script in the Tools/parser directory.    Nc                     t          j        |           5 }|                                cddd           S # 1 swxY w Y   dS )znRead and return the contents of a Python source file (as a
    string), taking into account the file encoding.N)tokenizeopenread)filenamestreams     (/usr/lib/python3.11/test/test_unparse.pyread_pyfiler
      s     
x	 	  F{{}}                 s   6::zQdef f():
    for x in range(10):
        break
    else:
        y = 2
    z = 3
zIdef g():
    while True:
        break
    else:
        y = 2
    z = 3
zQfrom . import fred
from .. import barney
from .australia import shrimp as prawns
zzdef f():
    x = 1
    def g():
        nonlocal x
        x = 2
        y = 7
        def h():
            nonlocal x, y
zOtry:
    1 / 0
except ZeroDivisionError as e:
    raise ArithmeticError from e
z@f1(arg)
@f2
class Foo: pass
z=if cond1:
    suite1
elif cond2:
    suite2
else:
    suite3
z,if cond1:
    suite1
elif cond2:
    suite2
zctry:
    suite1
except ex1:
    suite2
except ex2:
    suite3
else:
    suite4
finally:
    suite5
zetry:
    suite1
except* ex1:
    suite2
except* ex2:
    suite3
else:
    suite4
finally:
    suite5
zwith f():
    suite1
zwith f() as x:
    suite1
z$with f() as x, g() as y:
    suite1
) zclass foo:
    zdef foo():
    zasync def foo():
    c                   <    e Zd Zd Zd ZefdZddZddZddZ	dS )	ASTTestCasec                                            |t          j                                         |t          j                   t                      f fd	 ||           d S )Nc                    t          |           t          |          ur4                    t          |           dt          |                     t          | t          j                  r>| j        D ]4}t          | ||          }t          |||          }||ur ||           5d S t          | t                    r	 t          | |d          D ]\  }} ||           d S # t          $ rR t          |           }t          |          }	||	k    rd}
||	z
  }nd}
|	|z
  }|
 d| d}                    |          d w xY w| |k    r                    | d|           d S d S )	Nz is not T)strictFirstSecondz list contains z additional elements.z != )typefail
isinstanceastAST_fieldsgetattrlistzip
ValueErrorlenfailureException)abmissingfieldvalue1value2node1node2len1len2whatdiffmsgselftraverse_compares                r	   r-   z4ASTTestCase.assertASTEqual.<locals>.traverse_compare   s   Awwd1gg%%		T!WW;;Q;;<<<!SW%% -Y 9 9E$Qw77F$Qw77F V++((8889 9 At$$ -?(+Aq(>(>(> 7 7u((66667 7! ? ? ?q66Dq66Dd{{&#d{'#d{!MM$MMMC//44$>? a		Q++a++,,,,, s   $C( (AE)assertIsInstancer   r   object)r,   ast1ast2r-   s   `  @r	   assertASTEqualzASTTestCase.assertASTEqual   s{    dCG,,,dCG,,,
 ,288 	- 	- 	- 	- 	- 	- 	-: 	t$$$$$    c                    |                      ||          5  t          j        |fi |}t          j        |          }t          j        |fi |}|                     ||           d d d            d S # 1 swxY w Y   d S )N)code1ast_parse_kwargs)subTestr   parseunparser2   )r,   r5   kwargsr0   code2r1   s         r	   check_ast_roundtripzASTTestCase.check_ast_roundtrip   s    \\\?? 	, 	,9U--f--DK%%E9U--f--Dd+++		, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   AA44A8;A8c                     |                      |          5  |                     |t          j        |           d d d            d S # 1 swxY w Y   d S )N)node)r7   assertRaisesr   r9   )r,   r>   raisess      r	   check_invalidzASTTestCase.check_invalid   s    \\t\$$ 	9 	9fck4888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9s   "AA
A
Nc                 ^    |p|}t          j        t          j        |                    }||fS N)r   r9   r8   r,   r5   r;   s      r	   
get_sourcezASTTestCase.get_source   s.    CIe,,--e|r3   c                     |                      ||          \  }}|                     ||          5  |                     ||           d d d            d S # 1 swxY w Y   d S N)r5   r;   )rE   r7   assertEqualrD   s      r	   check_src_roundtripzASTTestCase.check_src_roundtrip   s    ue44u\\U\33 	+ 	+UE***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+   AAAc                     |                      ||          \  }}|                     ||          5  |                     ||           d d d            d S # 1 swxY w Y   d S rG   )rE   r7   assertNotEqualrD   s      r	   check_src_dont_roundtripz$ASTTestCase.check_src_dont_roundtrip   s    ue44u\\U\33 	. 	.u---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.rJ   rC   )
__name__
__module____qualname__r2   r<   r   rA   rE   rI   rM    r3   r	   r   r      s        %% %% %%N, , , *4 9 9 9 9   
+ + + +
. . . . . .r3   r   c                   (   e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0S )1UnparseTestCasec                    |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d	           |                      d
           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           d S )Nzf'a'zf'{{}}'zf'{{5}}'z	f'{{5}}5'z	f'X{{}}X'zf'{a}'zf'{ {1:2}}'zf'a{a}a'zf'a{a}{a}a'zf'a{a}a{a}a'zf'{a!r}x{a!s}12{{}}{a!a}'z	f'{a:10}'zf'{a:100_000{10}}'zf'{a!r:10}'zf'{a:a{b}10}'zRf'a{b}{c!s}{d!r}{e!a}{f:a}{g:a{b}}{h!s:a}{j!s:{a}b}{k!s:a{b}c}{l!a:{b}c{d}}{x+y=}'r<   r,   s    r	   test_fstringszUnparseTestCase.test_fstrings   sW     (((  +++  ,,,  ---  ---  ***  ///  ,,,  ///  000  !<===  ---  !5666  ///  111  <	
 	
 	
 	
 	
r3   c                     |                      d           |                      d           |                      d           |                      d           d S )Nzf'{f"{0}"*3}'zf'{f"{y}"*3}'zf''zf"""'end' "quote\""""rU   rV   s    r	   test_fstrings_special_charsz+UnparseTestCase.test_fstrings_special_chars   s[      !5666  !5666  +++  !=>>>>>r3   c                 ,   |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           d S )Nzf'''{"'"}'''%f'''-{f"""*{f"+{f'.{x}.'}+"}*"""}-'''z4f'''-{f"""*{f"+{f'.{x}.'}+"}*"""}-'single quote\''''zf"""{'''
'''}"""zf"""{g('''
''')}"""z	f"a\r\nb"f"\u2028{'x'}"rU   rV   s    r	   test_fstrings_complicatedz)UnparseTestCase.test_fstrings_complicated   s      !3444  !RSSS  !bccc  !:;;;  !=>>>  !2333  !677777r3   c                     |                      d           |                      d           |                      d           d S )Nzu'foo'zr'foo'zb'foo'rU   rV   s    r	   test_stringszUnparseTestCase.test_strings   sD      ***  ***  *****r3   c                 0    |                      d           d S )Nzdel x, y, zrU   rV   s    r	   test_del_statementz"UnparseTestCase.test_del_statement   s      /////r3   c                 Z    |                      d           |                      d           d S )Nz45 << 2z13 >> 7rU   rV   s    r	   test_shiftszUnparseTestCase.test_shifts   s0      +++  +++++r3   c                 :    |                      t                     d S rC   )r<   for_elserV   s    r	   test_for_elsezUnparseTestCase.test_for_else   s      *****r3   c                 :    |                      t                     d S rC   )r<   
while_elserV   s    r	   test_while_elsezUnparseTestCase.test_while_else         ,,,,,r3   c                     |                      d           |                      d           |                      d           |                      d           |                      d           d S )Nz(-1)**7z(-1.)**8z(-1j)**6znot True or FalsezTrue or not FalserU   rV   s    r	   test_unary_parensz!UnparseTestCase.test_unary_parens   sn      +++  ,,,  ,,,  !4555  !455555r3   c                 0    |                      d           d S )Nz3 .__abs__()rU   rV   s    r	   test_integer_parensz#UnparseTestCase.test_integer_parens  s      00000r3   c                     |                      d           |                      d           |                      d           |                      d           d S )N1e1000z-1e10001e1000jz-1e1000jrU   rV   s    r	   test_huge_floatzUnparseTestCase.test_huge_float
  sX      ***  +++  +++  ,,,,,r3   c                     |                      t          j        t          j        t          j        t          d                                        t          j        d                     d S )Nnanvaluez1e1000 - 1e1000)r2   r   r8   r9   ConstantfloatrV   s    r	   test_nanzUnparseTestCase.test_nan  s\    Ick#,U5\\"B"B"BCCDDI'((	
 	
 	
 	
 	
r3   c                     |                      t          d                     |                      t          d                     d S )Ni   l         )r<   strrV   s    r	   test_min_intzUnparseTestCase.test_min_int  s<      Z111  Z11111r3   c                     |                      d           |                      d           |                      d           |                      d           d S )N7jz-7j0jz-0jrU   rV   s    r	   test_imaginary_literalsz'UnparseTestCase.test_imaginary_literals  sX      &&&  '''  &&&  '''''r3   c                 0    |                      d           d S )Nz(lambda: int)()rU   rV   s    r	   test_lambda_parenthesesz'UnparseTestCase.test_lambda_parentheses         !233333r3   c                 Z    |                      d           |                      d           d S )Nz
1 < 4 <= 5za is b is c is not drU   rV   s    r	   test_chained_comparisonsz(UnparseTestCase.test_chained_comparisons#  s1      ...  !788888r3   c                    |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d	           |                      d
           |                      d           |                      d           d S )Nzdef f(): passzdef f(a): passzdef f(b = 2): passzdef f(a, b): passzdef f(a, b = 2): passzdef f(a = 5, b = 2): passzdef f(*, a = 1, b = 2): passzdef f(*, a = 1, b): passzdef f(*, a, b = 2): passz&def f(a, b = None, *, c, **kwds): passz'def f(a=2, *args, c=5, d, **kwds): passzdef f(*args, **kwargs): passrU   rV   s    r	   test_function_argumentsz'UnparseTestCase.test_function_arguments'  s     111  !1222  !5666  !4555  !8999  !<===  !?@@@  !;<<<  !;<<<  !IJJJ  !JKKK  !?@@@@@r3   c                 :    |                      t                     d S rC   )r<   relative_importrV   s    r	   test_relative_importz$UnparseTestCase.test_relative_import5        11111r3   c                 :    |                      t                     d S rC   )r<   nonlocal_exrV   s    r	   test_nonlocalzUnparseTestCase.test_nonlocal8        -----r3   c                 :    |                      t                     d S rC   )r<   
raise_fromrV   s    r	   test_raise_fromzUnparseTestCase.test_raise_from;  rj   r3   c                 0    |                      d           d S )Nzb'123'rU   rV   s    r	   
test_byteszUnparseTestCase.test_bytes>  s      *****r3   c                     |                      d           |                      d           |                      d           |                      d           |                      d           d S )Nzdef f(a : int): passzdef f(a: int = 5): passzdef f(*args: [int]): passzdef f(**kwargs: dict): passzdef f() -> None: passrU   rV   s    r	   test_annotationsz UnparseTestCase.test_annotationsA  sq      !7888  !:;;;  !<===  !>???  !899999r3   c                 0    |                      d           d S )Nz{'a', 'b', 'c'}rU   rV   s    r	   test_set_literalz UnparseTestCase.test_set_literalH  r   r3   c           	          |                      t          j        t          j        t          j        g                               t          j        d                     d S )N)eltsz{*()})r2   r   r8   r9   SetrV   s    r	   test_empty_setzUnparseTestCase.test_empty_setK  sU    Ick#'r"2"2"23344Ig	
 	
 	
 	
 	
r3   c                 0    |                      d           d S )Nz{x for x in range(5)}rU   rV   s    r	   test_set_comprehensionz&UnparseTestCase.test_set_comprehensionQ  s      !899999r3   c                 0    |                      d           d S )Nz{x: x*x for x in range(10)}rU   rV   s    r	   test_dict_comprehensionz'UnparseTestCase.test_dict_comprehensionT  s      !>?????r3   c                 :    |                      t                     d S rC   )r<   class_decoratorrV   s    r	   test_class_decoratorsz%UnparseTestCase.test_class_decoratorsW  r   r3   c                 0    |                      d           d S )Nz(class A(metaclass=type, *[], **{}): passrU   rV   s    r	   test_class_definitionz%UnparseTestCase.test_class_definitionZ  s      !KLLLLLr3   c                 n    |                      t                     |                      t                     d S rC   )r<   elif1elif2rV   s    r	   
test_elifszUnparseTestCase.test_elifs]  s0      '''  '''''r3   c                 :    |                      t                     d S rC   )r<   try_except_finallyrV   s    r	   test_try_except_finallyz'UnparseTestCase.test_try_except_finallya  s      !344444r3   c                 :    |                      t                     d S rC   )r<   try_except_star_finallyrV   s    r	   test_try_except_star_finallyz,UnparseTestCase.test_try_except_star_finallyd  s      !899999r3   c                     |                      d           |                      d           |                      d           |                      d           d S )Nza, *b, c = seqza, (*b, c) = seqza, *b[0], c = seqza, *(b, c) = seqrU   rV   s    r	   test_starred_assignmentz'UnparseTestCase.test_starred_assignmentg  s\      !1222  !3444  !4555  !344444r3   c                 :    |                      t                     d S rC   )r<   with_simplerV   s    r	   test_with_simplez UnparseTestCase.test_with_simplem  r   r3   c                 :    |                      t                     d S rC   )r<   with_asrV   s    r	   test_with_aszUnparseTestCase.test_with_asp  s      )))))r3   c                 :    |                      t                     d S rC   )r<   with_two_itemsrV   s    r	   test_with_two_itemsz#UnparseTestCase.test_with_two_itemss  s      00000r3   c                 Z    |                      d           |                      d           d S )Nz{**{'y': 2}, 'x': 1}z{**{'y': 2}, **{'x': 1}}rU   rV   s    r	   test_dict_unpacking_in_dictz+UnparseTestCase.test_dict_unpacking_in_dictv  s2      !<===  !@AAAAAr3   c                    |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d	           |                      d
           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           d S )Nza[i]za[i,]za[i, j]za[(*a,)]za[*a]za[b, *a]za[*a, c]za[b, *a, c]	a[*a, *a]za[b, *a, *a]za[*a, b, *a]za[*a, *a, b]za[b, *a, *a, c]z	a[(a:=b)]za[(a:=b,c)]a[()]za[i:j]za[:j]za[i:]za[i:j:k]za[:j:k]za[i::k]za[i:j,]z	a[i:j, k]rU   rV   s    r	   test_sliceszUnparseTestCase.test_slices{  s     (((  )))  +++  ,,,  )))  ,,,  ,,,  ///  ---  000  000  000  !2333  ---  ///  )))  ***  )))  )))  ,,,  +++  +++  +++  -----r3   c                 ~    |                      t          j        d t          j        d                               d S )NXid)exccause)rA   r   RaiseNamerV   s    r	   test_invalid_raisez"UnparseTestCase.test_invalid_raise  s8    39SX5E5E5EFFFGGGGGr3   c                     |                      t          j        t          j        d          t          j        d          g                     d S )Ntestr   ru   )values)rA   r   	JoinedStrr   rw   rV   s    r	   test_invalid_fstring_valuez*UnparseTestCase.test_invalid_fstring_value  s]    MH'''Lv...  	
 	
 	
 	
 	
r3   c                 |    |                      t          j        t          j        d                               d S )Nz\\ru   )rA   r   FormattedValuerw   rV   s    r	   test_invalid_fstring_backslashz.UnparseTestCase.test_invalid_fstring_backslash  s7    3-CLv4N4N4NOOOPPPPPr3   c                 V    |                      t          j        d                      d S )Nru   )rA   r   	YieldFromrV   s    r	   test_invalid_yield_fromz'UnparseTestCase.test_invalid_yield_from  s)    3=t44455555r3   c                 P   t          j        dt          j        d          g          }|                     t          j        |          d           t          j        dt          j        d          gd           }|                     t          j        |          d           d S )Nmodx)name)modulenameszfrom mod import x)r   r   level)r   
ImportFromaliasrH   r9   )r,   trees     r	   test_import_from_level_nonez+UnparseTestCase.test_import_from_level_none  s    ~U39#3F3F3F2GHHHT**,?@@@~U39#3F3F3F2GtTTTT**,?@@@@@r3   c                 F    d}|D ]}|                      d| d           d S )N)zthis ends with double quote"z"this includes a """triple quote"""z\r	z\t
z\nz	\r	\t
\nz$""">>> content = """blabla""" <<<"""z	foo\n\x00z' \'\'\'""" ""\'\' \'u   🐍⛎𩸽üéş^\\X\\BB⟿z'''rU   )r,   
docstrings	docstrings      r	   test_docstringszUnparseTestCase.test_docstrings  sG    

 $ 	; 	;I$$%99%9%9%9::::	; 	;r3   c                     |                      t          j        dd           d           |                      t          j        dd           d           d S )N)   )rv   kindz(1,))r         z	(1, 2, 3))rI   r   rw   rV   s    r	   test_constant_tuplesz$UnparseTestCase.test_constant_tuples  s]      Dt!D!D!DfMMM  Lyt444k	
 	
 	
 	
 	
r3   c                 >    dD ]}|                      |d           d S )N)z	() -> intz(int, int) -> intz=(Callable[complex], More[Complex(call.to_typevar())]) -> None	func_type)moderU   )r,   function_types     r	   test_function_typez"UnparseTestCase.test_function_type  s?    
 	F 	FM
 $$]$EEEE	F 	Fr3   c                 >    dD ]}|                      |d           d S )N)za = 5 # type:za = 5 # type: intza = 5 # type: int and morez!def x(): # type: () -> None
	passz.def x(y): # type: (int) -> None and more
	passz'async def x(): # type: () -> None
	passz4async def x(y): # type: (int) -> None and more
	passzfor x in y: # type: int
	passz#async for x in y: # type: int
	passzwith x(): # type: int
	passz!async with x(): # type: int
	passTtype_commentsrU   r,   	statements     r	   test_type_commentsz"UnparseTestCase.test_type_comments  s?    
 	D 	DI $$Yd$CCCC	D 	Dr3   c                 >    dD ]}|                      |d           d S )N)
za = 5 # type: ignoreza = 5 # type: ignore and morezdef x(): # type: ignore
	passz'def x(y): # type: ignore and more
	passz#async def x(): # type: ignore
	passz-async def x(y): # type: ignore and more
	passz for x in y: # type: ignore
	passz&async for x in y: # type: ignore
	passzwith x(): # type: ignore
	passz$async with x(): # type: ignore
	passTr   rU   r   s     r	   test_type_ignorez UnparseTestCase.test_type_ignore  s?    
 	D 	DI $$Yd$CCCC	D 	Dr3   N)2rN   rO   rP   rW   rY   r]   r_   ra   rc   rf   ri   rl   rn   rr   ry   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   rQ   r3   r	   rS   rS      s       
 
 
*? ? ?8 8 8+ + +
0 0 0, , ,+ + +- - -6 6 61 1 1- - -
 
 
2 2 2( ( (4 4 49 9 9A A A2 2 2. . .- - -+ + +: : :4 4 4
 
 
: : :@ @ @2 2 2M M M( ( (5 5 5: : :5 5 5. . .* * *1 1 1B B B
. . .6H H H
 
 
Q Q Q6 6 6A A A; ; ;(
 
 
F F FD D D D D D D Dr3   rS   c                   N    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd ZdS )CosmeticTestCasezATest if there are cosmetic issues caused by unnecessary additionsc                    |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d	           |                      d
           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           d S )Nz(a := b)zawait xzx if x else yzlambda x: xz1 + 1z	1 + 2 / 3z(1 + 2) / 3z(1 + 2) * 3 + 4 * (5 + 2)z(1 + 2) * 3 + 4 * (5 + 2) ** 2z~xzx and yzx and y and zzx and (y and x)z(x and y) and zz(x ** y) ** z ** qzx >> yzx << yzx >> y and x >> zzx + y - z * q ^ t ** kzP * V if P and V else n * R * Tz"lambda P, V, n: P * V == n * R * Tzflag & (other | foo)z
not x == yzx == (not y)zyield xzyield from xzcall((yield x))zreturn x + (yield x)rI   rV   s    r	   test_simple_expressions_parensz/CosmeticTestCase.test_simple_expressions_parens  sD     ,,,  +++  111  ///  )))  ---  ///  !<===  !ABBB  &&&  +++  111  !2333  !2333  !5666  ***  ***  !4555  !9:::  !BCCC  !EFFF  !7888  ...  000  +++  000  !2333  !788888r3   c                    |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d	           |                      d
           d S )Nzclass X:
    passzclass X(A):
    passzclass X(A, B, C, D):
    passzclass X(x=y):
    passzclass X(metaclass=z):
    passzclass X(x=y, z=d):
    passzclass X(A, x=y):
    passzclass X(A, **kw):
    passzclass X(*args):
    passz"class X(*args, **kwargs):
    passr   rV   s    r	   test_class_bases_and_keywordsz.CosmeticTestCase.test_class_bases_and_keywords  s      !5666  !8999  !ABBB  !:;;;  !BCCC  !?@@@  !=>>>  !>???  !<===  !FGGGGGr3   c                     |                      d           |                      d           |                      d           |                      d           |                      d           d S )Nr[   r\   zf'{x}\n'zf'''{"""
"""}\n'''zf'''{f"""{x}
"""}\n'''r   rV   s    r	   rW   zCosmeticTestCase.test_fstrings  sp      !RSSS  !6777  ---  !=>>>  !ABBBBBr3   c                 Z    d}t           D ] }|D ]}|                     | |            !d S )N)z"""simple doc string"""z7"""A more complex one
            with some newlines"""z,"""Foo bar baz

            empty newline"""z"""With some 	"""z"""Foo "bar" baz """z"""\r"""z""""""z	"""'''"""z"""''''''"""u"   """🐍⛎𩸽üéş^\\X\\BB⟿"""z"""end in single 'quote'"""z'''end in double "quote"'''z#"""almost end in double "quote".""")docstring_prefixesrI   )r,   r   prefixr   s       r	   r   z CosmeticTestCase.test_docstrings%  sa    

& ) 	A 	AF' A A	((F)?I)?)?@@@@A	A 	Ar3   c                     d}t           D ]7}|D ]2}| | }|                     |           |                     |           38d S )N)za = """false"""z("""false""" + """unless its optimized"""z1 + 1
"""false"""z"f"""no, top level but f-fstring""")r  r<   rM   )r,   docstrings_negativer  negativesrcs        r	   test_docstrings_negative_casesz/CosmeticTestCase.test_docstrings_negative_cases=  sv    
 ) 	3 	3F/ 3 3  +++((-----c22223	3 	3r3   c                 z    dD ]}|                      | d           dD ]}|                      | d           d S )N)+-~1)notz 1r   )r,   r  s     r	   test_unary_op_factorz%CosmeticTestCase.test_unary_op_factorO  sd    % 	3 	3F$$\\\2222 	4 	4F$$]]]3333	4 	4r3   c                 R   |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d	           |                      d
           |                      d           |                      d           |                      d           |                      d           d S )Nr   za[1]za[1, 2]za[*a,]za[1, *a]za[*a, 2]za[1, *a, 2]r   za[1, *a, *a]za[*a, 1, *a]za[*a, *a, 1]za[1, *a, *a, 2]z
a[1:2, *a]z
a[*a, 1:2]r   rV   s    r	   r   zCosmeticTestCase.test_slicesU  s#     )))  (((  +++ 	  ***  ,,,  ,,,  ///  ---  000  000  000  !2333  ...  .....r3   c                 V   |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           d S )	Nzlambda: somethingzfour = lambda: 2 + 2zlambda x: x * 2zsquare = lambda n: n ** 2zlambda x, y: x + yzadd = lambda x, y: x + yz lambda x, y, /, z, q, *, u: Nonezlambda x, *y, **z: Noner   rV   s    r	   test_lambda_parametersz'CosmeticTestCase.test_lambda_parametersh  s      !4555  !7888  !2333  !<===  !5666  !;<<<  !CDDD  !:;;;;;r3   c                     dD ]b\  }}dD ]Z}|                      ||          5  |                     |                    |                     d d d            n# 1 swxY w Y   [cd S )N))zsingle assignmentz{target} = foo)zmultiple assignmentz{target} = {target} = bar)zfor loopzfor {target} in foo:
    pass)zasync for loopz#async for {target} in foo:
    pass)r   za,za, bza, *b, cza, (b, c), dza, (b, c, d), *eza, (b, *c, d), eza, (b, *c, (d, e), f), gz[a]z[a, b]z
[a, *b, c]z[a, [b, c], d]z[a, [b, c, d], *e]z[a, [b, *c, d], e]z[a, [b, *c, [d, e], f], g]za, [b, c], dz[a, b, (c, d), (e, f)]za, b, [*c], d, e)source_typetarget)r  )r7   rI   format)r,   r  sourcer  s       r	   test_star_expr_assign_targetz-CosmeticTestCase.test_star_expr_assign_targetr  s    $
 	K 	KK K K( \\k&\II K K,,V]]&]-I-IJJJK K K K K K K K K K K K K K K)K	K 	Ks   *AA Ac                 ,   |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           |                      d           d S )Nz() = []z[] = ()z'() = [a] = c, = [d] = e, f = () = g = hza = b = c = dza, b = c, d = e, f = gz[a, b] = [c, d] = [e, f] = gza, b = [c, d] = e, f = gr   rV   s    r	   %test_star_expr_assign_target_multiplez6CosmeticTestCase.test_star_expr_assign_target_multiple  s      +++  +++  !JKKK  111  !9:::  !?@@@  !;<<<<<r3   N)rN   rO   rP   __doc__r   r   rW   r   r	  r  r   r  r  r  rQ   r3   r	   r   r     s        KK9 9 9<
H 
H 
HC C CA A A03 3 3$4 4 4/ / /&< < <K K K<= = = = =r3   r   c                   x    e Zd ZdZ ej        e          j        dz  Zeedz  fZ	h dZ
dZed             Zd ZdS )DirectoryTestCasez:Test roundtrip behaviour on all files in Lib and Lib/test.z..r   >   test_ast.pytest_patma.pytest_syntax.pytest_compile.pytest_fstring.pytest_grammar.pytest_asdl_parser.pyNc                      j          j         S d  j        D             }t          j                            d          sB fd|D             }t          t          j        |d                    }t          ||z            }| _         |S )Nc                     g | ]H}|                     d           D ]0}|j                            d          |                                1IS )z*.pybad)globr   
startswithresolve).0	directoryitems      r	   
<listcomp>z3DirectoryTestCase.files_to_test.<locals>.<listcomp>  si     
 
 
!v..
 
 9''..	
LLNN
 
 
 
r3   cpuc                 0    h | ]}|j         j        v |S rQ   )r   run_always_files)r,  r.  clss     r	   	<setcomp>z2DirectoryTestCase.files_to_test.<locals>.<setcomp>  s5     #F #F #FD#'90D#D#D $(#D#D#Dr3   
   )	_files_to_testtest_directoriesr   supportis_resource_enabledsetrandomsampler   )r3  itemstests_to_run_alwayss   `  r	   files_to_testzDirectoryTestCase.files_to_test  s     )%%
 
 1
 
 
 |//66 		6#F #F #F #FE #F #F #F eR0011E !4455E #r3   c                 B   |                                  D ]}t          j        j        r$t	          d|                                            |                     |          5  t          |          }|                     |           d d d            n# 1 swxY w Y   d S )NzTesting )r   )	r?  r   r8  verboseprintabsoluter7   r
   r<   )r,   r.  r  s      r	   
test_fileszDirectoryTestCase.test_files  s    &&(( 	1 	1D|# 4222333t,, 1 1$T**((0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1		1 	1s   "%BB	B	)rN   rO   rP   r  pathlibPath__file__parentlib_dirr7  r2  r6  classmethodr?  rD  rQ   r3   r	   r  r    s        DDgl8$$+d2G6!12) ) ) N  [<1 1 1 1 1r3   r  __main__)r  unittesttest.supportr   rE  r;  r   r   r
   re   rh   r   r   r   r   r   r   r   r   r   r   r   r  TestCaser   rS   r   r  rN   mainrQ   r3   r	   <module>rP     s   D D         



  
	
		  


 @. @. @. @. @.(# @. @. @.DiD iD iD iD iDk iD iD iDX	f= f= f= f= f={ f= f= f=T11 11 11 11 11 11 11 11h zHMOOOOO r3   