B
    u9a&                 @   s   d dl mZ d dlZd dlmZ d dlmZ d dlZd dlZe	dZ
dd ZG dd	 d	ejZG d
d dejZedkre  dS )    )partialN)support)dedentz\((\S+).py, line (\d+)c             C   s   t t| }|ddS )N      )rxsearchstrgroup)msgmo r   !/usr/lib/python3.7/test_future.pyget_error_location   s    r   c               @   s   e Zd Zd!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d Zdd Zdd Zdd Zdd Zdd Zd S )"
FutureTestr   c             C   sR   |  d||f t| | tj|j|d  | |j| | |j| d S )Nz%s.py, line %dz.py)	ZassertInr	   assertEqualospathbasenamefilenamelinenooffset)selferrr   r   r   r   r   r   check_syntax_error   s    zFutureTest.check_syntax_errorc          	   C   s4   t d  ddlm} | |jd W d Q R X d S )Nfuture_test1r   )r      )r   CleanImporttestr   r   result)r   r   r   r   r   test_future1   s    zFutureTest.test_future1c          	   C   s4   t d  ddlm} | |jd W d Q R X d S )Nfuture_test2r   )r!   r   )r   r   r   r!   r   r   )r   r!   r   r   r   test_future2   s    zFutureTest.test_future2c          	   C   s&   t d ddlm} W d Q R X d S )Ntest_future3r   )r#   )r   r   r   r#   )r   r#   r   r   r   r#   "   s    zFutureTest.test_future3c          	   C   s6   |  t}ddlm} W d Q R X | |jdd d S )Nr   )badsyntax_future3r$      )assertRaisesSyntaxErrorr   r$   r   	exception)r   cmr$   r   r   r   test_badfuture3&   s    zFutureTest.test_badfuture3c          	   C   s6   |  t}ddlm} W d Q R X | |jdd d S )Nr   )badsyntax_future4r+   r%   )r&   r'   r   r+   r   r(   )r   r)   r+   r   r   r   test_badfuture4+   s    zFutureTest.test_badfuture4c          	   C   s6   |  t}ddlm} W d Q R X | |jdd d S )Nr   )badsyntax_future5r-      )r&   r'   r   r-   r   r(   )r   r)   r-   r   r   r   test_badfuture50   s    zFutureTest.test_badfuture5c          	   C   s6   |  t}ddlm} W d Q R X | |jdd d S )Nr   )badsyntax_future6r0   r%   )r&   r'   r   r0   r   r(   )r   r)   r0   r   r   r   test_badfuture65   s    zFutureTest.test_badfuture6c          	   C   s8   |  t}ddlm} W d Q R X | |jddd d S )Nr   )badsyntax_future7r2   r%   5   )r&   r'   r   r2   r   r(   )r   r)   r2   r   r   r   test_badfuture7:   s    zFutureTest.test_badfuture7c          	   C   s6   |  t}ddlm} W d Q R X | |jdd d S )Nr   )badsyntax_future8r5   r%   )r&   r'   r   r5   r   r(   )r   r)   r5   r   r   r   test_badfuture8?   s    zFutureTest.test_badfuture8c          	   C   s8   |  t}ddlm} W d Q R X | |jddd d S )Nr   )badsyntax_future9r7   r%   )r&   r'   r   r7   r   r(   )r   r)   r7   r   r   r   test_badfuture9D   s    zFutureTest.test_badfuture9c          	   C   s8   |  t}ddlm} W d Q R X | |jddd d S )Nr   )badsyntax_future10r9   r%   )r&   r'   r   r9   r   r(   )r   r)   r9   r   r   r   test_badfuture10I   s    zFutureTest.test_badfuture10c             C   s\   yt d W n tk
r    Y nX | d yt d W n tk
rL   Y nX | d d S )Nz.from __future__ import print_function; print 0zsyntax error didn't occurz0from __future__ import (print_function); print 0)execr'   Zfail)r   r   r   r   test_parserhackN   s    
zFutureTest.test_parserhackc          	   C   s&   t d ddlm} W d Q R X d S )Nztest.test_future5r   )test_future5)r   r   r   r=   )r   r=   r   r   r   test_multiple_featuresb   s    z!FutureTest.test_multiple_featuresc             C   s$   i }t di | | |d t d S )Nz/from __future__ import unicode_literals; x = ''x)r;   ZassertIsInstancer	   )r   scoper   r   r   test_unicode_literals_execf   s    z%FutureTest.test_unicode_literals_execN)r   )__name__
__module____qualname__r   r    r"   r#   r*   r,   r/   r1   r4   r6   r8   r:   r<   r>   rA   r   r   r   r   r      s   
r   c               @   s.   e Zd ZedZdd Zd
ddZdd	 ZdS )AnnotationsFutureTestCasez
        from __future__ import annotations
        def f() -> {ann}:
            ...
        def g(arg: {ann}) -> None:
            ...
        var: {ann}
        var2: {ann} = None
        c             C   sv   i }t | jj|di | |d jd }|d jd }|d d }|d d }| || | || | || |S )	N)annfreturngarg__annotations__varZvar2)r;   templateformatrK   r   )r   
annotationr@   Zfunc_ret_annZfunc_arg_annZvar_ann1Zvar_ann2r   r   r   	getActualx   s    z#AnnotationsFutureTestCase.getActualNFc             C   sZ   |  |}|d kr&|s|n
|dd }|rJ| || |dddd}| || d S )Nr   ( ))rP   ZassertNotEqualreplacer   )r   rO   ZexpectedZdrop_parensZis_tupleactualr   r   r   assertAnnotationEqual   s    
z/AnnotationsFutureTestCase.assertAnnotationEqualc             C   s  | j }|d |d |d |d |d |d |d |d |d	 |d
 |d |d |d |d |d |d |d |d |d |d |d |d |d |d |d |d |d |d |d |d |d |d  |d! |d" |d# |d$ |d% |d& |d' |d( |d) |d* |d+ |d, |d- |d. |d/ |d0 |d1 |d2 |d3 |d4 |d5 |d6 |d7 |d8 |d9 |d: |d; |d< |d= |d> |d? |d@ |dA |dB |dC |dD |dE |dF |dG |dH |dI |dJ |dK |dL |dM |dN |dO |dP |dQ |dR |dS |dT |dU |dV |dW |dX |dY |dZ |d[ |d\ |d] |d^ |d_ |d` |da |db |dc |dd |de |df |dg |dh |di |dj |dk |dl |dm |dn |do |dp |dq |dr |ds |dt |du |dv |dw |dx |dy |dz |d{d| |d}d8 d S )~Nz...z'some_string'zb'\xa3'NameNoneTrueFalse1z1.0Z1jzTrue or FalsezTrue or False or NonezTrue and FalsezTrue and False and NonezName1 and Name2 or Name3zName1 and (Name2 or Name3)zName1 or Name2 and Name3z(Name1 or Name2) and Name3z"Name1 and Name2 or Name3 and Name4z!Name1 or Name2 and Name3 or Name4za + b + (c + d)za * b * (c * d)z(a ** b) ** c ** dzv1 << 2z1 >> v2z1 % finishedz"1 + v2 - v3 * 4 ^ 5 ** v6 / 7 // 8z	not greatznot not greatz~greatz+valuez++valuez-1z!~int and not v1 ^ 123 + v2 | Trueza + (not b)zlambda: Nonezlambda arg: Nonezlambda a=True: azlambda a, b, c=True: az-lambda a, b, c=True, *, d=1 << v2, e='str': az9lambda a, b, c=True, *vararg, d, e='str', **kwargs: a + bzlambda x: lambda y: x + yz1 if True else 2z4str or None if int or True else str or bytes or Nonez;str or None if (1 if True else 2) else str or bytes or Nonez"0 if not x else 1 if x > 0 else -1z (1 if x > 0 else -1) if x else 0z+{'2.7': dead, '3.7': long_live or die_hard}z@{'2.7': dead, '3.7': long_live or die_hard, **{'3.6': verygood}}z{**a, **b, **c}zC{'2.7', '3.6', '3.7', '3.8', '3.9', '4.0' if gilectomy else '3.10'}z{*a, *b, *c}z?({'a': 'b'}, True or False, +value, 'string', b'bytes') or Nonez()z(a,)z(a, b)z	(a, b, c)z(*a, *b, *c)z[]z6[1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C]z[*a, *b, *c]z{i for i in (1, 2, 3)}z{i ** 2 for i in (1, 2, 3)}z3{i ** 2 for i, _ in ((1, 'a'), (2, 'b'), (3, 'c'))}z2{i ** 2 + j for i in (1, 2, 3) for j in (1, 2, 3)}z[i for i in (1, 2, 3)]z[i ** 2 for i in (1, 2, 3)]z3[i ** 2 for i, _ in ((1, 'a'), (2, 'b'), (3, 'c'))]z2[i ** 2 + j for i in (1, 2, 3) for j in (1, 2, 3)]z(i for i in (1, 2, 3))z(i ** 2 for i in (1, 2, 3))z3(i ** 2 for i, _ in ((1, 'a'), (2, 'b'), (3, 'c')))z2(i ** 2 + j for i in (1, 2, 3) for j in (1, 2, 3))z{i: 0 for i in (1, 2, 3)}z1{i: j for i, j in ((1, 'a'), (2, 'b'), (3, 'c'))}z[(x, y) for x, y in (a, b)]z[(x,) for x, in (a,)]zPython3 > Python2 > COBOLzLife is Lifezcall()z	call(arg)zcall(kwarg='hey')zcall(arg, kwarg='hey')z&call(arg, *args, another, kwarg='hey')z6call(arg, another, kwarg='hey', **kwargs, kwarg2='ho')zlukasz.langa.plzcall.me(maybe)z1 .realz	1.0 .realz....__class__z	list[str]zdict[str, int]z	set[str,]ztuple[str, ...]z&tuple[str, int, float, dict[str, int]]zslice[0]z
slice[0:1]zslice[0:1:2]zslice[:]z
slice[:-1]z	slice[1:]zslice[::-1]z	slice[()]zslice[a, b:c, d:e:f]zslice[(x for x in a)]zCstr or None if sys.version_info[0] > (3,) else str or bytes or Nonez5f'f-string without formatted values is just a string'zf'{{NOT a formatted value}}'z:f'some f-string with {a} {few():.2f} {formatted.values!r}'zf"{f'{nested} inner'} outer"z:f'space between opening braces: { {a for a in (1, 2, 3)}}'zf'{(lambda x: x)}'z!f'{(None if a else lambda x: x)}'z!(yield from outside_of_generator)z(yield)z(yield a + b)z<await some.complicated[0].call(with_args=True or 1 is not 1)z[x for x in (a if b else c)]z![x for x in a if (b if c else d)]zf(x for x in a)zf(1, (x for x in a))zf((x for x in a), 2)z(((a)))az
(((a, b))))rW   )r   eqr   r   r   test_annotations   s    
z*AnnotationsFutureTestCase.test_annotations)NFF)rB   rC   rD   r   rM   rP   rW   r_   r   r   r   r   rE   k   s
   	
rE   __main__)	functoolsr   Zunittestr   r   textwrapr   r   recompiler   r   ZTestCaser   rE   rB   mainr   r   r   r   <module>   s   
[ &