
    dafn                     H   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dlm	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	ej2                        Z G d de      Z G d de      Z G d dej2                        Z G d de      Zedk(  r ej@                          yy)zTests for ast.unparse.    N)ASTTestMixinc                 x    t        j                  |       5 }|j                         cddd       S # 1 sw Y   yxY w)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     ,/root/Python-3.12.4/Lib/test/test_unparse.pyread_pyfiler      s0     
x	  F{{}  s   09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                   4    e Zd Zd ZefdZddZddZddZy)ASTTestCasec                     | j                  ||      5  t        j                  |fi |}t        j                  |      }t        j                  |fi |}| j	                  ||       d d d        y # 1 sw Y   y xY w)N)code1ast_parse_kwargs)subTestastparseunparseassertASTEqual)selfr   kwargsast1code2ast2s         r
   check_ast_roundtripzASTTestCase.check_ast_roundtrip   sk    \\\? 	,99U-f-DKK%E99U-f-Dd+		, 	, 	,s   AA11A:c                     | j                  |      5  | j                  |t        j                  |       d d d        y # 1 sw Y   y xY w)N)node)r   assertRaisesr   r   )r   r   raisess      r
   check_invalidzASTTestCase.check_invalid   s;    \\t\$ 	9fckk48	9 	9 	9s	   ">ANc                 f    |xs |}t        j                  t        j                  |            }||fS N)r   r   r   r   r   r   s      r
   
get_sourcezASTTestCase.get_source   s,    CIIe,-e|    c                     | j                  ||      \  }}| j                  ||      5  | j                  ||       d d d        y # 1 sw Y   y xY wN)r   r   )r%   r   assertEqualr$   s      r
   check_src_roundtripzASTTestCase.check_src_roundtrip   sK    ue4u\\U\3 	+UE*	+ 	+ 	+   AAc                     | j                  ||      \  }}| j                  ||      5  | j                  ||       d d d        y # 1 sw Y   y xY wr(   )r%   r   assertNotEqualr$   s      r
   check_src_dont_roundtripz$ASTTestCase.check_src_dont_roundtrip   sK    ue4u\\U\3 	.u-	. 	. 	.r+   r#   )	__name__
__module____qualname__r   
ValueErrorr!   r%   r*   r.    r&   r
   r   r      s     , *4 9
+
.r&   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/ Z1d0 Z2y1)2UnparseTestCasec                 $   | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d	       | j                  d
       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y )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   s      (  +  ,  -  -  *  /  ,  /  0  !<=  -  !56  /  1  <	
r&   c                     | j                  d       | j                  d       | j                  d       | j                  d       y )Nzf'{f"{0}"*3}'zf'{f"{y}"*3}'zf''zf"""'end' "quote\""""r7   r8   s    r
   test_fstrings_special_charsz+UnparseTestCase.test_fstrings_special_chars   s=      !56  !56  +  !=>r&   c                     | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y )Nzf'''{"'"}'''z%f'''-{f"""*{f"+{f'.{x}.'}+"}*"""}-'''z4f'''-{f"""*{f"+{f'.{x}.'}+"}*"""}-'single quote\''''zf"""{'''
'''}"""zf"""{g('''
''')}"""z	f"a\r\nb"zf"\u2028{'x'}"r7   r8   s    r
   test_fstrings_complicatedz)UnparseTestCase.test_fstrings_complicated   sk      !34  !RS  !bc  !:;  !=>  !23  !67r&   c                 H    | j                  d       | j                  d       y )Nz0f" something { my_dict["key"] } something else "z!f"{f"{f"{f"{f"{f"{1+1}"}"}"}"}"}"r7   r8   s    r
   test_fstrings_pep701z$UnparseTestCase.test_fstrings_pep701   s       !ST  !DEr&   c                 j    | j                  d       | j                  d       | j                  d       y )Nzu'foo'zr'foo'zb'foo'r7   r8   s    r
   test_stringszUnparseTestCase.test_strings   s,      *  *  *r&   c                 &    | j                  d       y )Nzdel x, y, zr7   r8   s    r
   test_del_statementz"UnparseTestCase.test_del_statement   s      /r&   c                 H    | j                  d       | j                  d       y )Nz45 << 2z13 >> 7r7   r8   s    r
   test_shiftszUnparseTestCase.test_shifts   s      +  +r&   c                 .    | j                  t               y r#   )r   for_elser8   s    r
   test_for_elsezUnparseTestCase.test_for_else   s      *r&   c                 .    | j                  t               y r#   )r   
while_elser8   s    r
   test_while_elsezUnparseTestCase.test_while_else         ,r&   c                     | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y )Nz(-1)**7z(-1.)**8z(-1j)**6znot True or FalsezTrue or not Falser7   r8   s    r
   test_unary_parensz!UnparseTestCase.test_unary_parens   sJ      +  ,  ,  !45  !45r&   c                 &    | j                  d       y )Nz3 .__abs__()r7   r8   s    r
   test_integer_parensz#UnparseTestCase.test_integer_parens   s      0r&   c                     | j                  d       | j                  d       | j                  d       | j                  d       y )N1e1000z-1e10001e1000jz-1e1000jr7   r8   s    r
   test_huge_floatzUnparseTestCase.test_huge_float   s:      *  +  +  ,r&   c                     | j                  t        j                  t        j                  t        j                  t        d                        t        j                  d             y )Nnanvaluez1e1000 - 1e1000)r   r   r   r   Constantfloatr8   s    r
   test_nanzUnparseTestCase.test_nan   s?    IIckk#,,U5\"BCDII'(	
r&   c                 l    | j                  t        d             | j                  t        d             y )Ni   l         )r   strr8   s    r
   test_min_intzUnparseTestCase.test_min_int   s&      Z1  Z1r&   c                     | j                  d       | j                  d       | j                  d       | j                  d       y )N7jz-7j0jz-0jr7   r8   s    r
   test_imaginary_literalsz'UnparseTestCase.test_imaginary_literals   s:      &  '  &  'r&   c                 &    | j                  d       y )Nz(lambda: int)()r7   r8   s    r
   test_lambda_parenthesesz'UnparseTestCase.test_lambda_parentheses         !23r&   c                 H    | j                  d       | j                  d       y )Nz
1 < 4 <= 5za is b is c is not dr7   r8   s    r
   test_chained_comparisonsz(UnparseTestCase.test_chained_comparisons  s      .  !78r&   c                    | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d	       | j                  d
       | j                  d       | j                  d       y )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): passr7   r8   s    r
   test_function_argumentsz'UnparseTestCase.test_function_arguments  s      1  !12  !56  !45  !89  !<=  !?@  !;<  !;<  !IJ  !JK  !?@r&   c                 .    | j                  t               y r#   )r   relative_importr8   s    r
   test_relative_importz$UnparseTestCase.test_relative_import        1r&   c                 .    | j                  t               y r#   )r   nonlocal_exr8   s    r
   test_nonlocalzUnparseTestCase.test_nonlocal        -r&   c                 .    | j                  t               y r#   )r   
raise_fromr8   s    r
   test_raise_fromzUnparseTestCase.test_raise_from  rL   r&   c                 &    | j                  d       y )Nzb'123'r7   r8   s    r
   
test_byteszUnparseTestCase.test_bytes  s      *r&   c                     | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y )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: passr7   r8   s    r
   test_annotationsz UnparseTestCase.test_annotations  sM      !78  !:;  !<=  !>?  !89r&   c                 &    | j                  d       y )Nz{'a', 'b', 'c'}r7   r8   s    r
   test_set_literalz UnparseTestCase.test_set_literal&  re   r&   c           	          | j                  t        j                  t        j                  t        j                  g                   t        j                  d             y )N)eltsz{*()})r   r   r   r   Setr8   s    r
   test_empty_setzUnparseTestCase.test_empty_set)  s:    IIckk#''r"234IIg	
r&   c                 &    | j                  d       y )Nz{x for x in range(5)}r7   r8   s    r
   test_set_comprehensionz&UnparseTestCase.test_set_comprehension/  s      !89r&   c                 &    | j                  d       y )Nz{x: x*x for x in range(10)}r7   r8   s    r
   test_dict_comprehensionz'UnparseTestCase.test_dict_comprehension2  s      !>?r&   c                 .    | j                  t               y r#   )r   class_decoratorr8   s    r
   test_class_decoratorsz%UnparseTestCase.test_class_decorators5  rm   r&   c                 &    | j                  d       y )Nz(class A(metaclass=type, *[], **{}): passr7   r8   s    r
   test_class_definitionz%UnparseTestCase.test_class_definition8  s      !KLr&   c                 X    | j                  t               | j                  t               y r#   )r   elif1elif2r8   s    r
   
test_elifszUnparseTestCase.test_elifs;  s      '  'r&   c                 .    | j                  t               y r#   )r   try_except_finallyr8   s    r
   test_try_except_finallyz'UnparseTestCase.test_try_except_finally?  s      !34r&   c                 .    | j                  t               y r#   )r   try_except_star_finallyr8   s    r
   test_try_except_star_finallyz,UnparseTestCase.test_try_except_star_finallyB  s      !89r&   c                     | j                  d       | j                  d       | j                  d       | j                  d       y )Nza, *b, c = seqza, (*b, c) = seqza, *b[0], c = seqza, *(b, c) = seqr7   r8   s    r
   test_starred_assignmentz'UnparseTestCase.test_starred_assignmentE  s>      !12  !34  !45  !34r&   c                 .    | j                  t               y r#   )r   with_simpler8   s    r
   test_with_simplez UnparseTestCase.test_with_simpleK  rq   r&   c                 .    | j                  t               y r#   )r   with_asr8   s    r
   test_with_aszUnparseTestCase.test_with_asN  s      )r&   c                 .    | j                  t               y r#   )r   with_two_itemsr8   s    r
   test_with_two_itemsz#UnparseTestCase.test_with_two_itemsQ  s      0r&   c                 H    | j                  d       | j                  d       y )Nz{**{'y': 2}, 'x': 1}z{**{'y': 2}, **{'x': 1}}r7   r8   s    r
   test_dict_unpacking_in_dictz+UnparseTestCase.test_dict_unpacking_in_dictT  s       !<=  !@Ar&   c                 4   | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d	       | j                  d
       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y )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]r7   r8   s    r
   test_sliceszUnparseTestCase.test_slicesY  sS     (  )  +  ,  )  ,  ,  /  -  0  0  0  !23  -  /  )  *  )  )  ,  +  +  +  -r&   c                 x    | j                  t        j                  d t        j                  d                   y )NXid)exccause)r!   r   RaiseNamer8   s    r
   test_invalid_raisez"UnparseTestCase.test_invalid_raiset  s$    399SXX5EFGr&   c                     | j                  t        j                  t        j                  d      t        j                  d      g             y )Ntestr   rW   )values)r!   r   	JoinedStrr   rY   r8   s    r
   test_invalid_fstring_valuez*UnparseTestCase.test_invalid_fstring_valuew  s9    MMHH'LLv.	
r&   c           	          | j                  t        j                  t        j                  t        j                  d      dd             d       y )Nz\\rW   )rX   
conversionformat_specz{'\\\\'})r)   r   r   FormattedValuerY   r8   s    r
   test_fstring_backslashz&UnparseTestCase.test_fstring_backslash  s@    ..&)ll&@+-,0 *	+r&   c                 N    | j                  t        j                  d              y )NrW   )r!   r   	YieldFromr8   s    r
   test_invalid_yield_fromz'UnparseTestCase.test_invalid_yield_from  s    3==t45r&   c                 J   t        j                  dt        j                  d      g      }| j                  t        j                  |      d       t        j                  dt        j                  d      gd       }| j                  t        j                  |      d       y )Nmodx)name)modulenameszfrom mod import x)r   r   level)r   
ImportFromaliasr)   r   )r   trees     r
   test_import_from_level_nonez+UnparseTestCase.test_import_from_level_none  sp    ~~U399#3F2GHT*,?@~~U399#3F2GtTT*,?@r&   c                 @    d}|D ]  }| j                  d| d        y )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'''r7   )r   
docstrings	docstrings      r
   test_docstringszUnparseTestCase.test_docstrings  s1    

 $ 	;I$$s9+S%9:	;r&   c                     | j                  t        j                  dd       d       | j                  t        j                  dd       d       y )N)   )rX   kindz(1,))r         z	(1, 2, 3))r*   r   rY   r8   s    r
   test_constant_tuplesz$UnparseTestCase.test_constant_tuples  s;      Dt!DfM  LLyt4k	
r&   c                 8    dD ]  }| j                  |d        y )N)z	() -> intz(int, int) -> intz=(Callable[complex], More[Complex(call.to_typevar())]) -> None	func_type)moder7   )r   function_types     r
   test_function_typez"UnparseTestCase.test_function_type  s*    
 	FM
 $$]$E	Fr&   c                 8    dD ]  }| j                  |d        y )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_commentsr7   r   	statements     r
   test_type_commentsz"UnparseTestCase.test_type_comments  s*    
 	DI $$Yd$C	Dr&   c                 8    dD ]  }| j                  |d        y )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   r7   r   s     r
   test_type_ignorez UnparseTestCase.test_type_ignore  s*    
 	DI $$Yd$C	Dr&   N)3r/   r0   r1   r9   r;   r=   r?   rA   rC   rE   rH   rK   rN   rP   rT   r[   r^   rb   rd   rg   ri   rl   rp   rt   rv   rx   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   r3   r&   r
   r5   r5      s    
*?8F+
0,+-61-
2(49A2.-+:4
:@2M(5:5.*1B
.6H
+6A;(
FD Dr&   r5   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y)CosmeticTestCasezATest if there are cosmetic issues caused by unnecessary additionsc                    | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d	       | j                  d
       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y )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)r*   r8   s    r
   test_simple_expressions_parensz/CosmeticTestCase.test_simple_expressions_parens  s     ,  +  1  /  )  -  /  !<=  !AB  &  +  1  !23  !23  !56  *  *  !45  !9:  !BC  !EF  !78  .  0  +  0  !23  !78r&   c                 X   | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d	       | j                  d
       y )N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   r8   s    r
   test_class_bases_and_keywordsz.CosmeticTestCase.test_class_bases_and_keywords  s      !56  !89  !AB  !:;  !BC  !?@  !=>  !>?  !<=  !FGr&   c                     | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y )Nzf'-{f'*{f'+{f'.{x}.'}+'}*'}-'zf'\u2028{'x'}'zf'{x}\n'zf'{'\n'}\n'zf'{f'{x}\n'}\n'r   r8   s    r
   r9   zCosmeticTestCase.test_fstrings  sK      !@A  !23  -  1  !45r&   c                 V    d}t         D ]  }|D ]  }| j                  | |           y )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_prefixesr*   )r   r   prefixr   s       r
   r   z CosmeticTestCase.test_docstrings
  sD    

& ) 	AF' A	((F8I;)?@A	Ar&   c                 |    d}t         D ]1  }|D ]*  }| | }| j                  |       | j                  |       , 3 y )N)za = """false"""z("""false""" + """unless its optimized"""z1 + 1
"""false"""z"f"""no, top level but f-fstring""")r   r   r.   )r   docstrings_negativer   negativesrcs        r
   test_docstrings_negative_casesz/CosmeticTestCase.test_docstrings_negative_cases"  sV    
 ) 	3F/ 3  
+((---c23	3r&   c                 p    dD ]  }| j                  | d        dD ]  }| j                  | d        y )N)+-~1)notz 1r   )r   r   s     r
   test_unary_op_factorz%CosmeticTestCase.test_unary_op_factor4  sH    % 	3F$$xq\2	3 	4F$$xr]3	4r&   c                    | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d	       | j                  d
       | j                  d       | j                  d       | j                  d       | j                  d       y )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   r8   s    r
   r   zCosmeticTestCase.test_slices:  s      )  (  + 	  *  ,  ,  /  -  0  0  0  !23  .  .r&   c                    | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y )	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   r8   s    r
   test_lambda_parametersz'CosmeticTestCase.test_lambda_parametersM  sz      !45  !78  !23  !<=  !56  !;<  !CD  !:;r&   c                     dD ]I  \  }}dD ]?  }| j                  ||      5  | j                  |j                  |             d d d        A K y # 1 sw Y   NxY w)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)az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   )r   r*   format)r   r   sourcer   s       r
   test_star_expr_assign_targetz-CosmeticTestCase.test_star_expr_assign_targetW  sw    $
 	KK K( \\k&\I K,,V]]&]-IJK K)K	K4K Ks   "AAc                     | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y )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   r8   s    r
   %test_star_expr_assign_target_multiplez6CosmeticTestCase.test_star_expr_assign_target_multipleu  sh      +  +  !JK  1  !9:  !?@  !;<r&   c                 X   | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d	       | j                  d
       y )Nzf"'''{1}\"\"\"" zf"'''{1}""\"" zf'"""{1}''' zf'"""{1}""\"' zf"'''{"\n"}""\"" zf'"""{"\n"}''' zf'"""{"\n"}""\"' zf'''"""''\'{"\n"}''' zf'''"""''\'{"\n\"'"}''' z'f'''"""''\'{"""\n\"'''""" '''\n'''}''' r7   r8   s    r
   test_multiquote_joined_stringz.CosmeticTestCase.test_multiquote_joined_string~  s      !;<  !67  !45  !78  !:;  !89  !;<  !?@  !CD  !UVr&   c                    dd l }|j                  d      }| j                  t        |      5  | j	                  d       d d d        | j	                  d       | j	                  d       | j                  t        |      5  | j	                  d       d d d        | j	                  d       | j	                  d       y # 1 sw Y   ~xY w# 1 sw Y   8xY w)	Nr   zinvalid escape sequence '\ 'z
f"{x:\ }" z
f"{x:\n}" zf"{x:\\ }" zf"{x:\\\ }" zf"{x:\\\n}" zf"{x:\\\\ }" )reescapeassertWarnsRegexSyntaxWarningr   )r   r  msgs      r
   test_backslash_in_format_specz.CosmeticTestCase.test_backslash_in_format_spec  s    ii78""=#6 	8$$%67	8  !23  !45""=#6 	<$$%:;	<  !67  !89	8 	8	< 	<s   B;>C;CCc                     | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y )Nz	f"{x:'}" z
f"{x:\'}" zf"{x:\\'}" zf'\'{x:"}' zf'\'{x:\"}' zf'\'{x:\\"}' r7   r8   s    r
   test_quote_in_format_specz*CosmeticTestCase.test_quote_in_format_spec  s[      1  !23  !45  !34  !56  !78r&   N)r/   r0   r1   __doc__r   r   r9   r   r   r   r   r   r   r  r  r  r  r3   r&   r
   r   r     sJ    K9<
H6A03$4/&<K<=W:9r&   r   c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
ManualASTCreationTestCasezJTest that AST nodes created without a type_params field unparse correctly.c                     t        j                  dg g t        j                         gg       }t        j                  |       | j	                  t        j
                  |      d       y )Nr   )r   baseskeywordsbodydecorator_listr   )r   ClassDefPassfix_missing_locationsr)   r   r   r   s     r
   
test_classz$ManualASTCreationTestCase.test_class  sI    ||B388:,_ab!!$'T*,@Ar&   c           
          t        j                  dg g t        j                         gg t        j                  d      g      }t        j                  |       | j                  t        j                  |      d       y )Nr   T)r   r  r  r  r  type_paramszclass X[T]:
    pass)r   r  r  TypeVarr  r)   r   r  s     r
   test_class_with_type_paramsz5ManualASTCreationTestCase.test_class_with_type_params  sZ    ||B388:,_a*-++c*:);=!!$'T*,CDr&   c                    t        j                  dt        j                  g g d g g d g       t        j                         gg d       }t        j                  |       | j                  t        j                  |      d       y )Nfposonlyargsargsvararg
kwonlyargskw_defaultskwargdefaultsr   r$  r  r  returnszdef f():
    pass)r   FunctionDef	argumentsr  r  r)   r   r  s     r
   test_functionz'ManualASTCreationTestCase.test_function  sj    2BtPR`bjny{|((*
 	!!$'T*,@Ar&   c                 0   t        j                  dt        j                  g g d g g d g       t        j                         gg d t        j                  d      g      }t        j
                  |       | j                  t        j                  |      d       y )Nr!  r"  r  r   r$  r  r  r+  r  zdef f[T]():
    pass)r   r,  r-  r  r  r  r)   r   r  s     r
   test_function_with_type_paramsz8ManualASTCreationTestCase.test_function_with_type_params  sy    2BtPR`bjny{|((*S)*
 	!!$'T*,CDr&   c                 Z   t        j                  dt        j                  g g d g g d g       t        j                         gg d t        j                  dt        j
                  d            g      }t        j                  |       | j                  t        j                  |      d       y )Nr!  r"  r  int)boundr0  zdef f[T: int]():
    pass)	r   r,  r-  r  r  r   r  r)   r   r  s     r
   (test_function_with_type_params_and_boundzBManualASTCreationTestCase.test_function_with_type_params_and_bound  s    2BtPR`bjny{|((*S@A
 	!!$'T*,HIr&   c                    t        j                  dt        j                  g g d g g d g       t        j                         gg d       }t        j                  |       | j                  t        j                  |      d       y )Nr!  r"  r*  zasync def f():
    pass)r   AsyncFunctionDefr-  r  r  r)   r   r  s     r
   test_async_functionz-ManualASTCreationTestCase.test_async_function  sl    ##2BtPR`bjny{|((*
 	!!$'T*,FGr&   c                 0   t        j                  dt        j                  g g d g g d g       t        j                         gg d t        j                  d      g      }t        j
                  |       | j                  t        j                  |      d       y )Nr!  r"  r  r0  zasync def f[T]():
    pass)r   r7  r-  r  r  r  r)   r   r  s     r
   $test_async_function_with_type_paramsz>ManualASTCreationTestCase.test_async_function_with_type_params  s{    ##2BtPR`bjny{|((*S)*
 	!!$'T*,IJr&   N)r/   r0   r1   r  r  r  r.  r1  r5  r8  r:  r3   r&   r
   r  r    s/    TB
E	B
E
J	H
Kr&   r  c                   ~    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y)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_tokenize.pytest_type_alias.pytest_asdl_parser.pytest_type_params.pyNc                    | j                   | j                   S | j                  D cg c]C  }|j                  d      D ]-  }|j                  j	                  d      s|j                         / E }}}t        j                  j                  d      sT|D ch c]  }|j                  | j                  v r| }}t        t        j                  |d            }t        ||z        }|| _         |S c c}}w c c}w )Nz*.pybadcpu
   )_files_to_testtest_directoriesglobr   
startswithresolver   supportis_resource_enabledrun_always_filessetrandomsamplelist)cls	directoryitemitemstests_to_run_alwayss        r
   files_to_testzDirectoryTestCase.files_to_test  s     )%%% !11
!v.
 99''. LLN

 
 ||//649 #FD#'990D0D#D $( #F #F eR01E !445E #/
#Fs   AC/!C5c                     | j                         D ]o  }t        j                  j                  rt	        d|j                                 | j                  |      5  t        |      }| j                  |       d d d        q y # 1 sw Y   |xY w)NzTesting )r   )	r\  r   rP  verboseprintabsoluter   r   r   )r   rY  r   s      r
   
test_fileszDirectoryTestCase.test_files  s}    &&( 	1D||## 123t, 1$T*((01 1		11 1s   BB	)r/   r0   r1   r  pathlibPath__file__parentlib_dirrL  rR  rK  classmethodr\  ra  r3   r&   r
   r<  r<    sV    Dgll8$++d2G6!12,
 N <1r&   r<  __main__)!r  unittesttest.supportr   rb  rT  r   r   test.support.ast_helperr   r   rG   rJ   rk   ro   rs   r   r   r   r   r   r   r   r   r   TestCaser   r5   r   r  r<  r/   mainr3   r&   r
   <module>rn     s          
 0
	
		  


 ., 1 1 .6tDk tDn	L9{ L9^FK 1 1 FKR21 21j zHMMO r&   