B
    u9a                 @   sv   d dl Z d dlZd dlZd dlZd dl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rre  dS )
    N)supportc               @   sT   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	e
jdd ZdS )	ClearTest   c             K   s   dd  d S )N   r    )selfxkwargsr   r    /usr/lib/python3.7/test_frame.pyinner   s    zClearTest.innerc          
   K   s<   y| j f | W n& tk
r6 } z|}W d d }~X Y nX |S )N)r   ZeroDivisionError)r   r	   eexcr   r   r
   outer   s
    zClearTest.outerc             C   s"   x|d k	r|j   |j}qW d S )N)tb_framecleartb_next)r   tbr   r   r
   clear_traceback_frames   s    

z ClearTest.clear_traceback_framesc             C   sh   G dd d}| }t |}| j|d}~t  | d |  | |j t  | d |  d S )Nc               @   s   e Zd ZdS )z&ClearTest.test_clear_locals.<locals>.CN)__name__
__module____qualname__r   r   r   r
   C!   s   r   )c)	weakrefrefr   r   Z
gc_collectassertIsNotr   __traceback__assertIs)r   r   r   wrr   r   r   r
   test_clear_locals    s    
zClearTest.test_clear_localsc                s@   d  fdd}| }t | |   |j  |   d S )NFc               3   s   zd V  t   W d d X d S )NT)r   r   )endlyr   r
   g1   s    
z)ClearTest.test_clear_generator.<locals>.g)nextassertFalsegi_framer   
assertTrue)r   r"   genr   )r!   r
   test_clear_generator/   s    

zClearTest.test_clear_generatorc          
   C   sz   ydd  W n* t k
r6 } z|jj}W d d }~X Y nX | t |  W d Q R X | t |j  W d Q R X d S )Nr   r   )r   r   r   assertRaisesRuntimeErrorr   f_back)r   r   fr   r   r
   test_clear_executing?   s    zClearTest.test_clear_executingc                s@   d  fdd}| }t |}  |    d S )NFc              3   s   zydd  W nn t k
r| }  zP| jj}t |  W d Q R X t |j  W d Q R X |V  W d d } ~ X Y nX W d d X d S )Nr   r   T)r   r   r   r)   r*   r   r+   )r   r,   )r!   r   r   r
   r"   M   s    z3ClearTest.test_clear_executing_generator.<locals>.g)r#   r$   r   r&   )r   r"   r'   r,   r   )r!   r   r
   test_clear_executing_generatorJ   s    
z(ClearTest.test_clear_executing_generatorc          	   C   sl   t  Z G dd d}| }t|}| j|d}~| d |  | |j | d |  W d Q R X d S )Nc               @   s   e Zd ZdS )z)ClearTest.test_clear_refcycles.<locals>.CN)r   r   r   r   r   r   r
   r   e   s   r   )r   )	r   Z
disable_gcr   r   r   r   r   r   r   )r   r   r   r   r   r   r   r
   test_clear_refcyclesa   s    

zClearTest.test_clear_refcyclesN)r   )r   r   r   r   r   r   r    r(   r-   r.   r   Zcpython_onlyr/   r   r   r   r
   r   	   s   
r   c               @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )FrameAttrsTestc          
   C   s`   dd }y
|  W nH t k
rZ } z*|j}g }x|rH||j |j}q0W W d d }~X Y nX |S )Nc                 s   d d}  fdd}| S )Nr      c                 s    d } dd  d}d S )N   r   r   	   r   )zt)r   r   r
   r   v   s    z8FrameAttrsTest.make_frames.<locals>.outer.<locals>.innerr   )yr   r   )r   r
   r   s   s    z)FrameAttrsTest.make_frames.<locals>.outer)r   r   appendr   r   )r   r   r   r   framesr   r   r
   make_framesr   s    
zFrameAttrsTest.make_framesc             C   sV   |   \}}}|j}| |dtj | |ddd |j}| |ddd d S )Nr   r   r1   )r   r6      )r   r4   )r9   f_localsZassertIsInstancepoptypesFunctionTypeassertEqual)r   r,   r   r   Zouter_localsZinner_localsr   r   r
   test_locals   s    zFrameAttrsTest.test_localsc             C   s>   |   \}}}|  |  | |ji  | |ji  d S )N)r9   r   r?   r;   )r   r,   r   r   r   r   r
   r       s
    z FrameAttrsTest.test_clear_localsc             C   sJ   |   \}}}|j |j |  |  | |ji  | |ji  d S )N)r9   r;   r   r?   )r   r,   r   r   r   r   r
   test_locals_clear_locals   s    z'FrameAttrsTest.test_locals_clear_localsc          	   C   s,   |   \}}}| t
 |`W d Q R X d S )N)r9   r)   AttributeErrorf_lineno)r   r,   _r   r   r
   test_f_lineno_del_segfault   s    z)FrameAttrsTest.test_f_lineno_del_segfaultN)r   r   r   r9   r@   r    rA   rE   r   r   r   r
   r0   p   s
   
r0   c               @   s   e Zd Zdd ZdS )ReprTestc       
   
   C   s   dd }|j j}y
|  W nH tk
rb } z*|j}g }x|rP||j |j}q8W W d d }~X Y nX | d |\}}}t	t
t}	| t
|d|	|d f  | t
|d|	|d f  | t
|d|	|d	 f  d S )
Nc                 s   d d}  fdd}| S )Nr   r1   c                 s    d } dd  d}d S )Nr2   r   r   r3   r   )r4   r5   )r   r   r
   r      s    z0ReprTest.test_repr.<locals>.outer.<locals>.innerr   )r6   r   r   )r   r
   r      s    z!ReprTest.test_repr.<locals>.outerzshould have raisedz=^<frame at 0x[0-9a-fA-F]+, file %s, line %d, code test_repr>$   z9^<frame at 0x[0-9a-fA-F]+, file %s, line %d, code outer>$r:   z9^<frame at 0x[0-9a-fA-F]+, file %s, line %d, code inner>$r   )__code__co_firstlinenor   r   r7   r   r   Zfailreescaperepr__file__ZassertRegex)
r   r   offsetr   r   r8   Zf_thisZf_outerZf_innerZ	file_reprr   r   r
   	test_repr   s,    	





zReprTest.test_reprN)r   r   r   rO   r   r   r   r
   rF      s   rF   __main__)rJ   r=   Zunittestr   Ztestr   ZTestCaser   r0   rF   r   mainr   r   r   r
   <module>   s   g5(