Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/test_tools/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/test_tools/__pycache__/test_unparse.cpython-35.pyc



��Yf	�@skdZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZe�ej
jed�Zejje��ddlZWdQRXdd�ZdZdZd	Zd
ZdZdZd
ZdZdZdZdZdZGdd�dej �Z!Gdd�de!�Z"Gdd�de!�Z#e$dkrgej%�dS)z>Tests for the unparse.py script in the Tools/parser directory.�N)�basepath�toolsdir�skip_if_missing�parsercCs^t|d��}tj|j�d}WdQRXt|dd|��}|j�}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�A/opt/alt/python35/lib64/python3.5/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@s+eZdZdd�Zddd�ZdS)�ASTTestCasecCs&|jtj|�tj|��dS)N)ZassertEqual�ast�dump)�self�ast1�ast2rrr�assertASTEqual{szASTTestCase.assertASTEqualZinternalcCslt||dtj�}tj�}tj||�|j�}t||dtj�}|j||�dS)N�exec)	�compilerZ
PyCF_ONLY_AST�io�StringIO�unparseZUnparser�getvaluer)r�code1rrZunparse_buffer�code2rrrr�check_roundtrip~szASTTestCase.check_roundtripN)�__name__�
__module__�__qualname__rr"rrrrrzsrc@sleZdZdd�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;S)<�UnparseTestCasecCs|jd�dS)Nzdel x, y, z)r")rrrr�test_del_statement�sz"UnparseTestCase.test_del_statementcCs|jd�|jd�dS)Nz45 << 2z13 >> 7)r")rrrr�test_shifts�s
zUnparseTestCase.test_shiftscCs|jt�dS)N)r"�for_else)rrrr�
test_for_else�szUnparseTestCase.test_for_elsecCs|jt�dS)N)r"�
while_else)rrrr�test_while_else�szUnparseTestCase.test_while_elsecCsE|jd�|jd�|jd�|jd�|jd�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|jd�dS)Nz3 .__abs__())r")rrrr�test_integer_parens�sz#UnparseTestCase.test_integer_parenscCs8|jd�|jd�|jd�|jd�dS)NZ1e1000z-1e1000Z1e1000jz-1e1000j)r")rrrr�test_huge_float�s


zUnparseTestCase.test_huge_floatcCs*|jtd��|jtd��dS)N���?li�ll����)r"�str)rrrr�test_min_int�szUnparseTestCase.test_min_intcCs8|jd�|jd�|jd�|jd�dS)NZ7jz-7jZ0jz-0j)r")rrrr�test_imaginary_literals�s


z'UnparseTestCase.test_imaginary_literalscCs|jd�dS)Nz(lambda: int)())r")rrrr�test_lambda_parentheses�sz'UnparseTestCase.test_lambda_parenthesescCs|jd�|jd�dS)Nz
1 < 4 <= 5za is b is c is not d)r")rrrr�test_chained_comparisons�s
z(UnparseTestCase.test_chained_comparisonscCs�|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd	�|jd
�|jd�|jd�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|jt�dS)N)r"�relative_import)rrrr�test_relative_import�sz$UnparseTestCase.test_relative_importcCs|jt�dS)N)r"�nonlocal_ex)rrrr�
test_nonlocal�szUnparseTestCase.test_nonlocalcCs|jt�dS)N)r"�
raise_from)rrrr�test_raise_from�szUnparseTestCase.test_raise_fromcCs|jd�dS)Nzb'123')r")rrrr�
test_bytes�szUnparseTestCase.test_bytescCsE|jd�|jd�|jd�|jd�|jd�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|jd�dS)Nz{'a', 'b', 'c'})r")rrrr�test_set_literal�sz UnparseTestCase.test_set_literalcCs|jd�dS)Nz{x for x in range(5)})r")rrrr�test_set_comprehension�sz&UnparseTestCase.test_set_comprehensioncCs|jd�dS)Nz{x: x*x for x in range(10)})r")rrrr�test_dict_comprehension�sz'UnparseTestCase.test_dict_comprehensioncCs|jt�dS)N)r"�class_decorator)rrrr�test_class_decorators�sz%UnparseTestCase.test_class_decoratorscCs|jd�dS)Nz(class A(metaclass=type, *[], **{}): pass)r")rrrr�test_class_definition�sz%UnparseTestCase.test_class_definitioncCs|jt�|jt�dS)N)r"�elif1�elif2)rrrr�
test_elifs�s
zUnparseTestCase.test_elifscCs|jt�dS)N)r"�try_except_finally)rrrr�test_try_except_finally�sz'UnparseTestCase.test_try_except_finallycCs8|jd�|jd�|jd�|jd�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|jt�dS)N)r"�with_simple)rrrr�test_with_simple�sz UnparseTestCase.test_with_simplecCs|jt�dS)N)r"�with_as)rrrr�test_with_as�szUnparseTestCase.test_with_ascCs|jt�dS)N)r"�with_two_items)rrrr�test_with_two_items�sz#UnparseTestCase.test_with_two_itemscCs|jd�|jd�dS)Nz{**{'y': 2}, 'x': 1}z{**{'y': 2}, **{'x': 1}})r")rrrr�test_dict_unpacking_in_dict�s
z+UnparseTestCase.test_dict_unpacking_in_dictN) r#r$r%r'r(r*r,r-r.r/r4r5r6r7r8r:r<r>r?r@rArBrCrErFrIrKrLrNrPrRrSrrrrr&�s:r&c@s=eZdZdZdejjdd�fZdd�ZdS)�DirectoryTestCasez:Test roundtrip behaviour on all files in Lib and Lib/test.ZLib�testcCs�g}x{|jD]p}tjjt|�}xRtj|�D]A}|jd�r;|jd�r;|jtjj||��q;WqWt	j
jd�s�tj
|d�}xA|D]9}t	j
jr�td|�t|�}|j|�q�WdS)Nz.pyZbadZcpu�
z
Testing %s)�test_directories�os�path�joinr�listdir�endswith�
startswith�appendrU�supportZis_resource_enabled�randomZsample�verbose�printrr")r�names�dZtest_dir�nrrrrr�
test_files	s$
zDirectoryTestCase.test_filesN)	r#r$r%�__doc__rXrYrZrWrfrrrrrTsrT�__main__)&rgZunittestZtest.supportrUrrXr`r
rZtest.test_toolsrrrrYrZZparser_pathr_Z
DirsOnSysPathrrr)r+r9r;r=rDrGrHrJrMrOrQZTestCaserr&rTr#�mainrrrr�<module>s<		
}