Your IP : 216.73.216.213


Current Path : /opt/alt/python36/lib64/python3.6/lib2to3/tests/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/lib2to3/tests/__pycache__/test_parser.cpython-36.pyc

3

� fnO�@s�dZddlmZddlmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlmZdd	lmZdd
lmZGdd�dej�ZGd
d�dej�ZGdd�dej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd �d e�Z"Gd!d"�d"e�Z#Gd#d$�d$e�Z$Gd%d&�d&e�Z%Gd'd(�d(e�Z&Gd)d*�d*ej�Z'Gd+d,�d,e�Z(d-d.�Z)dS)/aFTest suite for 2to3's parser and grammar files.

This is the place to add tests for changes to 2to3's grammar, such as those
merging the grammars for Python 2 and 3. In addition to specific tests for
parts of the grammar we've changed, we also make sure we can parse the
test_grammar.py files from both Python 2 and Python 3.
�)�support)�driver�driver_no_print_statement�N)r)�tokenize�)�
ParseError)�python_symbolsc@seZdZdd�ZdS)�
TestDrivercCsJd}tj|�}|j|jdjdjtj�|j|jdjdjtj�dS)Nzprint 1
print 2
rr)r�parse_string�assertEqualZchildren�type�symsZ
print_stmt)�self�s�t�r�>/opt/alt/python36/lib64/python3.6/lib2to3/tests/test_parser.py�
test_formfeed"s
zTestDriver.test_formfeedN)�__name__�
__module__�__qualname__rrrrrr
 sr
c@s>eZdZdd�Zdd�Zejejdkd�dd��Z	d	d
�Z
dS)�TestPgen2CachingcCstjtjddd�dS)NFT)�save�force)�pgen2_driver�load_grammarr�grammar_path)rrrr�test_load_grammar_from_txt_file*sz0TestPgen2Caching.test_load_grammar_from_txt_filecCs�tj�}zptjj|tjjtj��}tj	tj|�t
j|�}t
j|ddd�|j
tjj|��tj|�t
j|ddd�Wdtj|�XdS)NT)rrF)�tempfile�mkdtemp�os�path�join�basenamerr�shutil�copyr�_generate_pickle_namer�
assertTrue�exists�unlink�rmtree)r�tmpdir�grammar_copy�pickle_namerrr�test_load_grammar_from_pickle-s

z.TestPgen2Caching.test_load_grammar_from_pickleNzsys.executable requiredcCsDtj�}tjj|d�}�ztj|�tjjtj�}tjj||�}tjj||�}t	j
tj|�t	j
tj|�tj|�}tj|�}|j
||�tj|ddd�|jtjj|��ttj�}d|d<tjtjdd|fg|d�|jtjj|��t|d	��4}	t|d	��}
|j|	j�|
j�d
d�WdQRXWdQRXWdt	j|�XdS)NZsubdirT)rrZrandomZPYTHONHASHSEEDz-cz{
from lib2to3.pgen2 import driver as pgen2_driver
pgen2_driver.load_grammar(%r, save=True, force=True)
                    )�env�rbzGGrammar caches generated using different hash seeds were not identical.)�msg)rr r!r"r#�mkdirr$rrr%r&rr'ZassertNotEqualrr(r)�dict�environ�
subprocessZ
check_call�sys�
executable�openr�readr+)rr,Z	tmpsubdirZgrammar_baser-Zgrammar_sub_copyr.Zpickle_sub_nameZsub_envZ
pickle_f_1Z
pickle_f_2rrr�!test_load_grammar_from_subprocess?s8



 z2TestPgen2Caching.test_load_grammar_from_subprocesscsftd�Gdd�d��G��fdd�d�}|�tj�<|jtjtj��tj�d�}|j|j	d�dS)Nz
.load_testc@seZdZdd�ZdS)z=TestPgen2Caching.test_load_packaged_grammar.<locals>.MyLoadercSstjddi�S)N�elephant�)�pickle�dumps)r�whererrr�get_datakszFTestPgen2Caching.test_load_packaged_grammar.<locals>.MyLoader.get_dataN)rrrrArrrr�MyLoaderjsrBcs eZdZdZejj����ZdS)z=TestPgen2Caching.test_load_packaged_grammar.<locals>.MyModuleZparsertestmoduleN)rrr�__file__�	importlib�util�spec_from_loader�__spec__r)rB�modnamerr�MyModulemsrIzGrammar.txtr=)
rr7�modulesZ
addCleanup�operator�delitemrZload_packaged_grammarrr<)rrI�gr)rBrHr�test_load_packaged_grammarhsz+TestPgen2Caching.test_load_packaged_grammar)rrrrr/�unittestZskipIfr7r8r;rNrrrrr)s)rc@seZdZdd�Zdd�ZdS)�GrammarTestcCstj|�dS)N)rr)r�coderrr�validatewszGrammarTest.validatecCs0y|j|�Wntk
r"Yn
Xtd��dS)Nz Syntax shouldn't have been valid)rRr�AssertionError)rrQrrr�invalid_syntaxzs
zGrammarTest.invalid_syntaxN)rrrrRrTrrrrrPvsrPc@seZdZdd�ZdS)�TestMatrixMultiplicationcCs|jd�|jd�dS)Nza @ bza @= b)rR)rrrr�#test_matrix_multiplication_operator�s
z<TestMatrixMultiplication.test_matrix_multiplication_operatorN)rrrrVrrrrrU�srUc@seZdZdd�ZdS)�
TestYieldFromcCs"|jd�|jd�|jd�dS)Nzyield from xz(yield from x) + yz
yield from)rRrT)rrrr�test_yield_from�s

zTestYieldFrom.test_yield_fromN)rrrrXrrrrrW�srWc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestAsyncAwaitcCsr|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd	�|jd
�|jd�dS)NzLasync def foo():
                             await x
                      zYasync def foo():
                             [i async for i in b]
                      z�async def foo():
                             {i for i in b
                                async for i in a if await i
                                  for b in i}
                      zdasync def foo():
                             [await i for i in b if await c]
                      zYasync def foo():
                             [ i for i in b if c]
                      zhasync def foo():

            def foo(): pass

            def foo(): pass

            await x
        zasync def foo(): return await azTdef foo():
            def foo(): pass
            async def foo(): await x
        zawait xz5def foo():
                                   await xzedef foo():
            def foo(): pass
            async def foo(): pass
            await x
        )rRrT)rrrr�test_await_expr�s(

zTestAsyncAwait.test_await_exprcCs"|jd�|jd�|jd�dS)Nz	async = 1z	await = 1zdef async(): pass)rR)rrrr�test_async_var�s

zTestAsyncAwait.test_async_varcCs|jd�|jd�dS)NzDasync def foo():
                             async for a in b: passzDdef foo():
                                   async for a in b: pass)rRrT)rrrr�test_async_with�szTestAsyncAwait.test_async_withcCs|jd�|jd�dS)Nz@async def foo():
                             async with a: passz@def foo():
                                   async with a: pass)rRrT)rrrr�test_async_for�szTestAsyncAwait.test_async_forN)rrrrZr[r\r]rrrrrY�s1rYc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�TestRaiseChangescCs|jd�dS)N�raise)rR)rrrr�test_2x_style_1�sz TestRaiseChanges.test_2x_style_1cCs|jd�dS)Nz
raise E, V)rR)rrrr�test_2x_style_2�sz TestRaiseChanges.test_2x_style_2cCs|jd�dS)Nz
raise E, V, T)rR)rrrr�test_2x_style_3�sz TestRaiseChanges.test_2x_style_3cCs|jd�dS)Nzraise E, V, T, Z)rT)rrrr�test_2x_style_invalid_1�sz(TestRaiseChanges.test_2x_style_invalid_1cCs|jd�dS)Nzraise E1 from E2)rR)rrrr�
test_3x_style�szTestRaiseChanges.test_3x_stylecCs|jd�dS)Nzraise E, V from E1)rT)rrrr�test_3x_style_invalid_1�sz(TestRaiseChanges.test_3x_style_invalid_1cCs|jd�dS)Nzraise E from E1, E2)rT)rrrr�test_3x_style_invalid_2�sz(TestRaiseChanges.test_3x_style_invalid_2cCs|jd�dS)Nzraise from E1, E2)rT)rrrr�test_3x_style_invalid_3�sz(TestRaiseChanges.test_3x_style_invalid_3cCs|jd�dS)Nzraise E from)rT)rrrr�test_3x_style_invalid_4�sz(TestRaiseChanges.test_3x_style_invalid_4N)rrrr`rarbrcrdrerfrgrhrrrrr^�sr^c@s�eZdZdd�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�Zd9S):�TestUnpackingGeneralizationscCs|jd�dS)Nzfunc(1, *(2, 3), 4))rR)rrrr�test_mid_positional_star�sz5TestUnpackingGeneralizations.test_mid_positional_starcCs|jd�dS)Nz,func(**{'eggs':'scrambled', 'spam':'fried'}))rR)rrrr�test_double_star_dict_literal�sz:TestUnpackingGeneralizations.test_double_star_dict_literalcCs|jd�dS)Nz*func(spam='fried', **{'eggs':'scrambled'}))rR)rrrr�,test_double_star_dict_literal_after_keywords�szITestUnpackingGeneralizations.test_double_star_dict_literal_after_keywordscCs|jd�dS)Nz[*{2}, 3, *[4]])rR)rrrr�test_list_displaysz.TestUnpackingGeneralizations.test_list_displaycCs|jd�dS)Nz{*{2}, 3, *[4]})rR)rrrr�test_set_displaysz-TestUnpackingGeneralizations.test_set_displaycCs|jd�dS)Nz{**{}})rR)rrrr�test_dict_display_1sz0TestUnpackingGeneralizations.test_dict_display_1cCs|jd�dS)Nz{**{}, 3:4, **{5:6, 7:8}})rR)rrrr�test_dict_display_2	sz0TestUnpackingGeneralizations.test_dict_display_2cCs|jd�dS)Nzf(a, *b, *c, d))rR)rrrr�test_argument_unpacking_1sz6TestUnpackingGeneralizations.test_argument_unpacking_1cCs|jd�dS)Nzf(**a, **b))rR)rrrr�test_argument_unpacking_2sz6TestUnpackingGeneralizations.test_argument_unpacking_2cCs|jd�dS)Nzf(2, *a, *b, **b, **c, **d))rR)rrrr�test_argument_unpacking_3sz6TestUnpackingGeneralizations.test_argument_unpacking_3cCs|jd�|jd�dS)Nzdef f(a, b): call(a, b)zdef f(a, b,): call(a, b,))rR)rrrr�test_trailing_commas_1s
z3TestUnpackingGeneralizations.test_trailing_commas_1cCs|jd�|jd�dS)Nzdef f(a, *b): call(a, *b)zdef f(a, *b,): call(a, *b,))rR)rrrr�test_trailing_commas_2s
z3TestUnpackingGeneralizations.test_trailing_commas_2cCs|jd�|jd�dS)Nzdef f(a, b=1): call(a, b=1)zdef f(a, b=1,): call(a, b=1,))rR)rrrr�test_trailing_commas_3s
z3TestUnpackingGeneralizations.test_trailing_commas_3cCs|jd�|jd�dS)Nzdef f(a, **b): call(a, **b)zdef f(a, **b,): call(a, **b,))rR)rrrr�test_trailing_commas_4!s
z3TestUnpackingGeneralizations.test_trailing_commas_4cCs|jd�|jd�dS)Nzdef f(*a, b=1): call(*a, b=1)zdef f(*a, b=1,): call(*a, b=1,))rR)rrrr�test_trailing_commas_5%s
z3TestUnpackingGeneralizations.test_trailing_commas_5cCs|jd�|jd�dS)Nzdef f(*a, **b): call(*a, **b)zdef f(*a, **b,): call(*a, **b,))rR)rrrr�test_trailing_commas_6)s
z3TestUnpackingGeneralizations.test_trailing_commas_6cCs|jd�|jd�dS)Nzdef f(*, b=1): call(*b)zdef f(*, b=1,): call(*b,))rR)rrrr�test_trailing_commas_7-s
z3TestUnpackingGeneralizations.test_trailing_commas_7cCs|jd�|jd�dS)Nzdef f(a=1, b=2): call(a=1, b=2)z!def f(a=1, b=2,): call(a=1, b=2,))rR)rrrr�test_trailing_commas_81s
z3TestUnpackingGeneralizations.test_trailing_commas_8cCs|jd�|jd�dS)Nzdef f(a=1, **b): call(a=1, **b)z!def f(a=1, **b,): call(a=1, **b,))rR)rrrr�test_trailing_commas_95s
z3TestUnpackingGeneralizations.test_trailing_commas_9cCs|jd�|jd�dS)Nzf = lambda a, b: call(a, b)zf = lambda a, b,: call(a, b,))rR)rrrr�test_trailing_commas_lambda_19s
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_1cCs|jd�|jd�dS)Nzf = lambda a, *b: call(a, *b)zf = lambda a, *b,: call(a, *b,))rR)rrrr�test_trailing_commas_lambda_2=s
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_2cCs|jd�|jd�dS)Nzf = lambda a, b=1: call(a, b=1)z!f = lambda a, b=1,: call(a, b=1,))rR)rrrr�test_trailing_commas_lambda_3As
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_3cCs|jd�|jd�dS)Nzf = lambda a, **b: call(a, **b)z!f = lambda a, **b,: call(a, **b,))rR)rrrr�test_trailing_commas_lambda_4Es
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_4cCs|jd�|jd�dS)Nz!f = lambda *a, b=1: call(*a, b=1)z#f = lambda *a, b=1,: call(*a, b=1,))rR)rrrr�test_trailing_commas_lambda_5Is
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_5cCs|jd�|jd�dS)Nz!f = lambda *a, **b: call(*a, **b)z#f = lambda *a, **b,: call(*a, **b,))rR)rrrr�test_trailing_commas_lambda_6Ms
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_6cCs|jd�|jd�dS)Nzf = lambda *, b=1: call(*b)zf = lambda *, b=1,: call(*b,))rR)rrrr�test_trailing_commas_lambda_7Qs
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_7cCs|jd�|jd�dS)Nz#f = lambda a=1, b=2: call(a=1, b=2)z%f = lambda a=1, b=2,: call(a=1, b=2,))rR)rrrr�test_trailing_commas_lambda_8Us
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_8cCs|jd�|jd�dS)Nz#f = lambda a=1, **b: call(a=1, **b)z%f = lambda a=1, **b,: call(a=1, **b,))rR)rrrr�test_trailing_commas_lambda_9Ys
z:TestUnpackingGeneralizations.test_trailing_commas_lambda_9N)rrrrjrkrlrmrnrorprqrrrsrtrurvrwrxryrzr{r|r}r~rr�r�r�r�r�r�rrrrri�s8ric@s�eZdZdd�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+S),�TestFunctionAnnotationscCs|jd�dS)Nzdef f(x) -> list: pass)rR)rrrr�test_1`szTestFunctionAnnotations.test_1cCs|jd�dS)Nzdef f(x:int): pass)rR)rrrr�test_2cszTestFunctionAnnotations.test_2cCs|jd�dS)Nzdef f(*x:str): pass)rR)rrrr�test_3fszTestFunctionAnnotations.test_3cCs|jd�dS)Nzdef f(**x:float): pass)rR)rrrr�test_4iszTestFunctionAnnotations.test_4cCs|jd�dS)Nzdef f(x, y:1+2): pass)rR)rrrr�test_5lszTestFunctionAnnotations.test_5cCs|jd�dS)Nzdef f(a, (b:1, c:2, d)): pass)rR)rrrr�test_6oszTestFunctionAnnotations.test_6cCs|jd�dS)Nz/def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6): pass)rR)rrrr�test_7rszTestFunctionAnnotations.test_7cCsd}|j|�dS)Nzgdef f(a, (b:1, c:2, d), e:3=4, f=5,
                        *g:6, h:7, i=8, j:9=10, **k:11) -> 12: pass)rR)rrrrr�test_8uszTestFunctionAnnotations.test_8cCsd}|j|�dS)Nz�def f(
          a: str,
          b: int,
          *,
          c: bool = False,
          **kwargs,
        ) -> None:
            call(c=c, **kwargs,))rR)rrrrr�test_9zszTestFunctionAnnotations.test_9cCsd}|j|�dS)Nz@def f(
          a: str,
        ) -> None:
            call(a,))rR)rrrrr�test_10�szTestFunctionAnnotations.test_10cCsd}|j|�dS)NzGdef f(
          a: str = '',
        ) -> None:
            call(a=a,))rR)rrrrr�test_11�szTestFunctionAnnotations.test_11cCsd}|j|�dS)NzHdef f(
          *args: str,
        ) -> None:
            call(*args,))rR)rrrrr�test_12�szTestFunctionAnnotations.test_12cCs|jd�|jd�dS)Nz)def f(a: str, b: int) -> None: call(a, b)z+def f(a: str, b: int,) -> None: call(a, b,))rR)rrrr�test_13�s
zTestFunctionAnnotations.test_13cCs|jd�|jd�dS)Nz+def f(a: str, *b: int) -> None: call(a, *b)z-def f(a: str, *b: int,) -> None: call(a, *b,))rR)rrrr�test_14�s
zTestFunctionAnnotations.test_14cCs|jd�|jd�dS)Nz-def f(a: str, b: int=1) -> None: call(a, b=1)z/def f(a: str, b: int=1,) -> None: call(a, b=1,))rR)rrrr�test_15�s
zTestFunctionAnnotations.test_15cCs|jd�|jd�dS)Nz-def f(a: str, **b: int) -> None: call(a, **b)z/def f(a: str, **b: int,) -> None: call(a, **b,))rR)rrrr�test_16�s
zTestFunctionAnnotations.test_16cCs|jd�|jd�dS)Nz/def f(*a: str, b: int=1) -> None: call(*a, b=1)z1def f(*a: str, b: int=1,) -> None: call(*a, b=1,))rR)rrrr�test_17�s
zTestFunctionAnnotations.test_17cCs|jd�|jd�dS)Nz/def f(*a: str, **b: int) -> None: call(*a, **b)z1def f(*a: str, **b: int,) -> None: call(*a, **b,))rR)rrrr�test_18�s
zTestFunctionAnnotations.test_18cCs|jd�|jd�dS)Nz$def f(*, b: int=1) -> None: call(*b)z&def f(*, b: int=1,) -> None: call(*b,))rR)rrrr�test_19�s
zTestFunctionAnnotations.test_19cCs|jd�|jd�dS)Nz2def f(a: str='', b: int=2) -> None: call(a=a, b=2)z4def f(a: str='', b: int=2,) -> None: call(a=a, b=2,))rR)rrrr�test_20�s
zTestFunctionAnnotations.test_20cCs|jd�|jd�dS)Nz2def f(a: str='', **b: int) -> None: call(a=a, **b)z4def f(a: str='', **b: int,) -> None: call(a=a, **b,))rR)rrrr�test_21�s
zTestFunctionAnnotations.test_21N)rrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�_s*r�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestVarAnnotationscCs|jd�dS)Nz
var1: int = 5)rR)rrrrr��szTestVarAnnotations.test_1cCs|jd�dS)Nzvar2: [int, str])rR)rrrrr��szTestVarAnnotations.test_2cCs|jd�dS)NzCdef f():
    st: str = 'Hello'
    a.b: int = (1, 2)
    return st
)rR)rrrrr��szTestVarAnnotations.test_3cCs|jd�dS)Nz$def fbad():
    x: int
    print(x)
)rR)rrrrr��szTestVarAnnotations.test_4cCs|jd�dS)Nzeclass C:
    x: int
    s: str = 'attr'
    z = 2
    def __init__(self, x):
        self.x: int = x
)rR)rrrrr��szTestVarAnnotations.test_5cCs|jd�dS)Nzlst: List[int] = [])rR)rrrrr��szTestVarAnnotations.test_6N)	rrrr�r�r�r�r�r�rrrrr��sr�c@seZdZdd�Zdd�ZdS)�
TestExceptcCsd}|j|�dS)NzP
            try:
                x
            except E as N:
                y)rR)rrrrr�test_new�szTestExcept.test_newcCsd}|j|�dS)NzN
            try:
                x
            except E, N:
                y)rR)rrrrr�test_old�szTestExcept.test_oldN)rrrr�r�rrrrr��sr�c*@seZdZd.Zd+d,�Zd-S)/�TestStringLiterals�'�"�r'�r"�R'�R"�u'�u"�U'�U"�b'�b"�B'�B"�f'�f"�F'�F"�ur'�ur"�Ur'�Ur"�uR'�uR"�UR'�UR"�br'�br"�Br'�Br"�bR'�bR"�BR'�BR"�rb'�rb"�Rb'�Rb"�rB'�rB"�RB'�RB"cCsLxF|jD]<}dj||dd�}|j|�dj||dd�}|j|�qWdS)Nz{p}spamspamspam{s}r)�prz{p}{s}{s}eggs{s}{s}{s}���r�)�prefixes�formatrR)rZpreZsingleZtriplerrr�test_lit�s

zTestStringLiterals.test_litN)*r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�)rrrr�r�rrrrr��sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestSetLiteralcCs|jd�dS)Nzx = {'one'})rR)rrrrr�szTestSetLiteral.test_1cCs|jd�dS)Nzx = {'one', 1,})rR)rrrrr�
szTestSetLiteral.test_2cCs|jd�dS)Nzx = {'one', 'two', 'three'})rR)rrrrr�
szTestSetLiteral.test_3cCs|jd�dS)Nzx = {2, 3, 4,})rR)rrrrr�szTestSetLiteral.test_4N)rrrr�r�r�r�rrrrr�sr�c@seZdZdd�Zdd�ZdS)�TestNumericLiteralscCs|jd�|jd�dS)NZ0o7777777777777Z0o7324528887)rRrT)rrrr�test_new_octal_notations
z+TestNumericLiterals.test_new_octal_notationcCs|jd�|jd�dS)NZ0b101010Z	0b0101021)rRrT)rrrr�test_new_binary_notations
z,TestNumericLiterals.test_new_binary_notationN)rrrr�r�rrrrr�sr�c@seZdZdd�ZdS)�TestClassDefcCs6|jd�|jd�|jd�|jd�|jd�dS)Nzclass B(t=7): passzclass B(t, *args): passzclass B(t, **kwargs): passz!class B(t, *args, **kwargs): passz'class B(t, y=9, *args, **kwargs,): pass)rR)rrrr�test_new_syntaxs




zTestClassDef.test_new_syntaxN)rrrr�rrrrr�sr�c@s eZdZdZdd�Zdd�ZdS)�TestParserIdempotencyz,A cut-down version of pytree_idempotency.py.c(Csx�tj�D]�}t|d��}tj|j�d}WdQRX|j|d|�t|d|d��}|j�}WdQRXytj	|�}WnXt
k
r�ytj	|�}Wn4t
k
r�}z|jd||f�WYdd}~XnXYnXt
|�}||kr
tt|||��|jd|�q
WdS)Nr1rzcan't detect encoding for %s�r)�encodingzParseError on file %s (%s)zIdempotency failed: %s)rZall_project_filesr9r�detect_encoding�readlineZassertIsNotNoner:rrrrZfail�str�print�
diff_texts)r�filepath�fpr��sourceZtree�err�newrrr�test_all_project_files+s$
*z,TestParserIdempotency.test_all_project_filescCs,tjd�tjd�tjd�tjd�dS)Nz
a, *b, c = x
z[*a, b] = x
z(z, *y, w) = m
zfor *z, m in d: pass
)rr)rrrr�test_extended_unpacking?s


z-TestParserIdempotency.test_extended_unpackingN)rrr�__doc__r�r�rrrrr�'sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestLiteralscCstjtj|�d�dS)Nz

)rrr�dedent)rrrrrrRHszTestLiterals.validatecCsd}|j|�dS)Nu�
            md5test(b"ª" * 80,
                    (b"Test Using Larger Than Block-Size Key "
                     b"and Larger Than One Block-Size Data"),
                    "6f630fad67cda0ee1fb1f562db3aa53e")
            )rR)rrrrr�test_multiline_bytes_literalsKsz*TestLiterals.test_multiline_bytes_literalscCsd}|j|�dS)Nz�
            b"""
            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN">
            """
            )rR)rrrrr�'test_multiline_bytes_tripquote_literalsTsz4TestLiterals.test_multiline_bytes_tripquote_literalscCsd}|j|�dS)Nu�
            md5test("ª" * 80,
                    ("Test Using Larger Than Block-Size Key "
                     "and Larger Than One Block-Size Data"),
                    "6f630fad67cda0ee1fb1f562db3aa53e")
            )rR)rrrrr�test_multiline_str_literals]sz(TestLiterals.test_multiline_str_literalsN)rrrrRr�r�r�rrrrr�Fs		r�c	Cs(|j�}|j�}tj||||dddd�S)Nz
(original)z(reserialized)�)Zlineterm)�
splitlines�difflibZunified_diff)�a�b�filenamerrrr�gs
r�)*r�r�rrrr�rDrKr!r>r%r6r7rrOZ
lib2to3.pgen2rrZpgen2.parserZlib2to3.pygramr	rZTestCaser
rrPrUrWrYr^rir�r�r�r�r�r�r�r�r�r�rrrr�<module>sD	M
F ia
	!