Your IP : 216.73.216.85


Current Path : /opt/alt/python35/lib64/python3.5/lib2to3/tests/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/lib2to3/tests/__pycache__/test_parser.cpython-35.opt-1.pyc



��Yfo1�@s6dZddlmZddlmZmZddlmZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlmZd	d
lmZddlmZGdd
�d
ej�ZGdd�dej�ZGdd�dej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�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�test_dir�)�verboseN)r)�tokenize�)�
ParseError)�python_symbolsc@seZdZdd�ZdS)�
TestDrivercCsad}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/python35/lib64/python3.5/lib2to3/tests/test_parser.py�
test_formfeed s$zTestDriver.test_formfeedN)�__name__�
__module__�__qualname__rrrrrrsrc@sOeZdZdd�Zdd�Zejejdkd�dd��Z	dS)	�TestPgen2CachingcCs tjtjdddd�dS)N�saveF�forceT)�pgen2_driver�load_grammarr�grammar_path)rrrr�test_load_grammar_from_txt_file(sz0TestPgen2Caching.test_load_grammar_from_txt_filecCs�tj�}z�tjj|tjjtj��}tj	tj|�t
j|�}t
j|dddd�|j
tjj|��tj|�t
j|dddd�Wdtj|�XdS)NrTrF)�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 requiredcCs�tj�}tjj|d�}z�tj|�tjjtj�}tjj||�}tjj||�}t	j
tj|�t	j
tj|�tj|�}tj|�}|j
||�tj|dddd�|jtjj|��ttj�}d|d<tjtjdd|fgd	|�|jtjj|��t|d
��B}	t|d
��)}
|j|	j�|
j�dd�WdQRXWdQRXWdt	j|�XdS)
NZsubdirrTrZrandomZPYTHONHASHSEEDz-cz{
from lib2to3.pgen2 import driver as pgen2_driver
pgen2_driver.load_grammar(%r, save=True, force=True)
                    �env�rb�msgzGGrammar caches generated using different hash seeds were not identical.)r r!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_subprocess)
rrrrr0�unittestZskipIfr8r9r<rrrrr'src@s(eZdZdd�Zdd�ZdS)�GrammarTestcCstj|�dS)N)rr)r�coderrr�validateiszGrammarTest.validatecCs6y|j|�Wntk
r%Yn
Xtd��dS)Nz Syntax shouldn't have been valid)r@r	�AssertionError)rr?rrr�invalid_syntaxls

zGrammarTest.invalid_syntaxN)rrrr@rBrrrrr>hsr>c@seZdZdd�ZdS)�TestMatrixMultiplicationcCs|jd�|jd�dS)Nza @ bza @= b)r@)rrrr�#test_matrix_multiplication_operatorvs
z<TestMatrixMultiplication.test_matrix_multiplication_operatorN)rrrrDrrrrrCusrCc@seZdZdd�ZdS)�
TestYieldFromcCs+|jd�|jd�|jd�dS)Nzyield from xz(yield from x) + yz
yield from)r@rB)rrrr�test_yield_from|s

zTestYieldFrom.test_yield_fromN)rrrrFrrrrrE{srEc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestAsyncAwaitcCs_|jd�|jd�|jd�|jd�|jd�|jd�|jd�dS)NzLasync def foo():
                             await x
                      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
        )r@rB)rrrr�test_await_expr�s

zTestAsyncAwait.test_await_exprcCs+|jd�|jd�|jd�dS)Nz	async = 1z	await = 1zdef async(): pass)r@)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)r@rB)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)r@rB)rrrr�test_async_for�szTestAsyncAwait.test_async_forN)rrrrHrIrJrKrrrrrG�srGc@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�TestRaiseChangescCs|jd�dS)N�raise)r@)rrrr�test_2x_style_1�sz TestRaiseChanges.test_2x_style_1cCs|jd�dS)Nz
raise E, V)r@)rrrr�test_2x_style_2�sz TestRaiseChanges.test_2x_style_2cCs|jd�dS)Nz
raise E, V, T)r@)rrrr�test_2x_style_3�sz TestRaiseChanges.test_2x_style_3cCs|jd�dS)Nzraise E, V, T, Z)rB)rrrr�test_2x_style_invalid_1�sz(TestRaiseChanges.test_2x_style_invalid_1cCs|jd�dS)Nzraise E1 from E2)r@)rrrr�
test_3x_style�szTestRaiseChanges.test_3x_stylecCs|jd�dS)Nzraise E, V from E1)rB)rrrr�test_3x_style_invalid_1�sz(TestRaiseChanges.test_3x_style_invalid_1cCs|jd�dS)Nzraise E from E1, E2)rB)rrrr�test_3x_style_invalid_2�sz(TestRaiseChanges.test_3x_style_invalid_2cCs|jd�dS)Nzraise from E1, E2)rB)rrrr�test_3x_style_invalid_3�sz(TestRaiseChanges.test_3x_style_invalid_3cCs|jd�dS)Nzraise E from)rB)rrrr�test_3x_style_invalid_4�sz(TestRaiseChanges.test_3x_style_invalid_4N)rrrrNrOrPrQrRrSrTrUrVrrrrrL�srLc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�TestUnpackingGeneralizationscCs|jd�dS)Nzfunc(1, *(2, 3), 4))r@)rrrr�test_mid_positional_star�sz5TestUnpackingGeneralizations.test_mid_positional_starcCs|jd�dS)Nz,func(**{'eggs':'scrambled', 'spam':'fried'}))r@)rrrr�test_double_star_dict_literal�sz:TestUnpackingGeneralizations.test_double_star_dict_literalcCs|jd�dS)Nz*func(spam='fried', **{'eggs':'scrambled'}))r@)rrrr�,test_double_star_dict_literal_after_keywords�szITestUnpackingGeneralizations.test_double_star_dict_literal_after_keywordscCs|jd�dS)Nz[*{2}, 3, *[4]])r@)rrrr�test_list_display�sz.TestUnpackingGeneralizations.test_list_displaycCs|jd�dS)Nz{*{2}, 3, *[4]})r@)rrrr�test_set_display�sz-TestUnpackingGeneralizations.test_set_displaycCs|jd�dS)Nz{**{}})r@)rrrr�test_dict_display_1�sz0TestUnpackingGeneralizations.test_dict_display_1cCs|jd�dS)Nz{**{}, 3:4, **{5:6, 7:8}})r@)rrrr�test_dict_display_2�sz0TestUnpackingGeneralizations.test_dict_display_2cCs|jd�dS)Nzf(a, *b, *c, d))r@)rrrr�test_argument_unpacking_1�sz6TestUnpackingGeneralizations.test_argument_unpacking_1cCs|jd�dS)Nzf(**a, **b))r@)rrrr�test_argument_unpacking_2�sz6TestUnpackingGeneralizations.test_argument_unpacking_2cCs|jd�dS)Nzf(2, *a, *b, **b, **c, **d))r@)rrrr�test_argument_unpacking_3�sz6TestUnpackingGeneralizations.test_argument_unpacking_3N)
rrrrXrYrZr[r\r]r^r_r`rarrrrrW�srWc@speZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�TestFunctionAnnotationscCs|jd�dS)Nzdef f(x) -> list: pass)r@)rrrr�test_1�szTestFunctionAnnotations.test_1cCs|jd�dS)Nzdef f(x:int): pass)r@)rrrr�test_2�szTestFunctionAnnotations.test_2cCs|jd�dS)Nzdef f(*x:str): pass)r@)rrrr�test_3�szTestFunctionAnnotations.test_3cCs|jd�dS)Nzdef f(**x:float): pass)r@)rrrr�test_4szTestFunctionAnnotations.test_4cCs|jd�dS)Nzdef f(x, y:1+2): pass)r@)rrrr�test_5szTestFunctionAnnotations.test_5cCs|jd�dS)Nzdef f(a, (b:1, c:2, d)): pass)r@)rrrr�test_6szTestFunctionAnnotations.test_6cCs|jd�dS)Nz/def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6): pass)r@)rrrr�test_7
szTestFunctionAnnotations.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)r@)rrrrr�test_8
szTestFunctionAnnotations.test_8N)rrrrcrdrerfrgrhrirjrrrrrb�srbc@s(eZdZdd�Zdd�ZdS)�
TestExceptcCsd}|j|�dS)NzP
            try:
                x
            except E as N:
                y)r@)rrrrr�test_newszTestExcept.test_newcCsd}|j|�dS)NzN
            try:
                x
            except E, N:
                y)r@)rrrrr�test_oldszTestExcept.test_oldN)rrrrlrmrrrrrksrkc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestSetLiteralcCs|jd�dS)Nzx = {'one'})r@)rrrrrc'szTestSetLiteral.test_1cCs|jd�dS)Nzx = {'one', 1,})r@)rrrrrd*szTestSetLiteral.test_2cCs|jd�dS)Nzx = {'one', 'two', 'three'})r@)rrrrre-szTestSetLiteral.test_3cCs|jd�dS)Nzx = {2, 3, 4,})r@)rrrrrf0szTestSetLiteral.test_4N)rrrrcrdrerfrrrrrn&srnc@s(eZdZdd�Zdd�ZdS)�TestNumericLiteralscCs|jd�|jd�dS)NZ0o7777777777777Z0o7324528887)r@rB)rrrr�test_new_octal_notation5s
z+TestNumericLiterals.test_new_octal_notationcCs|jd�|jd�dS)NZ0b101010Z	0b0101021)r@rB)rrrr�test_new_binary_notation9s
z,TestNumericLiterals.test_new_binary_notationN)rrrrprqrrrrro4sroc@seZdZdd�ZdS)�TestClassDefcCsE|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)r@)rrrr�test_new_syntax?s




zTestClassDef.test_new_syntaxN)rrrrsrrrrrr>srrc@s7eZdZdZejdd��Zdd�ZdS)�TestParserIdempotencyz,A cut-down version of pytree_idempotency.py.c	 Csxtj�D]}t|d��}tj|j�d}WdQRX|j|d|�t|dd|��}|j�}WdQRXytj	|�}WnKt
k
r�}z+tdkr�tj
d||f�w
WYdd}~XnXt|�}t||�}|r
|jd|�q
WdS)Nr2rzcan't detect encoding for %s�r�encodingzParseError on file %s (%s)zIdempotency failed: %s)rZall_project_filesr:r�detect_encoding�readlineZassertIsNotNoner;rrr	r�warnings�warn�str�diffZfail)	r�filepath�fprv�sourceZtree�err�new�xrrr�test_all_project_filesLs"	z,TestParserIdempotency.test_all_project_filescCs8tjd�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=ZexpectedFailurer�r�rrrrrtGsrtc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestLiteralscCstjtj|�d�dS)Nz

)rrr�dedent)rrrrrr@iszTestLiterals.validatecCsd}|j|�dS)Nu�
            md5test(b"ª" * 80,
                    (b"Test Using Larger Than Block-Size Key "
                     b"and Larger Than One Block-Size Data"),
                    "6f630fad67cda0ee1fb1f562db3aa53e")
            )r@)rrrrr�test_multiline_bytes_literalslsz*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">
            """
            )r@)rrrrr�'test_multiline_bytes_tripquote_literalsusz4TestLiterals.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")
            )r@)rrrrr�test_multiline_str_literals~sz(TestLiterals.test_multiline_str_literalsN)rrrr@r�r�r�rrrrr�gs		r�cCs�zvtdd��}|jt|��WdQRX|jdd�}tjdd|dgdtdkrntjnd�SWdytj	d�Wnt
k
r�YnXXdS)	N�@�w�"z\"r|z-u�stdoutr)r:�writer{�replacer7ZcallrZDEVNULLr"�remove�OSError)�fn�result�frrrr|�s8
r|)'r��rrrZtest.supportrr"r&r7r8r r=ryZ
lib2to3.pgen2rrZpgen2.parser	Zlib2to3.pygramr
rZTestCaserrr>rCrErGrLrWrbrkrnrorrrtr�r|rrrr�<module>s<	A
4 !
	 !