a 5êdgéHã@sÂddlZddlZddlZddlZddlZddlZdd„ZdZdZ dZ dZ dZ d Z d Zd Zd Zd ZdZdZdZGdd„dejƒZGdd„deƒZGdd„deƒZGdd„deƒZedkr¾e ¡dS)éNcCs6t |¡}| ¡WdƒS1s(0YdS©N)ÚtokenizeÚopenÚread)ÚfilenameÚstream©rú-/usr/local/lib/python3.9/test/test_unparse.pyÚ read_pyfile s r 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 zwith f(): suite1 zwith f() as x: suite1 z$with f() as x, g() as y: suite1 )Úzclass foo: zdef foo(): zasync def foo(): c@sFeZdZdd„Zdd„Zefdd„Zddd „Zdd d „Zdd d „Z dS)Ú ASTTestCasecCs| t |¡t |¡¡dSr)Ú assertEqualÚastÚdump)ÚselfÚast1Úast2rrr ÚassertASTEqualwszASTTestCase.assertASTEqualcKsl|j||dJtj|fi|¤Ž}t |¡}tj|fi|¤Ž}| ||¡Wdƒn1s^0YdS)N)Úcode1Zast_parse_kwargs)ÚsubTestrÚparseÚunparser)rrÚkwargsrÚcode2rrrr Úcheck_ast_roundtripzs  zASTTestCase.check_ast_roundtripcCs@|j|d | |tj|¡Wdƒn1s20YdS)N)Únode)rZ assertRaisesrr)rrZraisesrrr Ú check_invalidszASTTestCase.check_invalidNcCs |p|}t t |¡¡}||fSr)rrr©rrrrrr Ú get_source…szASTTestCase.get_sourcecCsN| ||¡\}}|j||d| ||¡Wdƒn1s@0YdS©N)rr)rrr rrrr Úcheck_src_roundtripŠszASTTestCase.check_src_roundtripcCsN| ||¡\}}|j||d| ||¡Wdƒn1s@0YdSr)rrZassertNotEqualrrrr Úcheck_src_dont_roundtripsz$ASTTestCase.check_src_dont_roundtrip)N)N)N) Ú__name__Ú __module__Ú __qualname__rrÚ ValueErrorrrr r!rrrr r vs    r c@steZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5d6„Zd7d8„Zd9d:„Zd;d<„Z d=d>„Z!d?d@„Z"dAdB„Z#dCdD„Z$dEdF„Z%dGdH„Z&dIdJ„Z'dKdL„Z(dMdN„Z)dOdP„Z*dQdR„Z+dSdT„Z,dUdV„Z-dWdX„Z.dYdZ„Z/d[S)\ÚUnparseTestCasecCs,| d¡| d¡| d¡| d¡dS)Nz f'{f"{0}"*3}'z f'{f"{y}"*3}'zf''zf"""'end' "quote\""""©r©rrrr Ú test_fstrings—s   zUnparseTestCase.test_fstringscCsJ| d¡| d¡| d¡| d¡| d¡| d¡| d¡dS)Nz f'''{"'"}'''ú%f'''-{f"""*{f"+{f'.{x}.'}+"}*"""}-'''z4f'''-{f"""*{f"+{f'.{x}.'}+"}*"""}-'single quote\''''zf"""{''' '''}"""zf"""{g(''' ''')}"""z f"a\r\nb"úf"\u2028{'x'}"r'r(rrr Útest_fstrings_complicatedžs      z)UnparseTestCase.test_fstrings_complicatedcCs"| d¡| d¡| d¡dS)Nzu'foo'zr'foo'zb'foo'r'r(rrr Ú test_strings¨s  zUnparseTestCase.test_stringscCs| d¡dS)Nz del x, y, zr'r(rrr Útest_del_statement­sz"UnparseTestCase.test_del_statementcCs| d¡| d¡dS)Nz45 << 2z13 >> 7r'r(rrr Ú test_shifts°s zUnparseTestCase.test_shiftscCs| t¡dSr)rÚfor_elser(rrr Ú test_for_else´szUnparseTestCase.test_for_elsecCs| t¡dSr)rÚ while_elser(rrr Útest_while_else·szUnparseTestCase.test_while_elsecCs6| d¡| d¡| d¡| d¡| d¡dS)Nz(-1)**7z(-1.)**8z(-1j)**6znot True or FalsezTrue or not Falser'r(rrr Útest_unary_parensºs     z!UnparseTestCase.test_unary_parenscCs| d¡dS)Nz 3 .__abs__()r'r(rrr Útest_integer_parensÁsz#UnparseTestCase.test_integer_parenscCs,| d¡| d¡| d¡| d¡dS)NZ1e1000z-1e1000Z1e1000jz-1e1000jr'r(rrr Útest_huge_floatÄs   zUnparseTestCase.test_huge_floatc Cs.| t t tjtdƒd¡¡t d¡¡dS)NÚnan©Úvaluez1e1000 - 1e1000)rrrrÚConstantÚfloatr(rrr Útest_nanÊsþzUnparseTestCase.test_nancCs | tdƒ¡| tdƒ¡dS)Ni€lûÿÿÿ)rÚstrr(rrr Ú test_min_intÐszUnparseTestCase.test_min_intcCs,| d¡| d¡| d¡| d¡dS)NZ7jz-7jZ0jz-0jr'r(rrr Útest_imaginary_literalsÔs   z'UnparseTestCase.test_imaginary_literalscCs| d¡dS)Nz(lambda: int)()r'r(rrr Útest_lambda_parenthesesÚsz'UnparseTestCase.test_lambda_parenthesescCs| d¡| d¡dS)Nz 1 < 4 <= 5za is b is c is not dr'r(rrr Útest_chained_comparisonsÝs z(UnparseTestCase.test_chained_comparisonscCs|| d¡| d¡| d¡| d¡| d¡| d¡| d¡| d¡| d ¡| d ¡| d ¡| d ¡dS) Nz def f(): passzdef f(a): passzdef f(b = 2): passzdef f(a, b): passzdef f(a, b = 2): passzdef f(a = 5, b = 2): passzdef f(*, a = 1, b = 2): passzdef f(*, a = 1, b): passzdef f(*, a, b = 2): passz&def f(a, b = None, *, c, **kwds): passz'def f(a=2, *args, c=5, d, **kwds): passzdef f(*args, **kwargs): passr'r(rrr Útest_function_argumentsás           z'UnparseTestCase.test_function_argumentscCs| t¡dSr)rÚrelative_importr(rrr Útest_relative_importïsz$UnparseTestCase.test_relative_importcCs| t¡dSr)rÚ nonlocal_exr(rrr Ú test_nonlocalòszUnparseTestCase.test_nonlocalcCs| t¡dSr)rÚ raise_fromr(rrr Útest_raise_fromõszUnparseTestCase.test_raise_fromcCs| d¡dS)Nzb'123'r'r(rrr Ú test_bytesøszUnparseTestCase.test_bytescCs6| d¡| d¡| d¡| d¡| d¡dS)Nzdef f(a : int): passzdef f(a: int = 5): passzdef f(*args: [int]): passzdef f(**kwargs: dict): passzdef f() -> None: passr'r(rrr Útest_annotationsûs     z UnparseTestCase.test_annotationscCs| d¡dS)Nz{'a', 'b', 'c'}r'r(rrr Útest_set_literalsz UnparseTestCase.test_set_literalc Cs*| t t tjgd¡¡t d¡¡dS)N)Úeltsz{*()})rrrrÚSetr(rrr Útest_empty_setsþzUnparseTestCase.test_empty_setcCs| d¡dS)Nz{x for x in range(5)}r'r(rrr Útest_set_comprehension sz&UnparseTestCase.test_set_comprehensioncCs| d¡dS)Nz{x: x*x for x in range(10)}r'r(rrr Útest_dict_comprehensionsz'UnparseTestCase.test_dict_comprehensioncCs| t¡dSr)rÚclass_decoratorr(rrr Útest_class_decoratorssz%UnparseTestCase.test_class_decoratorscCs| d¡dS)Nz(class A(metaclass=type, *[], **{}): passr'r(rrr Útest_class_definitionsz%UnparseTestCase.test_class_definitioncCs| t¡| t¡dSr)rÚelif1Úelif2r(rrr Ú test_elifss zUnparseTestCase.test_elifscCs| t¡dSr)rÚtry_except_finallyr(rrr Útest_try_except_finallysz'UnparseTestCase.test_try_except_finallycCs,| d¡| d¡| d¡| d¡dS)Nza, *b, c = seqza, (*b, c) = seqza, *b[0], c = seqza, *(b, c) = seqr'r(rrr Útest_starred_assignments   z'UnparseTestCase.test_starred_assignmentcCs| t¡dSr)rÚ with_simpler(rrr Útest_with_simple$sz UnparseTestCase.test_with_simplecCs| t¡dSr)rÚwith_asr(rrr Ú test_with_as'szUnparseTestCase.test_with_ascCs| t¡dSr)rÚwith_two_itemsr(rrr Útest_with_two_items*sz#UnparseTestCase.test_with_two_itemscCs| d¡| d¡dS)Nz{**{'y': 2}, 'x': 1}z{**{'y': 2}, **{'x': 1}}r'r(rrr Útest_dict_unpacking_in_dict-s z+UnparseTestCase.test_dict_unpacking_in_dictcCsš| d¡| d¡| d¡| d¡| d¡| d¡| d¡| d¡| d ¡| d ¡| d ¡| d ¡| d ¡| d¡| d¡dS)Nza[i]za[i,]za[i, j]za[(*a,)]z a[(a:=b)]z a[(a:=b,c)]za[()]za[i:j]za[:j]za[i:]za[i:j:k]za[:j:k]za[i::k]za[i:j,]z a[i:j, k]r'r(rrr Ú test_slices2s              zUnparseTestCase.test_slicescCs | tjdtjddd¡dS)NÚX)Úid)ÚexcÚcause)rrZRaiseÚNamer(rrr Útest_invalid_raiseCsz"UnparseTestCase.test_invalid_raisecCs | tjtjddgd¡dS)Nédr8)Úvalues)rrZ JoinedStrr:r(rrr Útest_invalid_fstring_constantFsz-UnparseTestCase.test_invalid_fstring_constantcCs(| tjtjdddtdƒdd¡dS)NÚa©r9ÚkindÚY)r9Ú conversionÚ format_spec)rrÚFormattedValuer:Úordr(rrr Útest_invalid_fstring_conversionIs ýÿz/UnparseTestCase.test_invalid_fstring_conversioncCs| tjtjddd¡dS)Nz\\r8)rrrqr:r(rrr Útest_invalid_fstring_backslashRsz.UnparseTestCase.test_invalid_fstring_backslashcCs| tjdd¡dS)Nr8)rrZ YieldFromr(rrr Útest_invalid_yield_fromUsz'UnparseTestCase.test_invalid_yield_fromcCs$d}|D]}| d|›d¡qdS)N) zthis 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'''r')rÚ docstringsÚ docstringrrr Útest_docstringsXszUnparseTestCase.test_docstringscCs0| tjdddd¡| tjdddd¡dS)N)érlz(1,))r|ééz (1, 2, 3))r rr:r(rrr Útest_constant_tupleslsÿz$UnparseTestCase.test_constant_tuplescCsdD]}|j|ddqdS)N)z () -> intz(int, int) -> intz=(Callable[complex], More[Complex(call.to_typevar())]) -> NoneZ func_type)Úmoder')rZ function_typerrr Útest_function_typersz"UnparseTestCase.test_function_typecCsdD]}|j|ddqdS)N) z a = 5 # type:za = 5 # type: intza = 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 passzfor x in y: # type: int passz#async for x in y: # type: int passzwith x(): # type: int passz!async with x(): # type: int passT©Z type_commentsr'©rZ statementrrr Útest_type_commentszs z"UnparseTestCase.test_type_commentscCsdD]}|j|ddqdS)N) za = 5 # type: ignoreza = 5 # type: ignore and morezdef 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 passzwith x(): # type: ignore passz$async with x(): # type: ignore passTr‚r'rƒrrr Útest_type_ignoreŠs z UnparseTestCase.test_type_ignoreN)0r"r#r$r)r,r-r.r/r1r3r4r5r6r<r>r?r@rArBrDrFrHrIrJrKrNrOrPrRrSrVrXrYr[r]r_r`rargrjrsrtrur{rrr„r…rrrr r&”sZ  r&c@sDeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dS)ÚCosmeticTestCasecCs| 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¡dS)Nz(a := b)zawait xz x if x else yz lambda x: xz1 + 1z 1 + 2 / 3z (1 + 2) / 3z(1 + 2) * 3 + 4 * (5 + 2)z(1 + 2) * 3 + 4 * (5 + 2) ** 2z~xzx and yz x and y and zzx and (y and x)z(x and y) and zz(x ** y) ** z ** qzx >> yzx << yzx >> y and x >> zzx + y - z * q ^ t ** kzP * V if P and V else n * R * Tz"lambda P, V, n: P * V == n * R * Tzflag & (other | foo)z not x == yz x == (not y)zyield xz yield from xzcall((yield x))zreturn x + (yield x)©r r(rrr Útest_simple_expressions_parenss8                           z/CosmeticTestCase.test_simple_expressions_parenscCsh| d¡| d¡| d¡| d¡| d¡| d¡| d¡| d¡| d ¡| d ¡dS) Nzclass X: passzclass X(A): passzclass X(A, B, C, D): passzclass X(x=y): passzclass X(metaclass=z): passzclass X(x=y, z=d): passzclass X(A, x=y): passzclass X(A, **kw): passzclass X(*args): passz"class X(*args, **kwargs): passr‡r(rrr Útest_class_bases_and_keywords»s         z.CosmeticTestCase.test_class_bases_and_keywordscCs6| d¡| d¡| d¡| d¡| d¡dS)Nr*r+zf'{x}\n'zf'''{""" """}\n'''zf'''{f"""{x} """}\n'''r‡r(rrr r)Çs     zCosmeticTestCase.test_fstringscCs.d}tD] }|D]}| |›|›¡qqdS)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 )rryÚprefixrzrrr r{Îsz CosmeticTestCase.test_docstringscCs<d}tD].}|D]$}|›|›}| |¡| |¡qqdS)N)za = """false"""z("""false""" + """unless its optimized"""z1 + 1 """false"""z"f"""no, top level but f-fstring""")rŠrr!)rZdocstrings_negativer‹ÚnegativeÚsrcrrr Útest_docstrings_negative_casesæs   z/CosmeticTestCase.test_docstrings_negative_casescCs8dD]}| |›d¡qdD]}| |›d¡qdS)N)ú+ú-ú~Ú1)Únotz 1r‡)rr‹rrr Útest_unary_op_factorøsz%CosmeticTestCase.test_unary_op_factorcCs"| d¡| d¡| d¡dS)Nza[1]za[1, 2]z a[(1, *a)]r‡r(rrr raþs  zCosmeticTestCase.test_slicesN) r"r#r$rˆr‰r)r{rŽr”rarrrr r†šs r†c@sHeZdZe e¡jdZeedfZhd£Z dZ e dd„ƒZ dd„Z dS) ÚDirectoryTestCasez..Útest>ztest_compile.pyz test_ast.pyztest_asdl_parser.pyztest_syntax.pyztest_fstring.pyztest_grammar.pyNcsdˆjdurˆjSdd„ˆjDƒ}tj d¡sZ‡fdd„|Dƒ}tt |d¡ƒ}t||Bƒ}|ˆ_|S)NcSs0g|](}| d¡D]}|j d¡s| ¡‘qqS)z*.pyZbad)ÚglobÚnameÚ startswithÚresolve)Ú.0Z directoryÚitemrrr Ú s ýz3DirectoryTestCase.files_to_test..Zcpucsh|]}|jˆjvr|’qSr)r˜Úrun_always_files)r›rœ©Úclsrr Ú s ÿz2DirectoryTestCase.files_to_test..é ) Ú_files_to_testÚtest_directoriesr–ÚsupportZis_resource_enabledÚsetÚrandomÚsampleÚlist)r ÚitemsZtests_to_run_alwaysrrŸr Ú files_to_test s þ  zDirectoryTestCase.files_to_testc Csj| ¡D]\}tjjr&td| ¡›ƒ|j|d"t|ƒ}| |¡Wdƒq1sZ0YqdS)NzTesting )r) r«r–r¥ÚverboseÚprintÚabsoluterr r)rrœÚsourcerrr Ú test_files,s  zDirectoryTestCase.test_files)r"r#r$ÚpathlibÚPathÚ__file__ÚparentZlib_dirr¤ržr£Ú classmethodr«r°rrrr r•s  r•Ú__main__)ZunittestZ test.supportr–r±r§rrr r0r2rCrErGrQrTrUrWrZr\r^rŠZTestCaser r&r†r•r"Úmainrrrr Ús6     i3