
mY^!                 @   s  d  d l  m Z d d l m Z d d l m Z m Z d  d l m Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l Z d  d l m Z d d	 l m Z d  d
 l m Z Gd d   d e j  Z Gd d   d e j  Z Gd d   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 e  Z Gd d   d e  Z Gd d   d e  Z Gd d    d  e  Z Gd! d"   d" e j  Z  Gd# d$   d$ e  Z! d% d&   Z" d S)'    )with_statement   )support)drivertest_dir)verboseN)tokenize   )
ParseError)python_symbolsc               @   s   e  Z d  Z d d   Z d S)
TestDriverc             C   sa   d } t  j |  } |  j | j d j d j t j  |  j | j d j d j t j  d  S)Nzprint 1
print 2
r   r   )r   parse_stringZassertEqualZchildrentypesymsZ
print_stmt)selfst r   L/build/mts/release/bora-5583004/publish/lin64/lib64/python3.5/test_parser.pytest_formfeed   s    $zTestDriver.test_formfeedN)__name__
__module____qualname__r   r   r   r   r   r      s   r   c               @   s(   e  Z d  Z d d   Z d d   Z d S)GrammarTestc             C   s   t  j |  d  S)N)r   r   )r   coder   r   r   validate'   s    zGrammarTest.validatec             C   s6   y |  j  |  Wn t k
 r% Yn Xt d   d  S)Nz Syntax shouldn't have been valid)r   r
   AssertionError)r   r   r   r   r   invalid_syntax*   s
    zGrammarTest.invalid_syntaxN)r   r   r   r   r   r   r   r   r   r   &   s   r   c               @   s   e  Z d  Z d d   Z d S)TestMatrixMultiplicationc             C   s   |  j  d  |  j  d  d  S)Nza @ bza @= b)r   )r   r   r   r   #test_matrix_multiplication_operator4   s    z<TestMatrixMultiplication.test_matrix_multiplication_operatorN)r   r   r   r   r   r   r   r   r   3   s   r   c               @   s   e  Z d  Z d d   Z d S)TestYieldFromc             C   s+   |  j  d  |  j  d  |  j d  d  S)Nzyield from xz(yield from x) + yz
yield from)r   r   )r   r   r   r   test_yield_from:   s    zTestYieldFrom.test_yield_fromN)r   r   r   r!   r   r   r   r   r    9   s   r    c               @   s@   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 S)
TestAsyncAwaitc             C   s_   |  j  d  |  j  d  |  j  d  |  j  d  |  j d  |  j d  |  j d  d  S)NzLasync def foo():
                             await x
                      zhasync def foo():

            def foo(): pass

            def foo(): pass

            await x
        zasync def foo(): return await azTdef foo():
            def foo(): pass
            async def foo(): await x
        zawait xz5def foo():
                                   await xzedef foo():
            def foo(): pass
            async def foo(): pass
            await x
        )r   r   )r   r   r   r   test_await_exprA   s    zTestAsyncAwait.test_await_exprc             C   s+   |  j  d  |  j  d  |  j  d  d  S)Nz	async = 1z	await = 1zdef async(): pass)r   )r   r   r   r   test_async_var`   s    zTestAsyncAwait.test_async_varc             C   s   |  j  d  |  j d  d  S)NzDasync def foo():
                             async for a in b: passzDdef foo():
                                   async for a in b: pass)r   r   )r   r   r   r   test_async_withe   s    zTestAsyncAwait.test_async_withc             C   s   |  j  d  |  j d  d  S)Nz@async def foo():
                             async with a: passz@def foo():
                                   async with a: pass)r   r   )r   r   r   r   test_async_forl   s    zTestAsyncAwait.test_async_forN)r   r   r   r#   r$   r%   r&   r   r   r   r   r"   @   s   r"   c               @   s|   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d d   Z d d   Z	 d d   Z
 d d   Z d S)TestRaiseChangesc             C   s   |  j  d  d  S)Nraise)r   )r   r   r   r   test_2x_style_1u   s    z TestRaiseChanges.test_2x_style_1c             C   s   |  j  d  d  S)Nz
raise E, V)r   )r   r   r   r   test_2x_style_2x   s    z TestRaiseChanges.test_2x_style_2c             C   s   |  j  d  d  S)Nzraise E, V, T)r   )r   r   r   r   test_2x_style_3{   s    z TestRaiseChanges.test_2x_style_3c             C   s   |  j  d  d  S)Nzraise E, V, T, Z)r   )r   r   r   r   test_2x_style_invalid_1~   s    z(TestRaiseChanges.test_2x_style_invalid_1c             C   s   |  j  d  d  S)Nzraise E1 from E2)r   )r   r   r   r   test_3x_style   s    zTestRaiseChanges.test_3x_stylec             C   s   |  j  d  d  S)Nzraise E, V from E1)r   )r   r   r   r   test_3x_style_invalid_1   s    z(TestRaiseChanges.test_3x_style_invalid_1c             C   s   |  j  d  d  S)Nzraise E from E1, E2)r   )r   r   r   r   test_3x_style_invalid_2   s    z(TestRaiseChanges.test_3x_style_invalid_2c             C   s   |  j  d  d  S)Nzraise from E1, E2)r   )r   r   r   r   test_3x_style_invalid_3   s    z(TestRaiseChanges.test_3x_style_invalid_3c             C   s   |  j  d  d  S)Nzraise E from)r   )r   r   r   r   test_3x_style_invalid_4   s    z(TestRaiseChanges.test_3x_style_invalid_4N)r   r   r   r)   r*   r+   r,   r-   r.   r/   r0   r1   r   r   r   r   r'   t   s   r'   c               @   sp   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d d   Z d d   Z	 d d   Z
 d S)TestFunctionAnnotationsc             C   s   |  j  d  d  S)Nzdef f(x) -> list: pass)r   )r   r   r   r   test_1   s    zTestFunctionAnnotations.test_1c             C   s   |  j  d  d  S)Nzdef f(x:int): pass)r   )r   r   r   r   test_2   s    zTestFunctionAnnotations.test_2c             C   s   |  j  d  d  S)Nzdef f(*x:str): pass)r   )r   r   r   r   test_3   s    zTestFunctionAnnotations.test_3c             C   s   |  j  d  d  S)Nzdef f(**x:float): pass)r   )r   r   r   r   test_4   s    zTestFunctionAnnotations.test_4c             C   s   |  j  d  d  S)Nzdef f(x, y:1+2): pass)r   )r   r   r   r   test_5   s    zTestFunctionAnnotations.test_5c             C   s   |  j  d  d  S)Nzdef f(a, (b:1, c:2, d)): pass)r   )r   r   r   r   test_6   s    zTestFunctionAnnotations.test_6c             C   s   |  j  d  d  S)Nz/def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6): pass)r   )r   r   r   r   test_7   s    zTestFunctionAnnotations.test_7c             C   s   d } |  j  |  d  S)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   )r   r   r   r   r   test_8   s    zTestFunctionAnnotations.test_8N)r   r   r   r3   r4   r5   r6   r7   r8   r9   r:   r   r   r   r   r2      s   r2   c               @   s(   e  Z d  Z d d   Z d d   Z d S)
TestExceptc             C   s   d } |  j  |  d  S)NzP
            try:
                x
            except E as N:
                y)r   )r   r   r   r   r   test_new   s    zTestExcept.test_newc             C   s   d } |  j  |  d  S)NzN
            try:
                x
            except E, N:
                y)r   )r   r   r   r   r   test_old   s    zTestExcept.test_oldN)r   r   r   r<   r=   r   r   r   r   r;      s   r;   c               @   s@   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 S)
TestSetLiteralc             C   s   |  j  d  d  S)Nzx = {'one'})r   )r   r   r   r   r3      s    zTestSetLiteral.test_1c             C   s   |  j  d  d  S)Nzx = {'one', 1,})r   )r   r   r   r   r4      s    zTestSetLiteral.test_2c             C   s   |  j  d  d  S)Nzx = {'one', 'two', 'three'})r   )r   r   r   r   r5      s    zTestSetLiteral.test_3c             C   s   |  j  d  d  S)Nzx = {2, 3, 4,})r   )r   r   r   r   r6      s    zTestSetLiteral.test_4N)r   r   r   r3   r4   r5   r6   r   r   r   r   r>      s   r>   c               @   s(   e  Z d  Z d d   Z d d   Z d S)TestNumericLiteralsc             C   s   |  j  d  |  j d  d  S)NZ0o7777777777777Z0o7324528887)r   r   )r   r   r   r   test_new_octal_notation   s    z+TestNumericLiterals.test_new_octal_notationc             C   s   |  j  d  |  j d  d  S)NZ0b101010Z	0b0101021)r   r   )r   r   r   r   test_new_binary_notation   s    z,TestNumericLiterals.test_new_binary_notationN)r   r   r   r@   rA   r   r   r   r   r?      s   r?   c               @   s   e  Z d  Z d d   Z d S)TestClassDefc             C   sE   |  j  d  |  j  d  |  j  d  |  j  d  |  j  d  d  S)Nzclass B(t=7): passzclass B(t, *args): passzclass B(t, **kwargs): passz!class B(t, *args, **kwargs): passz&class B(t, y=9, *args, **kwargs): pass)r   )r   r   r   r   test_new_syntax   s
    zTestClassDef.test_new_syntaxN)r   r   r   rC   r   r   r   r   rB      s   rB   c               @   s1   e  Z d  Z e j d d    Z d d   Z d S)TestParserIdempotencyc       	       C   s  xt  j   D]} t | d   } t j | j  d } Wd  QRX|  j | d |  t | d d |  } | j   } Wd  QRXy t j	 |  } WnK t
 k
 r } z+ t d k r t j d | | f  w WYd  d  } ~ Xn Xt |  } t | |  } | r |  j d |  q Wd  S)Nrbr   zcan't detect encoding for %srencodingzParseError on file %s (%s)zIdempotency failed: %s)r   Zall_project_filesopenr   detect_encodingreadlineZassertIsNotNonereadr   r   r
   r   warningswarnstrdiffZfail)	r   filepathfprG   sourceZtreeerrnewxr   r   r   test_all_project_files   s"    	z,TestParserIdempotency.test_all_project_filesc             C   s8   t  j d  t  j d  t  j d  t  j d  d  S)Nza, *b, c = x
z[*a, b] = x
z(z, *y, w) = m
zfor *z, m in d: pass
)r   r   )r   r   r   r   test_extended_unpacking   s    z-TestParserIdempotency.test_extended_unpackingN)r   r   r   unittestZexpectedFailurerV   rW   r   r   r   r   rD      s   rD   c               @   s@   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 S)
TestLiteralsc             C   s   t  j t j |  d  d  S)Nz

)r   r   r   dedent)r   r   r   r   r   r     s    zTestLiterals.validatec             C   s   d } |  j  |  d  S)Nu   
            md5test(b"ª" * 80,
                    (b"Test Using Larger Than Block-Size Key "
                     b"and Larger Than One Block-Size Data"),
                    "6f630fad67cda0ee1fb1f562db3aa53e")
            )r   )r   r   r   r   r   test_multiline_bytes_literals  s    z*TestLiterals.test_multiline_bytes_literalsc             C   s   d } |  j  |  d  S)Nz
            b"""
            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN">
            """
            )r   )r   r   r   r   r   'test_multiline_bytes_tripquote_literals  s    z4TestLiterals.test_multiline_bytes_tripquote_literalsc             C   s   d } |  j  |  d  S)Nu   
            md5test("ª" * 80,
                    ("Test Using Larger Than Block-Size Key "
                     "and Larger Than One Block-Size Data"),
                    "6f630fad67cda0ee1fb1f562db3aa53e")
            )r   )r   r   r   r   r   test_multiline_str_literals  s    z(TestLiterals.test_multiline_str_literalsN)r   r   r   r   r[   r\   r]   r   r   r   r   rY     s   		rY   c             C   s   zv t  d d   } | j t |   Wd  QRX|  j d d  }  t j d d |  d g d t d k  rn t j n d  SWd  y t j	 d  Wn t
 k
 r Yn XXd  S)	N@w"z\"rO   z-ustdoutr   )rH   writerN   replace
subprocesscallr   DEVNULLosremoveOSError)fnresultfr   r   r   rO   #  s    8rO   )#Z
__future__r    r   r   r   Ztest.supportr   rg   sysrX   rL   rd   Zlib2to3.pgen2r   Zpgen2.parser
   Zlib2to3.pygramr   r   ZTestCaser   r   r   r    r"   r'   r2   r;   r>   r?   rB   rD   rY   rO   r   r   r   r   <module>	   s2   	4
	 !