Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/lib2to3/tests/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/lib2to3/tests/__pycache__/test_parser.cpython-34.pyo

�
j f�@s�dZddlmZddlmZddlmZmZddlmZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZd	d
lmZddlmZGdd
�d
ej�ZGdd�dej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGd 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.
�)�with_statement�)�support)�driver�test_dir)�verboseN)�tokenize�)�
ParseError)�python_symbolsc@seZdZdd�ZdS)�
TestDrivercCsad}tj|�}|j|jdjdjtj�|j|jdjdjtj�dS)Nzprint 1
print 2
rr)r�parse_stringZassertEqualZchildren�type�symsZ
print_stmt)�self�s�t�r�>/opt/alt/python34/lib64/python3.4/lib2to3/tests/test_parser.py�
test_formfeeds$zTestDriver.test_formfeedN)�__name__�
__module__�__qualname__rrrrrrsrc@s(eZdZdd�Zdd�ZdS)�GrammarTestcCstj|�dS)N)rr
)r�coderrr�validate'szGrammarTest.validatecCs6y|j|�Wntk
r%Yn
Xtd��dS)Nz Syntax shouldn't have been valid)rr
�AssertionError)rrrrr�invalid_syntax*s

zGrammarTest.invalid_syntaxN)rrrrrrrrrr&src@seZdZdd�ZdS)�TestMatrixMultiplicationcCs|jd�|jd�dS)Nza @ bza @= b)r)rrrr�#test_matrix_multiplication_operator4s
z<TestMatrixMultiplication.test_matrix_multiplication_operatorN)rrrrrrrrr3src@seZdZdd�ZdS)�
TestYieldFromcCs+|jd�|jd�|jd�dS)Nzyield from xz(yield from x) + yz
yield from)rr)rrrrr:s

z1TestYieldFrom.test_matrix_multiplication_operatorN)rrrrrrrrr 9sr c@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_1Asz TestRaiseChanges.test_2x_style_1cCs|jd�dS)Nz
raise E, V)r)rrrr�test_2x_style_2Dsz TestRaiseChanges.test_2x_style_2cCs|jd�dS)Nz
raise E, V, T)r)rrrr�test_2x_style_3Gsz TestRaiseChanges.test_2x_style_3cCs|jd�dS)Nzraise E, V, T, Z)r)rrrr�test_2x_style_invalid_1Jsz(TestRaiseChanges.test_2x_style_invalid_1cCs|jd�dS)Nzraise E1 from E2)r)rrrr�
test_3x_styleMszTestRaiseChanges.test_3x_stylecCs|jd�dS)Nzraise E, V from E1)r)rrrr�test_3x_style_invalid_1Psz(TestRaiseChanges.test_3x_style_invalid_1cCs|jd�dS)Nzraise E from E1, E2)r)rrrr�test_3x_style_invalid_2Ssz(TestRaiseChanges.test_3x_style_invalid_2cCs|jd�dS)Nzraise from E1, E2)r)rrrr�test_3x_style_invalid_3Vsz(TestRaiseChanges.test_3x_style_invalid_3cCs|jd�dS)Nzraise E from)r)rrrr�test_3x_style_invalid_4Ysz(TestRaiseChanges.test_3x_style_invalid_4N)rrrr#r$r%r&r'r(r)r*r+rrrrr!@sr!c@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_2bszTestFunctionAnnotations.test_2cCs|jd�dS)Nzdef f(*x:str): pass)r)rrrr�test_3eszTestFunctionAnnotations.test_3cCs|jd�dS)Nzdef f(**x:float): pass)r)rrrr�test_4hszTestFunctionAnnotations.test_4cCs|jd�dS)Nzdef f(x, y:1+2): pass)r)rrrr�test_5kszTestFunctionAnnotations.test_5cCs|jd�dS)Nzdef f(a, (b:1, c:2, d)): pass)r)rrrr�test_6nszTestFunctionAnnotations.test_6cCs|jd�dS)Nz/def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6): pass)r)rrrr�test_7qszTestFunctionAnnotations.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_8tszTestFunctionAnnotations.test_8N)rrrr-r.r/r0r1r2r3r4rrrrr,^sr,c@s(eZdZdd�Zdd�ZdS)�
TestExceptcCsd}|j|�dS)NzP
            try:
                x
            except E as N:
                y)r)rrrrr�test_new{szTestExcept.test_newcCsd}|j|�dS)NzN
            try:
                x
            except E, N:
                y)r)rrrrr�test_old�szTestExcept.test_oldN)rrrr6r7rrrrr5zsr5c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestSetLiteralcCs|jd�dS)Nzx = {'one'})r)rrrrr-�szTestSetLiteral.test_1cCs|jd�dS)Nzx = {'one', 1,})r)rrrrr.�szTestSetLiteral.test_2cCs|jd�dS)Nzx = {'one', 'two', 'three'})r)rrrrr/�szTestSetLiteral.test_3cCs|jd�dS)Nzx = {2, 3, 4,})r)rrrrr0�szTestSetLiteral.test_4N)rrrr-r.r/r0rrrrr8�sr8c@s(eZdZdd�Zdd�ZdS)�TestNumericLiteralscCs|jd�|jd�dS)NZ0o7777777777777Z0o7324528887)rr)rrrr�test_new_octal_notation�s
z+TestNumericLiterals.test_new_octal_notationcCs|jd�|jd�dS)NZ0b101010Z	0b0101021)rr)rrrr�test_new_binary_notation�s
z,TestNumericLiterals.test_new_binary_notationN)rrrr:r;rrrrr9�sr9c@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)rrrr=rrrrr<�sr<c@s7eZdZdZejdd��Zdd�ZdS)�TestParserIdempotencyz,A cut-down version of pytree_idempotency.py.c	Cs xtj�D]}t|d��}tj|j�d}WdQX|j|d|�t|dd|��}|j�}WdQXytj	|�}WnNt
k
r�}z.tdkr�tj
d||f�nw
WYdd}~XnXt|�}t||�}|r
|jd|�q
q
WdS)N�rbrzcan't detect encoding for %s�r�encodingzParseError on file %s (%s)zIdempotency failed: %s)rZall_project_files�openr�detect_encoding�readlineZassertIsNotNone�readrr
r
r�warnings�warn�str�diffZfail)	r�filepath�fprA�sourceZtree�err�new�xrrr�test_all_project_files�s"	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__�unittestZexpectedFailurerPrQrrrrr>�sr>c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestLiteralscCstjtj|�d�dS)Nz

)rr
r�dedent)rrrrrr�szTestLiterals.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_literals�sz*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_literals�sz4TestLiterals.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)rrrrrVrWrXrrrrrT�s		rTcCs�zutdd��}|jt|��WdQX|jdd�}tjdd|dgdtdkrmtjnd�SWdytj	d�Wnt
k
r�YnXXdS)	N�@�w�"z\"rIz-u�stdoutr)rB�writerH�replace�
subprocess�callrZDEVNULL�os�remove�OSError)�fn�result�frrrrI�s8
rI)#rRZ
__future__r�rrrZtest.supportrra�sysrSrFr_Z
lib2to3.pgen2rZpgen2.parser
Zlib2to3.pygramrrZTestCaserrrr r!r,r5r8r9r<r>rTrIrrrr�<module>s2	

	 !