Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 52.14.144.75
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_unparse.cpython-310.pyc
o

abI�@s�dZddlZddlZddlZddlZddlZddlZdd�ZdZ	dZ
dZdZd	Z
d
ZdZdZd
ZdZdZdZdZGdd�dej�ZGdd�de�ZGdd�de�ZGdd�de�Zedkrce��dSdS)z>Tests for the unparse.py script in the Tools/parser directory.�NcCs6t�|��}|��Wd�S1swYdS)znRead and return the contents of a Python source file (as a
    string), taking into account the file encoding.N)�tokenize�open�read)�filename�stream�r�:/usr/local/python-3.10/lib/python3.10/test/test_unparse.py�read_pyfiles$�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�|��dS�N)�assertEqual�ast�dump)�self�ast1�ast2rrr�assertASTEqualwszASTTestCase.assertASTEqualcKsn|j||d��&tj|fi|��}t�|�}tj|fi|��}|�||�Wd�dS1s0wYdS)N)�code1Zast_parse_kwargs)�subTestr�parse�unparser)rr�kwargsr�code2rrrr�check_ast_roundtripzs
"�zASTTestCase.check_ast_roundtripcCsB|j|d��|�|tj|�Wd�dS1swYdS)N)�node)rZassertRaisesrr)rrZraisesrrr�
check_invalid�s"�zASTTestCase.check_invalidNcCs |p|}t�t�|��}||fSr)rrr�rrrrrr�
get_source�szASTTestCase.get_sourcecC�P|�||�\}}|j||d��|�||�Wd�dS1s!wYdS�N)rr)rrr
rrrr�check_src_roundtrip��"�zASTTestCase.check_src_roundtripcCrr )rrZassertNotEqualrrrr�check_src_dont_roundtrip�r"z$ASTTestCase.check_src_dont_roundtripr)
�__name__�
__module__�__qualname__rr�
ValueErrorrrr!r#rrrrrvs

rc@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�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)\�UnparseTestCasecC�,|�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_complicatedcC�"|�d�|�d�|�d�dS)Nzu'foo'zr'foo'zb'foo'r*r+rrr�test_strings��

zUnparseTestCase.test_stringscC�|�d�dS)Nzdel x, y, zr*r+rrr�test_del_statement��z"UnparseTestCase.test_del_statementcC�|�d�|�d�dS)Nz45 << 2z13 >> 7r*r+rrr�test_shifts��
zUnparseTestCase.test_shiftscC�|�t�dSr)r�for_elser+rrr�
test_for_else�r5zUnparseTestCase.test_for_elsecCr9r)r�
while_elser+rrr�test_while_else�r5zUnparseTestCase.test_while_elsecC�6|�d�|�d�|�d�|�d�|�d�dS)Nz(-1)**7z(-1.)**8z(-1j)**6znot True or FalsezTrue or not Falser*r+rrr�test_unary_parens��




z!UnparseTestCase.test_unary_parenscCr3)Nz3 .__abs__()r*r+rrr�test_integer_parens�r5z#UnparseTestCase.test_integer_parenscCr))NZ1e1000z-1e1000Z1e1000jz-1e1000jr*r+rrr�test_huge_float��


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_intcCr))NZ7jz-7jZ0jz-0jr*r+rrr�test_imaginary_literals�rCz'UnparseTestCase.test_imaginary_literalscCr3)Nz(lambda: int)()r*r+rrr�test_lambda_parentheses�r5z'UnparseTestCase.test_lambda_parenthesescCr6)Nz
1 < 4 <= 5za is b is c is not dr*r+rrr�test_chained_comparisons�r8z(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_argumentscCr9r)r�relative_importr+rrr�test_relative_import�r5z$UnparseTestCase.test_relative_importcCr9r)r�nonlocal_exr+rrr�
test_nonlocal�r5zUnparseTestCase.test_nonlocalcCr9r)r�
raise_fromr+rrr�test_raise_from�r5zUnparseTestCase.test_raise_fromcCr3)Nzb'123'r*r+rrr�
test_bytes�r5zUnparseTestCase.test_bytescCr>)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�r@z UnparseTestCase.test_annotationscCr3)Nz{'a', 'b', 'c'}r*r+rrr�test_set_literalr5z UnparseTestCase.test_set_literalc	Cs*|�t�t�tjgd���t�d��dS)N)�eltsz{*()})rrrr�Setr+rrr�test_empty_sets�zUnparseTestCase.test_empty_setcCr3)Nz{x for x in range(5)}r*r+rrr�test_set_comprehensionr5z&UnparseTestCase.test_set_comprehensioncCr3)Nz{x: x*x for x in range(10)}r*r+rrr�test_dict_comprehensionr5z'UnparseTestCase.test_dict_comprehensioncCr9r)r�class_decoratorr+rrr�test_class_decoratorsr5z%UnparseTestCase.test_class_decoratorscCr3)Nz(class A(metaclass=type, *[], **{}): passr*r+rrr�test_class_definitionr5z%UnparseTestCase.test_class_definitioncCs|�t�|�t�dSr)r�elif1�elif2r+rrr�
test_elifsr8zUnparseTestCase.test_elifscCr9r)r�try_except_finallyr+rrr�test_try_except_finallyr5z'UnparseTestCase.test_try_except_finallycCr))Nza, *b, c = seqza, (*b, c) = seqza, *b[0], c = seqza, *(b, c) = seqr*r+rrr�test_starred_assignmentrCz'UnparseTestCase.test_starred_assignmentcCr9r)r�with_simpler+rrr�test_with_simple$r5z UnparseTestCase.test_with_simplecCr9r)r�with_asr+rrr�test_with_as'r5zUnparseTestCase.test_with_ascCr9r)r�with_two_itemsr+rrr�test_with_two_items*r5z#UnparseTestCase.test_with_two_itemscCr6)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)]za[(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 |�tjdtjdd�d��dS)N�X)�id)�exc�cause)rrZRaise�Namer+rrr�test_invalid_raiseC� z"UnparseTestCase.test_invalid_raisecCs |�tjtjdd�gd��dS)N�drE)�values)rrZ	JoinedStrrGr+rrr�test_invalid_fstring_constantFruz-UnparseTestCase.test_invalid_fstring_constantcCs(|�tjtjddd�td�dd��dS)N�a�rF�kind�Y)rF�
conversion�format_spec)rr�FormattedValuerG�ordr+rrr�test_invalid_fstring_conversionIs��z/UnparseTestCase.test_invalid_fstring_conversioncCs|�tjtjdd�d��dS)Nz\\rE)rrrrGr+rrr�test_invalid_fstring_backslashRsz.UnparseTestCase.test_invalid_fstring_backslashcCs|�tjdd��dS)NrE)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_docstringsXs�zUnparseTestCase.test_docstringscCs0|�tjddd�d�|�tjddd�d�dS)N)�rzz(1,))r���z	(1, 2, 3))r!rrGr+rrr�test_constant_tuplesls�z$UnparseTestCase.test_constant_tuplescC�dD]	}|j|dd�qdS)N)z	() -> intz(int, int) -> intz=(Callable[complex], More[Complex(call.to_typevar())]) -> NoneZ	func_type)�moder*)rZ
function_typerrr�test_function_typers�z"UnparseTestCase.test_function_typecCr�)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_commentscCr�)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/r1r4r7r;r=r?rArBrIrKrLrMrNrOrQrSrUrVrWrXr[r\r]r_r`rcrerfrhrjrlrmrnrtrxr�r�r�r�r�r�r�r�rrrrr(�s\
	r(c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�CosmeticTestCasezATest if there are cosmetic issues caused by unnecessary additionscCs|�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 yzlambda 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_parens�s8


























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_keywordscCr>)Nr-r.zf'{x}\n'zf'''{"""
"""}\n'''zf'''{f"""{x}
"""}\n'''r�r+rrrr,�r@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!)rr��prefixr�rrrr��s��z 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�s
�z%CosmeticTestCase.test_unary_op_factorcCr0)Nza[1]za[1, 2]z
a[(1, *a)]r�r+rrrrn�r2zCosmeticTestCase.test_slicesN)r$r%r&�__doc__r�r�r,r�r�r�rnrrrrr��sr�c@sLeZdZdZe�e�jdZeedfZ	hd�Z
dZedd��Z
dd	�ZdS)
�DirectoryTestCasez:Test roundtrip behaviour on all files in Lib and Lib/test.z..�test>ztest_grammar.pyztest_compile.pyz
test_patma.pyztest_ast.pyztest_asdl_parser.pyztest_syntax.pyztest_fstring.pyNcsd�jdur�jSdd��jD�}tj�d�s-�fdd�|D�}tt�|d��}t||B�}|�_|S)NcSs0g|]}|�d�D]}|j�d�s	|���q	qS)z*.pyZbad)�glob�name�
startswith�resolve)�.0Z	directory�itemrrr�
<listcomp>s�
��z3DirectoryTestCase.files_to_test.<locals>.<listcomp>Zcpucsh|]
}|j�jvr|�qSr)r��run_always_files)r�r���clsrr�	<setcomp>s

�z2DirectoryTestCase.files_to_test.<locals>.<setcomp>�
)	�_files_to_test�test_directoriesr��supportZis_resource_enabled�set�random�sample�list)r��itemsZtests_to_run_alwaysrr�r�
files_to_tests
�zDirectoryTestCase.files_to_testc	Csj|��D].}tjjrtd|�����|j|d��t|�}|�|�Wd�n1s-wYqdS)NzTesting )r)	r�r�r��verbose�print�absoluterr	r)rr��sourcerrr�
test_files-s���zDirectoryTestCase.test_files)r$r%r&r��pathlib�Path�__file__�parentZlib_dirr�r�r��classmethodr�r�rrrrr�s
r��__main__)r�ZunittestZtest.supportr�r�r�rrr	r:r<rPrRrTr^rarbrdrgrirkr�ZTestCaserr(r�r�r$�mainrrrr�<module>s<			
i4�
© 2025 GrazzMean