B
    u9a–‰  ã               @   s¦   d dl Z d dlZd dl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mZ G dd„ dejƒZG dd„ dejƒZG dd	„ d	ejƒZed
kr¢e ¡  dS )é    N)Úsupport)Úscript_helperÚFakePathc               @   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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ejd%krªd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Z d:d;„ Z!d<d=„ Z"d>d?„ Z#e$j%d@dA„ ƒZ&dBdC„ Z'dDdE„ Z(dFdG„ Z)dHdI„ Z*e$j%dJdK„ ƒZ+dLdM„ Z,dNdO„ Z-e$j%dPdQ„ ƒZ.e$j%dRdS„ ƒZ/dTdU„ Z0dVdW„ Z1dXdY„ Z2dZS )[ÚTestSpecificsc             C   s   t |ddƒ d S )Nz<single>Úsingle)Úcompile)ÚselfÚsource© r
   ú"/usr/lib/python3.7/test_compile.pyÚcompile_single   s    zTestSpecifics.compile_singlec             C   s   |   t| j|¡ d S )N)ÚassertRaisesÚSyntaxErrorr   )r   r	   r
   r
   r   ÚassertInvalidSingle   s    z!TestSpecifics.assertInvalidSinglec             C   s   t dddƒ t dddƒ d S )NÚhiz<test>Úexeczhi)r   )r   r
   r
   r   Útest_no_ending_newline   s    z$TestSpecifics.test_no_ending_newlinec             C   s   t dddƒ d S )NÚ z<test>r   )r   )r   r
   r
   r   Ú
test_empty   s    zTestSpecifics.test_emptyc             C   s4   t dddƒ t dddƒ t dddƒ t dddƒ d S )Nz
z<test>r   úzhi
stuff
def f():
    passz(this_isreally_old_macdef f():
    pass)r   )r   r
   r
   r   Útest_other_newlines   s    z!TestSpecifics.test_other_newlinesc             C   sH   |   ttddd¡ dd l}|j}t|ddƒ |  d|¡ t|d|ƒ d S )Nz__debug__ = 1ú?r   r   Ú	__debug__ZsureT)r   r   r   Úbuiltinsr   ÚsetattrÚassertEqual)r   r   Úprevr
   r
   r   Útest_debug_assignment!   s    z#TestSpecifics.test_debug_assignmentc             C   sX   |   ttd¡ |   ttd¡ |   ttd¡ |   ttd¡ |   ttd¡ |   ttd¡ d S )Nzlambda a,a:0zlambda a,a=1:0zlambda a=1,a=1:0zdef f(a, a): passzdef f(a = 0, a = 1): passzdef f(a): global a; a = 1)r   r   Úevalr   )r   r
   r
   r   Útest_argument_handling*   s    z$TestSpecifics.test_argument_handlingc             C   s   |   ttddd¡ d S )Nz1+*3Úfilenamer   )r   r   r   )r   r
   r
   r   Útest_syntax_error3   s    zTestSpecifics.test_syntax_errorc             C   s   |   ttddd¡ d S )Nz	f(None=1)z<string>r   )r   r   r   )r   r
   r
   r   Útest_none_keyword_arg6   s    z#TestSpecifics.test_none_keyword_argc             C   s   |   ttd¡ d S )Nzdef f(a): global a; a = 1)r   r   r   )r   r
   r
   r   Útest_duplicate_global_local9   s    z)TestSpecifics.test_duplicate_global_localc             C   s.  G dd„ dƒ}|ƒ }t ƒ }td||ƒ |  |jd¡ ytd||ƒ W n tk
rX   Y nX |  d¡ td||ƒ |  |jdtd	ƒf¡ td
||ƒ |  |jd|f¡ td||ƒ |  |jd|f¡ |  ttd|¡ G dd„ dƒ}|ƒ }|  ttd||¡ G dd„ dt	ƒ}|ƒ }td||ƒ |  |d d¡ d S )Nc               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	zBTestSpecifics.test_exec_with_general_mapping_for_locals.<locals>.Mz9Test mapping interface versus possible calls from eval().c             S   s   |dkrdS t ‚d S )NÚaé   )ÚKeyError)r   Úkeyr
   r
   r   Ú__getitem__@   s    zNTestSpecifics.test_exec_with_general_mapping_for_locals.<locals>.M.__getitem__c             S   s   ||f| _ d S )N)Úresults)r   r'   Úvaluer
   r
   r   Ú__setitem__D   s    zNTestSpecifics.test_exec_with_general_mapping_for_locals.<locals>.M.__setitem__c             S   s   t dƒS )NÚxyz)Úlist)r   r
   r
   r   ÚkeysF   s    zGTestSpecifics.test_exec_with_general_mapping_for_locals.<locals>.M.keysN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r(   r+   r.   r
   r
   r
   r   ÚM>   s   r3   zz = a)Úzr%   zz = bzDid not detect a KeyErrorz	z = dir()r4   r,   zz = globals()zz = locals()c               @   s   e Zd ZdZdS )zBTestSpecifics.test_exec_with_general_mapping_for_locals.<locals>.AzNon-mappingN)r/   r0   r1   r2   r
   r
   r
   r   ÚA[   s   r5   c               @   s   e Zd Zdd„ ZdS )zBTestSpecifics.test_exec_with_general_mapping_for_locals.<locals>.Dc             S   s   |dkrdS t  | |¡S )Nr$   r%   )Údictr(   )r   r'   r
   r
   r   r(   c   s    zNTestSpecifics.test_exec_with_general_mapping_for_locals.<locals>.D.__getitem__N)r/   r0   r1   r(   r
   r
   r
   r   ÚDb   s   r7   r%   )
Úglobalsr   r   r)   Ú	NameErrorÚfailr-   r   Ú	TypeErrorr6   )r   r3   ÚmÚgr5   r7   Údr
   r
   r   Ú)test_exec_with_general_mapping_for_locals<   s0    
z7TestSpecifics.test_exec_with_general_mapping_for_localsc             C   s@   ddd  }i }d|fd  }t ||ƒ |  |d dƒd¡ d S )	Nz	x = x or z-xiÄ	  zÞ
def f(x):
    %s
    %s
    %s
    %s
    %s
    %s
    %s
    %s
    %s
    %s
    # the expressions above have no effect, x == argument
    while x:
        x -= 1
        # EXTENDED_ARG/JUMP_ABSOLUTE here
    return x
é
   Úfé   r   )r   r   )r   Zlongexprr=   Úcoder
   r
   r   Útest_extended_argk   s
    
zTestSpecifics.test_extended_argc             C   s   |   ttd¡ d S )Nzdef f(a=1, b): pass)r   r   r   )r   r
   r
   r   Útest_argument_orderƒ   s    z!TestSpecifics.test_argument_orderc             C   s<   |   ttd¡ |   ttd¡ |   ttd¡ |   ttd¡ d S )NZ2ez2.0e+z1e-z3-4e/21)r   r   r   )r   r
   r
   r   Útest_float_literals†   s    z!TestSpecifics.test_float_literalsc             C   s   d}t |ddƒ d S )Nz
if 1:
    if 2:
        passz<string>r   )r   )r   Úsr
   r
   r   Útest_indentation   s    zTestSpecifics.test_indentationc             C   sD   d  dgd dg ¡}t|ddƒ}|  |jd¡ |  |jtƒ ¡ d S )Nr   Ú
é   ZspamÚfnr   i  )Újoinr   r   Úco_firstlinenoÚ	co_lnotabÚbytes)r   Zs256Úcor
   r
   r   Útest_leading_newlines™   s    z#TestSpecifics.test_leading_newlinesc             C   s   xdD ]}|   tt|¡ qW |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd	¡ |  td
ƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd¡ |  tdƒd ¡ |  td!ƒd"¡ |  td#ƒd$¡ |  td%ƒd&¡ |  td'ƒd(¡ d S ))N)Z077787Z0xjz0x.Z0eZ090000000000000Z080000000000000Z000000000000009Z000000000000008Z0b42Z0BADCAFEZ0o123456789z0b1.1z0o4.2Z0b101j2Z0o153j2Z0b100e1Z0o777e1Z0777Z000777Z000000000000007Z0xfféÿ   z0777.i	  z0777.0Z8000000000000000000000000000000000000000000000000000777e0Z0777e1iZ  Z0e0r   z	0000e-012z09.5g      #@Z0777jy             Hˆ@Z000Z00jy                z00.0Z0e3z090000000000000.g  è°vÔBz&090000000000000.0000000000000000000000Z090000000000000e0z090000000000000e-0Z090000000000000jy          è°vÔBz000000000000008.g       @z000000000000009.g      "@Z0b101010é*   z-0b000000000010éþÿÿÿZ0o777iÿ  z
-0o0000010iøÿÿÿ)r   r   r   r   )r   Úargr
   r
   r   Ú!test_literals_with_leading_zeroesŸ   s4    
z/TestSpecifics.test_literals_with_leading_zeroesc             C   s®   t jdkr4d}|  t|ƒd¡ |  td| ƒd¡ n>t jdkrhd}|  t|ƒd¡ |  td| ƒd	¡ n
|  d
¡ |  tdt j d  ƒt¡ |  tdt j d  ƒt¡ d S )NiÿÿÿZ
0xffffffffl   ÿÿ ú-lýÿÿÿÿÿ l   ÿÿÿÿ Z0xffffffffffffffffl   ÿÿÿÿ lûÿÿÿÿÿÿÿ z)How many bits *does* this machine have???z%sé   é   )ÚsysÚmaxsizer   r   r:   ÚassertIsInstanceÚint)r   Zall_one_bitsr
   r
   r   Útest_unary_minusÀ   s    


zTestSpecifics.test_unary_minusl   ÿÿÿÿ c       
      C   sL   d}d}d}d}d}d}d}d}x&| j jjD ]}	|	d k	r,|  |	t¡ q,W d S )	Nl        lýÿÿÿ     l          lüÿÿÿ       l            lûÿÿÿ         l   ÿÿÿÿ lûÿÿÿÿÿÿÿ )Útest_32_63_bit_valuesÚ__code__Ú	co_constsr\   r]   )
r   r$   ÚbÚcr>   ÚerA   r=   ÚhÚvariabler
   r
   r   r_   Ô   s    z#TestSpecifics.test_32_63_bit_valuesc             C   s(   dpd\}}|   |d¡ |   |d¡ d S )N)rX   éÿÿÿÿ)rg   rX   rX   rg   )r   )r   ÚiÚjr
   r
   r   Útest_sequence_unpacking_errorâ   s    z+TestSpecifics.test_sequence_unpacking_errorc             C   sZ   ddddddddd	d
ddg}x8|D ]0}|d7 }|   tt|dd¡ |   tt|dd¡ q"W d S )NzNone = 0z	None += 0z__builtins__.None = 0zdef None(): passzclass None: passz(a, None) = 0, 0zfor None in range(10): passzdef f(None): passzimport Nonezimport x as Nonezfrom x import Nonezfrom x import y as NonerI   Útmpr   r   )r   r   r   )r   ZstmtsÚstmtr
   r
   r   Útest_none_assignmentè   s     
z"TestSpecifics.test_none_assignmentc             C   s   ddddddddd	d
dddddg}ddddddddddddddddd d!d"d#d$d%g}x|D ]}t |d&d'ƒ qXW x|D ]}|  tt |d&d'¡ qrW d S )(Nz
import syszimport os, syszimport os as barzimport os.path as barz0from __future__ import nested_scopes, generatorsz2from __future__ import (nested_scopes,
generators)z3from __future__ import (nested_scopes,
generators,)z%from sys import stdin, stderr, stdoutz'from sys import (stdin, stderr,
stdout)z(from sys import (stdin, stderr,
stdout,)z(from sys import (stdin
, stderr, stdout)z)from sys import (stdin
, stderr, stdout,)z7from sys import stdin as si, stdout as so, stderr as sez9from sys import (stdin as si, stdout as so, stderr as se)z:from sys import (stdin as si, stdout as so, stderr as se,)zimport (os, sys)zimport (os), (sys)zimport ((os), (sys))zimport (syszimport sys)zimport (os,)zimport os As barzimport os.path a barzfrom sys import stdin As stdoutzfrom sys import stdin a stdoutzfrom (sys) import stdinz%from __future__ import (nested_scopesz%from __future__ import nested_scopes)z0from __future__ import nested_scopes,
generatorszfrom sys import (stdinzfrom sys import stdin)z%from sys import stdin, stdout,
stderrzfrom sys import stdin sizfrom sys import stdin,zfrom sys import (*)z(from sys import (stdin,, stdout, stderr)z from sys import (stdin, stdout),rk   r   )r   r   r   )r   Zsucceedr:   rl   r
   r
   r   Útest_importü   sR    

zTestSpecifics.test_importc             C   s.   dd„ }|ƒ \}}|   t|jƒt|jƒ¡ d S )Nc              S   s   ddd„} ddd„}| |fS )NrX   c             S   s   | S )Nr
   )Úxr
   r
   r   Ú<lambda>.  ó    zITestSpecifics.test_for_distinct_code_objects.<locals>.f.<locals>.<lambda>rY   c             S   s   | S )Nr
   )ro   r
   r
   r   rp   /  rq   )rX   )rY   r
   )Úf1Úf2r
   r
   r   rA   -  s    

z7TestSpecifics.test_for_distinct_code_objects.<locals>.f)ÚassertNotEqualÚidr`   )r   rA   rr   rs   r
   r
   r   Útest_for_distinct_code_objects+  s    
z,TestSpecifics.test_for_distinct_code_objectsc             C   s   dd„ }|   |j¡ d S )Nc               S   s   dS )NZfoor
   r
   r
   r
   r   rp   5  rq   z/TestSpecifics.test_lambda_doc.<locals>.<lambda>)ZassertIsNoner2   )r   Úlr
   r
   r   Útest_lambda_doc4  s    zTestSpecifics.test_lambda_docc             C   sÆ   d}|   tt|dd¡ d}t|ddƒ |  t|ƒd¡ d}|  t|ƒd¡ d}|  t|ƒd¡ d	}|  t|ƒd¡ d
}|  t|ƒd¡ d}|  t|ƒd¡ d}|  t|ƒd¡ d}|  t|ƒd¡ d S )Ns#   # -*- coding: badencoding -*-
pass
rk   r   u%   # -*- coding: badencoding -*-
"Ã‚Â¤"
u   Ã‚Â¤u   "Ã‚Â¤"
s   "Â¤"
õ   Â¤s   # -*- coding: latin1 -*-
"Â¤"
s   # -*- coding: utf-8 -*-
"Â¤"
s"   # -*- coding: iso8859-15 -*-
"Â¤"
u   Ã‚â‚¬u*   """\
# -*- coding: iso8859-15 -*-
Ã‚Â¤"""
u!   # -*- coding: iso8859-15 -*-
Ã‚Â¤s(   """\
# -*- coding: iso8859-15 -*-
Â¤"""
u   # -*- coding: iso8859-15 -*-
Â¤)r   r   r   r   r   )r   rC   r
   r
   r   Útest_encoding8  s&    zTestSpecifics.test_encodingc             C   s^  G dd„ dt ƒ}|ƒ }d|d< |  |d d¡ |d  d7  < |  |d d¡ |d= |  d|¡ d|d< |  |d d¡ |d  d7  < |  |d d¡ |d= |  d|¡ d|dd…< |  |dd… d¡ |dd…  d7  < |  |dd… d¡ |dd…= |  tddƒ|¡ d|dd…dd…f< |  |dd…dd…f d¡ |dd…dd…f  d7  < |  |dd…dd…f d¡ |dd…dd…f= |  tddƒtddƒf|¡ d|ddd…< |  |ddd… d¡ |ddd…  d7  < |  |ddd… d¡ |ddd…= |  tdddƒ|¡ d|ddd…ddd…f< |  |ddd…ddd…f d¡ |ddd…ddd…f  d7  < |  |ddd…ddd…f d¡ |ddd…ddd…f= |  tdddƒtdddƒf|¡ d|d< |  |d d¡ |d  d7  < |  |d d¡ |d= |  t|¡ d|d< |  |d d¡ |d  d7  < |  |d d¡ |d= |  ttf|¡ d S )	Nc               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )z.TestSpecifics.test_subscripts.<locals>.str_mapc             S   s
   i | _ d S )N)Údata)r   r
   r
   r   Ú__init__Q  s    z7TestSpecifics.test_subscripts.<locals>.str_map.__init__c             S   s   | j t|ƒ S )N)r{   Ústr)r   r'   r
   r
   r   r(   S  s    z:TestSpecifics.test_subscripts.<locals>.str_map.__getitem__c             S   s   || j t|ƒ< d S )N)r{   r}   )r   r'   r*   r
   r
   r   r+   U  s    z:TestSpecifics.test_subscripts.<locals>.str_map.__setitem__c             S   s   | j t|ƒ= d S )N)r{   r}   )r   r'   r
   r
   r   Ú__delitem__W  s    z:TestSpecifics.test_subscripts.<locals>.str_map.__delitem__c             S   s   t |ƒ| jkS )N)r}   r{   )r   r'   r
   r
   r   Ú__contains__Y  s    z;TestSpecifics.test_subscripts.<locals>.str_map.__contains__N)r/   r0   r1   r|   r(   r+   r~   r   r
   r
   r
   r   Ústr_mapP  s
   r€   rX   rY   )rX   rX   é   .)..)Úobjectr   ZassertNotInÚsliceÚEllipsis)r   r€   r>   r
   r
   r   Útest_subscriptsM  sd    
    zTestSpecifics.test_subscriptsc             C   s0   d}|d  dd„ tdƒD ƒ¡; }t|ddƒ d S )Nzdef f(%s): passz, c             s   s   | ]}d ||f V  qdS )za%d:%dNr
   )Ú.0rh   r
   r
   r   ú	<genexpr>˜  s    z6TestSpecifics.test_annotation_limit.<locals>.<genexpr>i,  r   r   )rL   Úranger   )r   rG   r
   r
   r   Útest_annotation_limit•  s    z#TestSpecifics.test_annotation_limitc             C   sZ   G dd„ dƒ}|   d|jjj¡ |   d|jjj¡ |   d|jjj¡ |   d|jjj¡ d S )Nc               @   s   e Zd Zdd„ ZdS )z&TestSpecifics.test_mangling.<locals>.Ac              S   s   d} d}dd l }dd l}d S )NrX   rY   r   )Ú_A__mangled_modZ__package__.module)Ú_A__mangledÚ__not_mangled__rŠ   Ú__package__r
   r
   r   rA     s    z(TestSpecifics.test_mangling.<locals>.A.fN)r/   r0   r1   rA   r
   r
   r
   r   r5   œ  s   r5   r‹   rŒ   rŠ   r   )ÚassertInrA   r`   Úco_varnames)r   r5   r
   r
   r   Útest_mangling›  s
    zTestSpecifics.test_manglingc       	   	   C   s8  t }| ¡  d¡r|d d… }t|dƒ}| ¡ }W d Q R X ddgddgdd	gd
dg||gg}xv|D ]n\}}t|d| dƒ}t|d| dtjƒ}|  t	|ƒtj
k¡ t|d| dƒ}|  ||¡ |  |jd| ¡ qdW tdddtjƒ}|  tt|dd¡ |  ttt ¡ dd¡ t 
¡ }t ¡ g|_|  tt|dd¡ d S )NZpycrg   Úrz<assign>zx = 5z	<ifblock>zif True:
    pass
z
<forblock>z!for n in [1, 2, 3]:
    print(n)
z	<deffunc>zdef foo():
    pass
foo()
z%s1r   z%s2z%s3zprint(1)z<string>z<ast>r   )Ú__file__ÚlowerÚendswithÚopenÚreadr   Ú_astZPyCF_ONLY_ASTÚ
assertTrueÚtypeZModuler   Úco_filenamer   r;   ZIfZBoolOpZbody)	r   ZfnamerA   Z	fcontentsZsample_coderC   Zco1ZastZco2r
   r
   r   Útest_compile_ast¨  s.    
zTestSpecifics.test_compile_astc                s:   d‰ ‡ fdd„}|ƒ |ƒ |ƒ |ƒ i}|   |dddœ¡ d S )Nr   c                  s   ˆ d7 ‰ ˆ S )NrX   r
   r
   )rh   r
   r   rA   Î  s    z3TestSpecifics.test_dict_evaluation_order.<locals>.frY   é   )rX   r   )r   )r   rA   r>   r
   )rh   r   Útest_dict_evaluation_orderË  s    z(TestSpecifics.test_dict_evaluation_orderc          
   C   sŒ   x&dD ]}t d|dƒ}|  |jd¡ qW xHtdƒtdƒfD ]4}|  t¡ t d|dƒ}W d Q R X |  |jd¡ q:W |  tt dt	dƒd¡ d S )N)zfile.pys   file.pyÚpassr   zfile.pys   file.py)
r   r   rš   Ú	bytearrayÚ
memoryviewZassertWarnsÚDeprecationWarningr   r;   r-   )r   r    rC   r
   r
   r   Útest_compile_filenameÖ  s    
z#TestSpecifics.test_compile_filenamec             C   s@   d}t |ddƒ}x*|jD ] }t|tjƒr|  |j|j¡ qW d S )Nzdef f(): pass
def g(): passZmyfiler   )r   ra   Ú
isinstanceÚtypesÚCodeTypeÚassertIsrš   )r   rG   rc   Úobjr
   r
   r   Útest_same_filename_usedà  s
    z%TestSpecifics.test_same_filename_usedc             C   s   |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d	¡ |   d
¡ |   d¡ |   d¡ |   d¡ |   d¡ d S )Nz1 + 2z
1 + 2z1 + 2
z1 + 2

z1 + 2		
z1 + 2		
        z1 + 2 # one plus twoz1; 2zimport sys; syszdef f():
   passzwhile False:
   passzif x:
   f(x)zif x:
   f(x)
else:
   g(x)zclass T:
   pass)r   )r   r
   r
   r   Útest_single_statementè  s    












z#TestSpecifics.test_single_statementc             C   sT   |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ d S )	Nz1
2zdef f(): passza = 13
b = 187zdel x
del yzf()
g()zf()
# blah
blah()zf()
xy # blah
blah()zx = 5 # comment
x = 6
)r   )r   r
   r
   r   Útest_bad_single_statementø  s    






z'TestSpecifics.test_bad_single_statementc          
   C   sf   d}t  ¡ B}tj |d¡}t|dƒ}| |¡ W d Q R X t |¡d }W d Q R X |  	d|j
¡ d S )Ns   0000 
00000000000
 
ž
zbad.pyÚwbr   s	   Non-UTF-8)ÚtempfileÚTemporaryDirectoryÚosÚpathrL   r•   Úwriter   Úrun_python_until_endrŽ   Úerr)r   ÚsrcÚtmpdrK   ÚfpÚresr
   r
   r   Ú"test_particularly_evil_undecodable  s    
z0TestSpecifics.test_particularly_evil_undecodablec          
   C   sf   d}t  ¡ B}tj |d¡}t|dƒ}| |¡ W d Q R X t |¡d }W d Q R X |  	d|j
¡ d S )Ns   # 
#ý
zbad.pyr«   r   s	   Non-UTF-8)r¬   r­   r®   r¯   rL   r•   r°   r   r±   rŽ   r²   )r   r³   r´   rK   rµ   r¶   r
   r
   r   Ú$test_yet_more_evil_still_undecodable  s    
z2TestSpecifics.test_yet_more_evil_still_undecodablec                sT   t  ¡ d ‰ tˆ d ƒ‰‡ ‡‡fdd„}|ddƒ |ddƒ |ddƒ |dd	ƒ d S )
Nr   g      è?c          	      sX   | |ˆ  }ˆ  |¡ | |ˆ   }d | |ˆ ¡}ˆjt|d ˆ  |¡ W d Q R X d S )NzCompiling ({!r} + {!r} * {}))Úmsg)r   Úformatr   ÚRecursionError)ÚprefixZrepeatedZ	expect_okZbrokenZdetails)Ú
fail_depthr   Úsuccess_depthr
   r   Úcheck_limit"  s    

z@TestSpecifics.test_compiler_recursion_limit.<locals>.check_limitr$   z()z.bz[0]z*a)rZ   Úgetrecursionlimitr]   )r   r¿   r
   )r½   r   r¾   r   Útest_compiler_recursion_limit  s    		


z+TestSpecifics.test_compiler_recursion_limitc          	   C   s  |   td¡ tdddƒ W d Q R X |   td¡ ttdƒddƒ W d Q R X ttdƒdd… ddƒ}|  t|ƒd¡ ttd	ƒdd… ddƒ}|  t|ƒd¡ ttd
ƒdd… ddƒ}|  t|ƒd¡ |  ttd	ƒdd… ƒd¡ tƒ }ttdƒdd… |ƒ |  |d d¡ d S )Nzcannot contain nullz123 z<dummy>r   s   123 rX   rg   é   s   1234s   $23$s   ax = 123ro   r%   )ZassertRaisesRegexÚ
ValueErrorr   r    r   r   r6   r   )r   rC   Ú	namespacer
   r
   r   Útest_null_terminated0  s    z"TestSpecifics.test_null_terminatedc             C   s>   x8|j jD ]}t|ƒt|ƒkr
P q
W |  d||j jf ¡ d S )Nz unable to find constant %r in %r)r`   ra   Úreprr:   )r   ÚfuncZexpectedÚconstr
   r
   r   Úcheck_constantD  s
    zTestSpecifics.check_constantc                s¾   ‡ fdd„}|d ƒ |dƒ |dƒ |dƒ |dƒ dd„ dd„  }}ˆ   |j|j¡ ˆ  |t¡ ˆ  t|ƒ ƒttƒ¡ d	d„ d	d„  }}ˆ   |j|j¡ ˆ  |tdhƒ¡ ˆ  |dƒ¡ d S )
Nc                s`   i }d| | f }t ||ƒ |d }|d }ˆ  |j|j¡ ˆ  || ¡ ˆ  t|ƒ ƒt| ƒ¡ d S )Nzf1, f2 = lambda: %r, lambda: %rrr   rs   )r   r¦   r`   rÉ   r   rÆ   )rÈ   ÚnsrC   rr   rs   )r   r
   r   Úcheck_same_constantS  s    
z?TestSpecifics.test_merge_constants.<locals>.check_same_constantr   g        s   abcÚabcc               S   s   dS )N.r
   r
   r
   r
   r   rp   e  rq   z4TestSpecifics.test_merge_constants.<locals>.<lambda>c             S   s   | dkS )N>   r   r
   )ro   r
   r
   r   rp   l  rq   )r¦   r`   rÉ   r„   r   rÆ   Ú	frozensetr˜   )r   rË   rr   rs   r
   )r   r   Útest_merge_constantsN  s    
z"TestSpecifics.test_merge_constantsc             C   s(   dd„ }|   dtt |¡ƒd j¡ dS )z9Regression test for issue35193 when run under clang msan.c               S   s   dS )Nr   Zunreachable)ÚRuntimeErrorr
   r
   r
   r   Úunused_code_at_endx  s    zcTestSpecifics.test_peephole_opt_unreachable_code_array_access_in_bounds.<locals>.unused_code_at_endZRETURN_VALUErg   N)r   r-   ÚdisZget_instructionsÚopname)r   rÐ   r
   r
   r   Ú9test_peephole_opt_unreachable_code_array_access_in_boundsu  s    zGTestSpecifics.test_peephole_opt_unreachable_code_array_access_in_boundsc                s
  ‡ fdd„}|ddƒ |ddƒ |ddƒ |dd	ƒ |d
dƒ dd„ dd„  }}ˆ   |j|j¡ ˆ  |d¡ ˆ  |d¡ ˆ  t|ƒ ƒtdƒ¡ ˆ  t|ƒ ƒtdƒ¡ dd„ dd„  }}ˆ   |j|j¡ ˆ  |tdhƒ¡ ˆ  |tdhƒ¡ ˆ  |dƒ¡ ˆ  |dƒ¡ d S )Nc                sŽ   i }t d| |f |ƒ |d }|d }ˆ  |j|j¡ ˆ  |j|j¡ ˆ  || ¡ ˆ  ||¡ ˆ  t|ƒ ƒt| ƒ¡ ˆ  t|ƒ ƒt|ƒ¡ d S )Nzf1, f2 = lambda: %r, lambda: %rrr   rs   )r   ÚassertIsNotr`   rt   rÉ   r   rÆ   )Zconst1Zconst2rÊ   rr   rs   )r   r
   r   Úcheck_different_constants‡  s    zJTestSpecifics.test_dont_merge_constants.<locals>.check_different_constantsr   g        g       €)r   )g        r$   ó   a)r$   )rÖ   c               S   s   dS )Ny                r
   r
   r
   r
   r   rp   ›  rq   z9TestSpecifics.test_dont_merge_constants.<locals>.<lambda>c               S   s   dS )Ny       €       €r
   r
   r
   r
   r   rp   ›  rq   y                y       €       €c             S   s   | dkS )N>   r   r
   )ro   r
   r
   r   rp   ¤  rq   c             S   s   | dkS )N>   ç        r
   )ro   r
   r
   r   rp   ¤  rq   )rÔ   r`   rÉ   r   rÆ   rÍ   r˜   )r   rÕ   rr   rs   r
   )r   r   Útest_dont_merge_constantsƒ  s$    




z'TestSpecifics.test_dont_merge_constantsc             C   s   t dtdƒdƒ d S )NZ42Ztest_compile_pathliker   )r   r   )r   r
   r
   r   Útest_path_like_objects«  s    z$TestSpecifics.test_path_like_objectsc             C   s   t dd ddƒ d S )Nzif a: b
i@ z<dummy>r   )r   )r   r
   r
   r   Útest_stack_overflow¯  s    z!TestSpecifics.test_stack_overflowN)3r/   r0   r1   r   r   r   r   r   r   r   r!   r"   r#   r?   rD   rE   rF   rH   rQ   rV   r^   rZ   r[   r_   rj   rm   rn   rv   rx   rz   r…   r‰   r   r›   r   r¢   r   Zcpython_onlyr¨   r©   rª   r·   r¸   rÁ   rÅ   rÉ   rÎ   rÓ   rØ   rÙ   rÚ   r
   r
   r
   r   r      sZ   		/!
/	H#




'(r   c               @   sP   e Zd 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 )ÚTestExpressionStackSizeéd   c             C   s>   t |tƒrt|ddƒ}t t t|jƒ¡¡}|  |j	|¡ d S )Nz<foo>r   )
r£   r}   r   ÚmathZceilÚlogÚlenÚco_codeZassertLessEqualÚco_stacksize)r   rC   Zmax_sizer
   r
   r   Úcheck_stack_size»  s    
z(TestExpressionStackSize.check_stack_sizec             C   s   |   d| j d ¡ d S )Nzx and ro   )râ   ÚN)r   r
   r
   r   Útest_andÃ  s    z TestExpressionStackSize.test_andc             C   s   |   d| j d ¡ d S )Nzx or ro   )râ   rã   )r   r
   r
   r   Útest_orÆ  s    zTestExpressionStackSize.test_orc             C   s   |   d| j d ¡ d S )Nzx and x or ro   )râ   rã   )r   r
   r
   r   Útest_and_orÉ  s    z#TestExpressionStackSize.test_and_orc             C   s   |   d| j d ¡ d S )Nzx < ro   )râ   rã   )r   r
   r
   r   Útest_chained_comparisonÌ  s    z/TestExpressionStackSize.test_chained_comparisonc             C   s   |   d| j d ¡ d S )Nzx if x else ro   )râ   rã   )r   r
   r
   r   Útest_if_elseÏ  s    z$TestExpressionStackSize.test_if_elsec             C   s   |   d| j d ¡ d S )Nzx + ro   )râ   rã   )r   r
   r
   r   Ú
test_binopÒ  s    z"TestExpressionStackSize.test_binopc             C   s    d}|d| j  7 }|  |¡ d S )Nz
def f(x):
z   x and x
)rã   râ   )r   rC   r
   r
   r   Útest_func_andÕ  s    z%TestExpressionStackSize.test_func_andN)r/   r0   r1   rã   râ   rä   rå   ræ   rç   rè   ré   rê   r
   r
   r
   r   rÛ   µ  s   rÛ   c               @   sÖ   e Zd Zd5d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 d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4S )6ÚTestStackSizeStabilityFc                s|   ‡ ‡fdd„‰‡fdd„t ddƒD ƒ}tt|ƒƒdkrxdd l}dd l}| ¡ }|jˆdƒ|d	 |  d
|ˆ| ¡ f ¡ d S )Nc                s>   i }d| ˆ  }ˆ rd| }t |ddƒ}t|||ƒ |d jS )Nzdef func():
zasync z<script>r   rÇ   )r   r   r`   )rh   rÊ   ZscriptrC   )Úasync_Úsnippetr
   r   Úcompile_snippetà  s    z@TestStackSizeStability.check_stack_size.<locals>.compile_snippetc                s   g | ]}ˆ |ƒj ‘qS r
   )rá   )r†   rh   )rî   r
   r   ú
<listcomp>é  s    z;TestStackSizeStability.check_stack_size.<locals>.<listcomp>rY   rB   rX   r   )Úfilez<stack sizes diverge with # of consecutive snippets: %s
%s
%s)rˆ   rß   ÚsetrÑ   ÚioÚStringIOr:   Úgetvalue)r   rí   rì   ZsizesrÑ   rò   Úoutr
   )rì   rî   rí   r   râ   ß  s    	z'TestStackSizeStability.check_stack_sizec             C   s   d}|   |¡ d S )Nz1
            if x:
                a
            )râ   )r   rí   r
   r
   r   Útest_ifñ  s    zTestStackSizeStability.test_ifc             C   s   d}|   |¡ d S )Nz{
            if x:
                a
            elif y:
                b
            else:
                c
            )râ   )r   rí   r
   r
   r   rè   ø  s    z#TestStackSizeStability.test_if_elsec             C   s   d}|   |¡ d S )NzV
            try:
                a
            except:
                b
            )râ   )r   rí   r
   r
   r   Útest_try_except_bare  s    z+TestStackSizeStability.test_try_except_barec             C   s   d}|   |¡ d S )Nz¬
            try:
                a
            except ImportError:
                b
            except:
                c
            else:
                d
            )râ   )r   rí   r
   r
   r   Útest_try_except_qualified  s    
z0TestStackSizeStability.test_try_except_qualifiedc             C   s   d}|   |¡ d S )Nz±
            try:
                a
            except ImportError as e:
                b
            except:
                c
            else:
                d
            )râ   )r   rí   r
   r
   r   Útest_try_except_as  s    
z)TestStackSizeStability.test_try_except_asc             C   s   d}|   |¡ d S )Nzg
                try:
                    a
                finally:
                    b
            )râ   )r   rí   r
   r
   r   Útest_try_finally&  s    z'TestStackSizeStability.test_try_finallyc             C   s   d}|   |¡ d S )Nz8
            with x as y:
                a
            )râ   )r   rí   r
   r
   r   Ú	test_with/  s    z TestStackSizeStability.test_withc             C   s   d}|   |¡ d S )NzX
            while x:
                a
            else:
                b
            )râ   )r   rí   r
   r
   r   Útest_while_else6  s    z&TestStackSizeStability.test_while_elsec             C   s   d}|   |¡ d S )Nz7
            for x in y:
                a
            )râ   )r   rí   r
   r
   r   Útest_for?  s    zTestStackSizeStability.test_forc             C   s   d}|   |¡ d S )Nz[
            for x in y:
                a
            else:
                b
            )râ   )r   rí   r
   r
   r   Útest_for_elseF  s    z$TestStackSizeStability.test_for_elsec             C   s   d}|   |¡ d S )NzÚ
            for x in y:
                if z:
                    break
                elif u:
                    continue
                else:
                    a
            else:
                b
            )râ   )r   rí   r
   r
   r   Útest_for_break_continueO  s    z.TestStackSizeStability.test_for_break_continuec             C   s   d}|   |¡ d S )Na6  
            for x in y:
                try:
                    if z:
                        break
                    elif u:
                        continue
                    else:
                        a
                finally:
                    f
            else:
                b
            )râ   )r   rí   r
   r
   r   Ú0test_for_break_continue_inside_try_finally_block]  s    zGTestStackSizeStability.test_for_break_continue_inside_try_finally_blockc             C   s   d}|   |¡ d S )Nzù
            for x in y:
                try:
                    t
                finally:
                    if z:
                        break
                    else:
                        a
            else:
                b
            )râ   )r   rí   r
   r
   r   Ú#test_for_break_inside_finally_blockn  s    z:TestStackSizeStability.test_for_break_inside_finally_blockc             C   s   d}|   |¡ d S )Na5  
            for x in y:
                try:
                    t
                except:
                    if z:
                        break
                    elif u:
                        continue
                    else:
                        a
            else:
                b
            )râ   )r   rí   r
   r
   r   Ú+test_for_break_continue_inside_except_block}  s    zBTestStackSizeStability.test_for_break_continue_inside_except_blockc             C   s   d}|   |¡ d S )Na
  
            for x in y:
                with c:
                    if z:
                        break
                    elif u:
                        continue
                    else:
                        a
            else:
                b
            )râ   )r   rí   r
   r
   r   Ú)test_for_break_continue_inside_with_blockŽ  s    z@TestStackSizeStability.test_for_break_continue_inside_with_blockc             C   s   d}|   |¡ d S )Nz¢
            try:
                if z:
                    return
                else:
                    a
            finally:
                f
            )râ   )r   rí   r
   r
   r   Ú$test_return_inside_try_finally_block  s    	z;TestStackSizeStability.test_return_inside_try_finally_blockc             C   s   d}|   |¡ d S )Nz¢
            try:
                t
            finally:
                if z:
                    return
                else:
                    a
            )râ   )r   rí   r
   r
   r   Ú test_return_inside_finally_block©  s    	z7TestStackSizeStability.test_return_inside_finally_blockc             C   s   d}|   |¡ d S )Nz¡
            try:
                t
            except:
                if z:
                    return
                else:
                    a
            )râ   )r   rí   r
   r
   r   Útest_return_inside_except_blockµ  s    	z6TestStackSizeStability.test_return_inside_except_blockc             C   s   d}|   |¡ d S )Nz~
            with c:
                if z:
                    return
                else:
                    a
            )râ   )r   rí   r
   r
   r   Útest_return_inside_with_blockÁ  s    z4TestStackSizeStability.test_return_inside_with_blockc             C   s   d}| j |dd d S )Nz>
            async with x as y:
                a
            T)rì   )râ   )r   rí   r
   r
   r   Útest_async_withË  s    z&TestStackSizeStability.test_async_withc             C   s   d}| j |dd d S )Nz=
            async for x in y:
                a
            T)rì   )râ   )r   rí   r
   r
   r   Útest_async_forÒ  s    z%TestStackSizeStability.test_async_forc             C   s   d}| j |dd d S )Nza
            async for x in y:
                a
            else:
                b
            T)rì   )râ   )r   rí   r
   r
   r   Útest_async_for_elseÙ  s    z*TestStackSizeStability.test_async_for_elsec             C   s   d}| j |dd d S )Na  
            for x in y:
                async with c:
                    if z:
                        break
                    elif u:
                        continue
                    else:
                        a
            else:
                b
            T)rì   )râ   )r   rí   r
   r
   r   Ú/test_for_break_continue_inside_async_with_blockâ  s    zFTestStackSizeStability.test_for_break_continue_inside_async_with_blockc             C   s   d}| j |dd d S )Nz„
            async with c:
                if z:
                    return
                else:
                    a
            T)rì   )râ   )r   rí   r
   r
   r   Ú#test_return_inside_async_with_blockñ  s    z:TestStackSizeStability.test_return_inside_async_with_blockN)F)r/   r0   r1   râ   rö   rè   r÷   rø   rù   rú   rû   rü   rý   rþ   rÿ   r   r  r  r  r  r  r  r  r  r	  r
  r  r  r
   r
   r
   r   rë   Û  s2   
				
	rë   Ú__main__)rÑ   rÝ   r®   ZunittestrZ   r—   r¬   r¤   Ztestr   Ztest.supportr   r   ZTestCaser   rÛ   rë   r/   Úmainr
   r
   r
   r   Ú<module>   s*        .&  #