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-2.pyc



���]o1�@s0ddlmZddlmZmZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddl
mZdd	lmZdd
lmZGdd�dej�ZGd
d�dej�ZGdd�dej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd �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)+�)�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�0/opt/alt/python35/lib64/python3.5/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)
NZsubdirrTr�randomZPYTHONHASHSEEDz-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�
subprocess�
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�unittestZskipIfr:r;r>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)rBr	�AssertionError)rrArrr�invalid_syntaxls

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

zTestYieldFrom.test_yield_fromN)rrrrHrrrrrG{srGc@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
        )rBrD)rrrr�test_await_expr�s

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




zTestClassDef.test_new_syntaxN)rrrrurrrrrt>srtc@s1eZdZejdd��Zdd�ZdS)�TestParserIdempotencyc	 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)Nr3rzcan'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�fprx�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)rrrr?ZexpectedFailurer�r�rrrrrvGsrvc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestLiteralscCstjtj|�d�dS)Nz

)rrr�dedent)rrrrrrBiszTestLiterals.validatecCsd}|j|�dS)Nu�
            md5test(b"ª" * 80,
                    (b"Test Using Larger Than Block-Size Key "
                     b"and Larger Than One Block-Size Data"),
                    "6f630fad67cda0ee1fb1f562db3aa53e")
            )rB)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">
            """
            )rB)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")
            )rB)rrrrr�test_multiline_str_literals~sz(TestLiterals.test_multiline_str_literalsN)rrrrBr�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}�replacer8�callr�DEVNULLr"�remove�OSError)�fn�result�frrrr~�s8
r~)&�rrrZtest.supportrr"r&r8r:r r?r{Z
lib2to3.pgen2rrZpgen2.parser	Zlib2to3.pygramr
rZTestCaserrr@rErGrIrNrYrdrmrprqrtrvr�r~rrrr�<module>
s:	A
4 !
	 !