HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/test_tools/__pycache__/test_unparse.cpython-37.pyc
B

"��g�"�	@sdZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZe�ej
�ed�Zej�e��ddlZWdQRXdd�ZdZdZd	Zd
ZdZdZd
ZdZdZdZdZdZGdd�dej �Z!Gdd�de!�Z"Gdd�de!�Z#e$dkr�e�%�dS)z>Tests for the unparse.py script in the Tools/parser directory.�N)�basepath�toolsdir�skip_if_missing�parserc	CsLt|d��}t�|j�d}WdQRXt|d|d��}|��}WdQRX|S)znRead and return the contents of a Python source file (as a
    string), taking into account the file encoding.�rbrN�r)�encoding)�open�tokenize�detect_encoding�readline�read)�filenameZpyfiler�source�r�8/usr/local/lib/python3.7/test/test_tools/test_unparse.py�read_pyfiles
rzQdef 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
c@seZdZdd�Zddd�ZdS)�ASTTestCasecCs|�t�|�t�|��dS)N)ZassertEqual�ast�dump)�self�ast1�ast2rrr�assertASTEqual{szASTTestCase.assertASTEqual�internalcCsLt||dtj�}t��}t�||�|��}t||dtj�}|�||�dS)N�exec)	�compilerZ
PyCF_ONLY_AST�io�StringIO�unparseZUnparser�getvaluer)r�code1rrZunparse_buffer�code2rrrr�check_roundtrip~szASTTestCase.check_roundtripN)r)�__name__�
__module__�__qualname__rr#rrrrrzsrc@seZdZdd�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?S)@�UnparseTestCasecCs|�d�|�d�dS)Nz
f'{f"{0}"*3}'z
f'{f"{y}"*3}')r#)rrrr�
test_fstrings�s
zUnparseTestCase.test_fstringscCs|�d�dS)Nzdel x, y, z)r#)rrrr�test_del_statement�sz"UnparseTestCase.test_del_statementcCs|�d�|�d�dS)Nz45 << 2z13 >> 7)r#)rrrr�test_shifts�s
zUnparseTestCase.test_shiftscCs|�t�dS)N)r#�for_else)rrrr�
test_for_else�szUnparseTestCase.test_for_elsecCs|�t�dS)N)r#�
while_else)rrrr�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 False)r#)rrrr�test_unary_parens�s




z!UnparseTestCase.test_unary_parenscCs|�d�dS)Nz3 .__abs__())r#)rrrr�test_integer_parens�sz#UnparseTestCase.test_integer_parenscCs,|�d�|�d�|�d�|�d�dS)NZ1e1000z-1e1000Z1e1000jz-1e1000j)r#)rrrr�test_huge_float�s


zUnparseTestCase.test_huge_floatcCs |�td��|�td��dS)Ni�l����)r#�str)rrrr�test_min_int�szUnparseTestCase.test_min_intcCs,|�d�|�d�|�d�|�d�dS)NZ7jz-7jZ0jz-0j)r#)rrrr�test_imaginary_literals�s


z'UnparseTestCase.test_imaginary_literalscCs|�d�dS)Nz(lambda: int)())r#)rrrr�test_lambda_parentheses�sz'UnparseTestCase.test_lambda_parenthesescCs|�d�|�d�dS)Nz
1 < 4 <= 5za is b is c is not d)r#)rrrr�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): pass)r#)rrrr�test_function_arguments�s










z'UnparseTestCase.test_function_argumentscCs|�t�dS)N)r#�relative_import)rrrr�test_relative_import�sz$UnparseTestCase.test_relative_importcCs|�t�dS)N)r#�nonlocal_ex)rrrr�
test_nonlocal�szUnparseTestCase.test_nonlocalcCs|�t�dS)N)r#�
raise_from)rrrr�test_raise_from�szUnparseTestCase.test_raise_fromcCs|�d�dS)Nzb'123')r#)rrrr�
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: pass)r#)rrrr�test_annotations�s




z UnparseTestCase.test_annotationscCs|�d�dS)Nz{'a', 'b', 'c'})r#)rrrr�test_set_literal�sz UnparseTestCase.test_set_literalcCs|�d�dS)Nz{x for x in range(5)})r#)rrrr�test_set_comprehension�sz&UnparseTestCase.test_set_comprehensioncCs|�d�dS)Nz{x: x*x for x in range(10)})r#)rrrr�test_dict_comprehension�sz'UnparseTestCase.test_dict_comprehensioncCs|�t�dS)N)r#�class_decorator)rrrr�test_class_decorators�sz%UnparseTestCase.test_class_decoratorscCs|�d�dS)Nz(class A(metaclass=type, *[], **{}): pass)r#)rrrr�test_class_definition�sz%UnparseTestCase.test_class_definitioncCs|�t�|�t�dS)N)r#�elif1�elif2)rrrr�
test_elifs�s
zUnparseTestCase.test_elifscCs|�t�dS)N)r#�try_except_finally)rrrr�test_try_except_finally�sz'UnparseTestCase.test_try_except_finallycCs,|�d�|�d�|�d�|�d�dS)Nza, *b, c = seqza, (*b, c) = seqza, *b[0], c = seqza, *(b, c) = seq)r#)rrrr�test_starred_assignment�s


z'UnparseTestCase.test_starred_assignmentcCs|�t�dS)N)r#�with_simple)rrrr�test_with_simple�sz UnparseTestCase.test_with_simplecCs|�t�dS)N)r#�with_as)rrrr�test_with_as�szUnparseTestCase.test_with_ascCs|�t�dS)N)r#�with_two_items)rrrr�test_with_two_items�sz#UnparseTestCase.test_with_two_itemscCs|�d�|�d�dS)Nz{**{'y': 2}, 'x': 1}z{**{'y': 2}, **{'x': 1}})r#)rrrr�test_dict_unpacking_in_dicts
z+UnparseTestCase.test_dict_unpacking_in_dictcCs||�d�|�d�|�d�|�d�|�d�|�d�|�d�|�d�|�d	�|�d
�|�d�|�d�dS)
Nza[i]za[i,]za[i, j]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#)rrrr�test_subscripts










zUnparseTestCase.test_subscriptN)"r$r%r&r(r)r*r,r.r/r0r1r3r4r5r6r7r9r;r=r>r?r@rArBrDrErHrJrKrMrOrQrRrSrrrrr'�s>r'c@s:eZdZdZdZdej�dd�fZe	dd��Z
dd�ZdS)	�DirectoryTestCasez:Test roundtrip behaviour on all files in Lib and Lib/test.NZLib�testcCs�|jdk	r|jSg}xX|jD]N}tj�t|�}x:t�|�D],}|�d�r:|�d�s:|�	tj�||��q:WqWt
j�d�s�t
�|d�}||_|S)Nz.pyZbadZcpu�
)�NAMES�test_directories�os�path�joinr�listdir�endswith�
startswith�appendrU�supportZis_resource_enabled�randomZsample)�cls�names�dZtest_dir�nrrr�	get_namess
zDirectoryTestCase.get_namesc
Cs�|��}xt|D]l}tjjr&td|�tj�|�dkrPtjjrtd|�d��q|j|d��t	|�}|�
|�WdQRXqWdS)Nz
Testing %s)ztest_fstring.pyz	Skipping z: see issue 28002)r)rfrUr`�verbose�printrYrZ�basenameZsubTestrr#)rrcrrrrr�
test_files1s
zDirectoryTestCase.test_files)r$r%r&�__doc__rWrYrZr[rX�classmethodrfrjrrrrrTs
rT�__main__)&rkZunittestZtest.supportrUrrYrar
rZtest.test_toolsrrrrZr[Zparser_pathr`Z
DirsOnSysPathrrr+r-r8r:r<rCrFrGrIrLrNrPZTestCaserr'rTr$�mainrrrr�<module>s>		
0