o
    HXh                     @   sl  d dl mZ d dlZd dlmZ d dlZd dlZd dlZd dlm	Z	 d dl
Z
G dd dZG dd dZd	d
 Zdd Zg de_dd Zg de_dd Zg de_dd Zg de_dd Zg de_dd Zg de_dd Zg de_dd  Zd!d" Zg d#e_d$d% Zd&d' Zg d(e_d)d* Zd+d, Zd-ge_d.d/ Zd0d1 Zg d2e_d3d4 Zg d5e_d6d7 Zg d8e_d9d: Z g d;e _d<d= Z!d>d? Z"g d@dAdBgdC  dAdDg e"_G dEdF dFZ#G dGdH dHej$Z%G dIdJ dJe%Z&ej'G dKdL dLe%Z(G dMdN dNej$Z)G dOdP dPZ*dQdR Z+dSdT Z,G dUdV dVej$Z-G dWdX dXej$Z.e/dYkr4e0  dS dS )Z    )supportN)	MagicMockwrapsc                   @   &   e Zd Z	 dd Zdd Zdd ZdS )tracecontextc                 C      || _ || _d S Noutputvalueselfr   r    r   @/opt/python-3.10.19/usr/lib/python3.10/test/test_sys_settrace.py__init__      
ztracecontext.__init__c                 C   s   | j | j d S r	   r   appendr   r   r   r   r   	__enter__      ztracecontext.__enter__c                 G   s   | j | j  d S r	   r   r   exc_infor   r   r   __exit__   s   ztracecontext.__exit__N)__name__
__module____qualname__r   r   r   r   r   r   r   r      
    r   c                   @   r   )asynctracecontextc                 C   r   r	   r
   r   r   r   r   r      r   zasynctracecontext.__init__c                    s   | j | j d S r	   r   r   r   r   r   
__aenter__   s   zasynctracecontext.__aenter__c                    s   | j | j  d S r	   r   r   r   r   r   	__aexit__"   s   zasynctracecontext.__aexit__N)r   r   r   r   r    r!   r   r   r   r   r      r   r   c                 C  s   	 | D ]}|V  qd S r	   r   )iterablexr   r   r   	asynciter%   s
   r$   c                   C   s   dS N   r   r   r   r   r   basic,      r'   )r   callr&   liner&   returnc                  C      d} ~ 	 d} d S r%   r   r#   r   r   r   arigo_example0;      r1   )r)   r+      r,      r,      r,   r8   r.   c                  C   r/   r%   r   r0   r   r   r   arigo_example1I   r2   r:   c                  C   r/   r%   r   r0   r   r   r   arigo_example2W   s
   r;   )r)   r+   r3   r5      r,      r,   r?   r.   c                  C   s   d} ~ d} d S r%   r   r0   r   r   r   one_instr_linej   s   rA   r)   r+   r3   r5   r6   r.   c                  C   s$   d} t dD ]	}|rd} qd} qd S Nr&   r4   range)r#   ar   r   r   no_pop_topsu   s   rH   )
r)   r+   r3   r5      r,   r3   r5   r<   r3   r4   r.   c                  C   s   d} | st  | rd}d S r%   )Zbla)yr#   r   r   r   no_pop_blocks   s
   rM   r)   r+   r3   r<   r=   r.   c                  C   s   d} d S r%   r   r0   r   r   r   called   s   rP   c                   C   
   t   d S r	   )rP   r   r   r   r   r*      s   
r*   )r)   r+   r*   r,   rU   r.   r-   c                   C   s   t r	   	Exceptionr   r   r   r   raises   r(   rY   c                   C   s"   zt   W d S  ty   Y d S w r	   )rY   rX   r   r   r   r   
test_raise   s
   rZ   )r)   r+   r3   rR   rT   rU   	exceptionrV   r4   r\   r5   r<   rO   c                 C   s   t |  | t  j_d S r	   )syssettrace	_getframef_backf_traceZ	tracefuncr   r   r   _settrace_and_return   s   
rd   c                 C   s   t |  d S r	   )rd   rc   r   r   r   settrace_and_return   s   re   r-   c                 C   s   t |  | t  j_tr	   )r^   r_   r`   ra   rb   RuntimeErrorrc   r   r   r   _settrace_and_raise   s   
rg   c                 C   s$   zt |  W d S  ty   Y d S w r	   )rg   rf   rc   r   r   r   settrace_and_raise   s
   rh   )r]   r5   r<   rO   c                  C   s"   d} d}| |kr| d }d S 	 d S )Nr8   r&   r   )rG   br   r   r   ireturn_example   s
   rj   r)   r+   r3   r5   r<   rO   c                  C   s8   t dd} zd}	 | | }|d7 }q	 ty   Y d S w )Nr   r6   r&   rF   
IndexError)itemsiri   r   r   r   tightloop_example   s   
rp   )r)   r+   r3   r5   r<   r7   r<   r7   r<   r7   r<   r7   )r8   r\   rI   r>   r@   c                  C   s.   t dd} zd}| | }q ty   Y d S w )Nr&   r=   r   rl   )rn   ro   r   r   r   tighterloop_example   s   

rq   )r)   r+   r3   r5   r<   r<   r<   r<   )r=   r\   r7   rI   rJ   r.   c                   c   s    zdV  W d S w )NTr   r   r   r   r   generator_function  s
   rs   c                  C   s    t t } tdD ]} | }q	d S )N
   )anyrs   rF   )r#   rL   r   r   r   generator_example  s   
rv   )
r)   r3   r*   r,   r,   r|   r.   )r|   r*   r|   r\   r,   r   r.   r7   rI   rt   r9   c                   @   s.   e Zd Zd
ddZdd Zdd Zdd	 ZdS )TracerNc                 C   s   || _ || _g | _d S r	   )trace_line_eventstrace_opcode_eventsevents)r   r   r   r   r   r   r   1  s   
zTracer.__init__c                 C   s,   | j d ur	| j |_| jd ur| j|_d S d S r	   )r   f_trace_linesr   f_trace_opcodes)r   framer   r   r   _reconfigure_frame6  s
   

zTracer._reconfigure_framec                 C   s"   |  | | j|j|f | jS r	   r   r   r   f_linenotracer   r   eventargr   r   r   r   <  s   
zTracer.tracec                 C   s0   |  | dd dD  | j|j|f | jS )Nc                 s   s    | ]}|V  qd S r	   r   ).0or   r   r   	<genexpr>C  s    z)Tracer.traceWithGenexp.<locals>.<genexpr>r&   r   r   r   r   r   traceWithGenexpA  s   
zTracer.traceWithGenexp)NN)r   r   r   r   r   r   r   r   r   r   r   r   0  s
    
r   c                   @   s  e Zd Zdd Zdd Ze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/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Z d;d< Z!d=d> Z"d?d@ Z#dAdB Z$dCdD Z%dEdF Z&dGdH Z'dIdJ Z(dKdL Z)dMdN Z*dOdP Z+dQdR Z,dSdT Z-dUdV Z.dWdX Z/dYdZ Z0d[d\ Z1d]d^ Z2d_d` Z3dadb Z4dcdd Z5dedf Z6dgdh Z7didj Z8dkdl Z9dmdn Z:doS )pTraceTestCasec                 C   s(   t  | _t   | tjt  d S r	   )gc	isenabledusing_gcdisable
addCleanupr^   r_   gettracer   r   r   r   setUpL  s   
zTraceTestCase.setUpc                 C   s   | j r	t  d S d S r	   )r   r   enabler   r   r   r   tearDownQ  s   zTraceTestCase.tearDownc                   C   s   	 t  S r	   r   r   r   r   r   make_tracerU  s   zTraceTestCase.make_tracerc              
      sR    fdd|D }||kr'|  ddtdd |D dd |D   d S d S )Nc                    s   g | ]
\}}|  |fqS r   r   )r   leline_offsetr   r   
<listcomp>[      z0TraceTestCase.compare_events.<locals>.<listcomp>z"events did not match expectation:

c                 S      g | ]}t |qS r   strr   r#   r   r   r   r   _      c                 S   r   r   r   r   r   r   r   r   `  r   )failjoindifflibZndiff)r   r   r   expected_eventsr   r   r   compare_eventsZ  s   zTraceTestCase.compare_eventsc                 C   s<   |   }t|j |  td  | |jj|j| d S r	   )r   r^   r_   r   r   __code__co_firstlinenor   )r   funcr   tracerr   r   r   run_and_compareb  s   

zTraceTestCase.run_and_comparec                 C   s   |  ||j d S r	   )r   r   r   r   r   r   r   run_testj  r   zTraceTestCase.run_testc                 C   s6   |   }||j td  | |jj|j|j d S r	   )r   r   r^   r_   r   r   r   r   )r   r   r   r   r   r   	run_test2m  s   


zTraceTestCase.run_test2c                 C   s   t d  d S r	   r^   r_   r   r   r   r   test_set_and_retrieve_nonet     z(TraceTestCase.test_set_and_retrieve_nonec              	   C   s0   dd }t | zW t d  d S t d  w )Nc                  W      d S r	   r   argsr   r   r   fny  r(   z4TraceTestCase.test_set_and_retrieve_func.<locals>.fnr   )r   r   r   r   r   test_set_and_retrieve_funcx  s   
z(TraceTestCase.test_set_and_retrieve_funcc                 C      |  t d S r	   )r   r'   r   r   r   r   test_01_basic  r   zTraceTestCase.test_01_basicc                 C   r   r	   )r   r1   r   r   r   r   test_02_arigo0  r   zTraceTestCase.test_02_arigo0c                 C   r   r	   )r   r:   r   r   r   r   test_02_arigo1  r   zTraceTestCase.test_02_arigo1c                 C   r   r	   )r   r;   r   r   r   r   test_02_arigo2  r   zTraceTestCase.test_02_arigo2c                 C   r   r	   )r   rA   r   r   r   r   test_03_one_instr  r   zTraceTestCase.test_03_one_instrc                 C   r   r	   )r   rM   r   r   r   r   test_04_no_pop_blocks  r   z#TraceTestCase.test_04_no_pop_blocksc                 C   r   r	   )r   rH   r   r   r   r   test_05_no_pop_tops  r   z!TraceTestCase.test_05_no_pop_topsc                 C   r   r	   )r   r*   r   r   r   r   test_06_call  r   zTraceTestCase.test_06_callc                 C   r   r	   )r   rZ   r   r   r   r   test_07_raise  r   zTraceTestCase.test_07_raisec                 C   r   r	   )r   re   r   r   r   r   test_08_settrace_and_return  r   z)TraceTestCase.test_08_settrace_and_returnc                 C   r   r	   )r   rh   r   r   r   r   test_09_settrace_and_raise  r   z(TraceTestCase.test_09_settrace_and_raisec                 C   r   r	   )r   rj   r   r   r   r   test_10_ireturn  r   zTraceTestCase.test_10_ireturnc                 C   r   r	   )r   rp   r   r   r   r   test_11_tightloop  r   zTraceTestCase.test_11_tightloopc                 C   r   r	   )r   rq   r   r   r   r   test_12_tighterloop  r   z!TraceTestCase.test_12_tighterloopc                 C   sH   |  t |  }t|j t  td  | tjj|j	tj	 d S r	   )
r   rv   r   r^   r_   r   r   r   r   r   )r   r   r   r   r   test_13_genexp  s   


zTraceTestCase.test_13_genexpc                 C      dd }|  |g d d S )Nc                  S   s   d} dS )NTFr   r   r0   r   r   r   onliners  s   z2TraceTestCase.test_14_onliner_if.<locals>.onliners)r)   r+   r5   rC   r   )r   r   r   r   r   test_14_onliner_if  s
   z TraceTestCase.test_14_onliner_ifc                 C   s4   dd }|  |g d dd }|  |g d d S )Nc                  S   s   t dD ]} qd S Nr4   rE   r0   r   r   r   for_example  s   z0TraceTestCase.test_15_loops.<locals>.for_example)r)   r+   r3   r+   r3   r+   r-   c                  S   s$   d} | dkr| d8 } | dksd S d S )Nr4   r   r&   r   r0   r   r   r   while_example  s   z2TraceTestCase.test_15_loops.<locals>.while_example)r)   r3   r5   r<   r5   r<   r5   rC   r   )r   r   r   r   r   r   test_15_loops  s   
zTraceTestCase.test_15_loopsc                 C   s&   i }t d| | |d g d d S )Na  def f():
































































































































































































































































    passf)r)   )  r,   )r   r.   )execr   )r   	namespacer   r   r   test_16_blank_lines  s   
z!TraceTestCase.test_16_blank_linesc                 C   s   dd }|  |ddg d S )Nc                  S   s   d t  _d} d S r   )r^   r`   rb   )linenor   r   r   r     s   
z0TraceTestCase.test_17_none_f_trace.<locals>.funcr)   r+   r   r   r   r   r   test_17_none_f_trace  s   z"TraceTestCase.test_17_none_f_tracec                 C   r   )Nc               
   S   s6   zzt  t y }  z d } ~ ww  t y   Y d S w r	   rW   )r   r#   rL   r   r   r   r     s   z4TraceTestCase.test_18_except_with_name.<locals>.func)
r)   r+   r3   r5   r6   r\   r<   r7      r,   )	   r,   )r   r.   r   r   r   r   r   test_18_except_with_name  s   z&TraceTestCase.test_18_except_with_namec                 C   r   )Nc                  S   s&   zzt d} w  t y   d}Y d S w )NZ	Something   rW   )rL   ri   r   r   r   r     s   
z7TraceTestCase.test_19_except_with_finally.<locals>.func)	r)   r+   r3   r5   r   r7   rI   r>   r@   r   r   r   r   r   test_19_except_with_finally     	z)TraceTestCase.test_19_except_with_finallyc                    sp   G dd d  fddfdd}|   }g d}z||j W n	 ty+   Y nw | jj|j| d S )Nc                   @   $   e Zd Zdd Zdd Zdd ZdS )zBTraceTestCase.test_20_async_for_loop.<locals>.AsyncIteratorWrapperc                 S   s   t || _d S r	   )iter_it)r   objr   r   r   r     r   zKTraceTestCase.test_20_async_for_loop.<locals>.AsyncIteratorWrapper.__init__c                 S      | S r	   r   r   r   r   r   	__aiter__  r(   zLTraceTestCase.test_20_async_for_loop.<locals>.AsyncIteratorWrapper.__aiter__c                    s"   zt | jW S  ty   tw r	   )nextr   StopIterationStopAsyncIterationr   r   r   r   	__anext__  s   zLTraceTestCase.test_20_async_for_loop.<locals>.AsyncIteratorWrapper.__anext__N)r   r   r   r   r   r   r   r   r   r   AsyncIteratorWrapper  s    r   c                     s&    d2 z3 d H W } | }q6 d}d S )Nabc*   r   )Zletterr#   rL   )r   r   r   
doit_async%  s
   z8TraceTestCase.test_20_async_for_loop.<locals>.doit_asyncc              	      s8     }zt |  |d  W t d  d S t d  w r	   )r^   r_   send)r   r#   )r   r   r   run*  s
   
z1TraceTestCase.test_20_async_for_loop.<locals>.run)(r)   r+   )ir*   )r,   )r   r.   ir*   r,   r   r.   rw   ry   r{   r}   r&   r\   r3   r+   rw   ry   r{   r}   r   r3   r+   rw   ry   r{   r}   r   r3   r+   rw   ry   r{   r~   rS   r,   rT   r[   rV   r   r5   rC   )r   r   rX   r   r   r   r   )r   r   r   r   r   )r   r   r   test_20_async_for_loop  s   )
z$TraceTestCase.test_20_async_for_loopc              	      s   dd   fdd}|   }| }zzt|j |d  W n	 ty(   Y nw W td  ntd  w g d}| |jj|j	| d S )Nc                 S  s   t | D ]}|V  qd S r	   rE   )nro   r   r   r   aranged  s   zGTraceTestCase.test_async_for_backwards_jump_has_no_line.<locals>.arangec                     s,    d2 z3 d H W } | dkr d S q6 d S )Nr6   d   r   ro   r  r   r   r   g  s   zBTraceTestCase.test_async_for_backwards_jump_has_no_line.<locals>.f)r)   r+   rR   rT   r   r   r   r3   r+   r   r*   rT   r   r   r   r3   r+   r  rT   r   r   r   r3   r+   r  rT   rV   r   r-   )
r   r^   r_   r   r   rX   r   r   r   r   )r   r   r   coror   r   r  r   )test_async_for_backwards_jump_has_no_linec  s    
z7TraceTestCase.test_async_for_backwards_jump_has_no_linec                 C   r   )Nc                   S   s   	 d S r	   r   r   r   r   r   r     s   z1TraceTestCase.test_21_repeated_pass.<locals>.funcr)   r+   r3   rK   r   r   r   r   r   test_21_repeated_pass  s   z#TraceTestCase.test_21_repeated_passc                 C   r   )Nc                  S   s   zdD ]} qW dS    Y dS )Nr   r&   r4   r   r  r   r   r   r     s
   
z3TraceTestCase.test_loop_in_try_except.<locals>.funcrB   r   r   r   r   r   test_loop_in_try_except  s   z%TraceTestCase.test_loop_in_try_exceptc                 C   r   )Nc                   S   s   zzW W d S    Y W d S w r	   r   r   r   r   r   r     s   z8TraceTestCase.test_try_except_no_exception.<locals>.func)r)   r+   r3   rI   rr   r   r   r   r   r   test_try_except_no_exception     z*TraceTestCase.test_try_except_no_exceptionc                 C   r   )Nc                  S   s,   t dD ]} t dD ]}| | }q
q|dkS )Nr4   r&   rE   )ro   jrG   r   r   r   r     s
   
z-TraceTestCase.test_nested_loops.<locals>.func)r)   r+   r3   r5   r3   r5   r3   r+   r3   r5   r3   r5   r3   r+   r<   rO   r   r   r   r   r   test_nested_loops     zTraceTestCase.test_nested_loopsc                 C   r   )Nc                  S   s*   ddg} | r|   }|r	 |S | sd}|S )Nr&   r   c   pop)seqr  r   r   r   r     s   z)TraceTestCase.test_if_break.<locals>.func)r)   r+   r3   r5   r<   r3   r5   r<   r7   r   )r   r.   r   r   r   r   r   test_if_break     
zTraceTestCase.test_if_breakc                 C   r   )Nc                  S   s^   d\} }}}z t dD ]}zd} |dkrW d} W d S d} W d}qd}w W d S    d}Y d S )N)r&   r&   r&   r  r6   r8   r   rt   r      rE   )rG   cdro   r   r   r   r     s   
z6TraceTestCase.test_break_through_finally.<locals>.func)r)   r+   r3   r5   r<   r7   rI   r   rt   r,   r5   r<   r7   rI   r>   r     r,   r  r.   r   r   r   r   r   test_break_through_finally     z(TraceTestCase.test_break_through_finallyc                 C   r   )Nc                  S   sZ   d\} }}}}zt dD ]}zd} |dkrW d}qd}W d}qd}w W d S    d}Y d S )N)r&   r&   r&   r&   r  r4   r8   r   rt   r   r  rE   )rG   ri   r  r  ro   r   r   r   r     s   
z9TraceTestCase.test_continue_through_finally.<locals>.func)r)   r+   r3   r5   r<   r7   rI   r   r  r5   r<   r7   rI   r>   r  r5   r  r  r   r   r   r   r   test_continue_through_finally  r  z+TraceTestCase.test_continue_through_finallyc                 C   r   )Nc                   S   s
   zW dS w r   r   r   r   r   r   r   B  s   z7TraceTestCase.test_return_through_finally.<locals>.funcrN   r   r   r   r   r   test_return_through_finally@  r  z)TraceTestCase.test_return_through_finallyc                 C   r   )Nc                   S   s6   zzdd  W W dS  t y   Y W dS w    Y dS )Nr4   r   rJ   )rm   r   r   r   r   r   Q  s   z;TraceTestCase.test_try_except_with_wrong_type.<locals>.func)r)   r+   r3   r]   r5   rI   rr   r   r   r   r   r   test_try_except_with_wrong_typeO  r  z-TraceTestCase.test_try_except_with_wrong_typec                 C   r   )Nc                  S   s"   d} dg}|r|   | r	 qd S r%   r  TRUEr#   r   r   r   r   d  s   z3TraceTestCase.test_break_to_continue1.<locals>.func)
r)   r+   r3   r5   r<   r7   rI   r>   r5   rC   r   r   r   r   r   test_break_to_continue1b     	z%TraceTestCase.test_break_to_continue1c                 C   r   )Nc                  S   s*   d} dg}|r|   | rnq|sd S d S r%   r  r#  r   r   r   r   {  s   z3TraceTestCase.test_break_to_continue2.<locals>.func)	r)   r+   r3   r5   r<   r7   rI   r5   rC   r   r   r   r   r   test_break_to_continue2y  r  z%TraceTestCase.test_break_to_continue2c                 C   r   )Nc                  S   s   d} | r| r		 d S d S d S r%   r   )r$  r   r   r   r     s   z/TraceTestCase.test_break_to_break.<locals>.func)r)   r+   r3   r5   r<   r7   r9   r   r   r   r   r   test_break_to_break     z!TraceTestCase.test_break_to_breakc                 C   r   )Nc                  S   s0   d } }| dkr|dkrd}d S d}d S d}d S )Nr&   r=   rJ   r   r   )rG   ri   r#   rL   zr   r   r   r     s   z+TraceTestCase.test_nested_ifs.<locals>.funcrk   r   r   r   r   r   test_nested_ifs  r  zTraceTestCase.test_nested_ifsc                    s0    fdd}d  d|  |g d d S )Nc                      s4    rrr
t rdS d S d S dS trtrdS d S d S )NFT)DEFr   ABCr   r   r     s   z4TraceTestCase.test_nested_ifs_with_and.<locals>.funcTFrB   r   r   r   r/  r   test_nested_ifs_with_and  s   z&TraceTestCase.test_nested_ifs_with_andc                 C   r   )Nc                  S   s>   d} z	dd  W d}d S  t y   | dkrt Y d}d S w )NZhellor6   r   raiser?   )ZeroDivisionError
ValueError)r#   r   r   r   r   r     s   
z.TraceTestCase.test_nested_try_if.<locals>.func	r)   r+   r3   r5   r   r<   r7   r>   r@   r   r   r   r   r   test_nested_try_if  r&  z TraceTestCase.test_nested_try_ifc                    s.   G dd d  fdd}|  |g d d S )Nc                   @      e Zd Zdd Zdd ZdS )z.TraceTestCase.test_if_false_in_with.<locals>.Cc                 S   r   r	   r   r   r   r   r   r     r(   z8TraceTestCase.test_if_false_in_with.<locals>.C.__enter__c                  W   r   r	   r   r   r   r   r   r     r(   z7TraceTestCase.test_if_false_in_with.<locals>.C.__exit__Nr   r   r   r   r   r   r   r   r   r2        r2  c                      .     
 	 W d    d S 1 sw   Y  d S r	   r   r   r2  r   r   r     s   "z1TraceTestCase.test_if_false_in_with.<locals>.func)r)   r+   rz   r*   r{   r}   r3   r+   rR   rT   rV   r-   r   r   r   r=  r   test_if_false_in_with  s
   z#TraceTestCase.test_if_false_in_withc                 C   r   )Nc                   S   s    zW d S  t y   t Y d S w r	   )rX   Xr   r   r   r   r     s
   
z7TraceTestCase.test_if_false_in_try_except.<locals>.funcr	  r   r   r   r   r   test_if_false_in_try_except  r)  z)TraceTestCase.test_if_false_in_try_exceptc                 C   r   )Nc                  S   s   G dd d} d S )Nc                   @   s    e Zd Zddk rdZdS dZdS )zDTraceTestCase.test_implicit_return_in_class.<locals>.func.<locals>.Ar6   r   r&   r4   N)r   r   r   rG   r   r   r   r   r0    s    r0  r   )r0  r   r   r   r     r   z9TraceTestCase.test_implicit_return_in_class.<locals>.func)r)   r+   )r&   r*   r+   r3   r5   rC   r-   r   r   r   r   r   test_implicit_return_in_class  r)  z+TraceTestCase.test_implicit_return_in_classc                 C   r   )Nc               
   S   sH   zzW W d S  t y }  zW Y d } ~ W d S d } ~ ww  t y#   Y d S w r	   rW   )exr   r   r   r      s   z+TraceTestCase.test_try_in_try.<locals>.funcrB   r   r   r   r   r   test_try_in_try  r   zTraceTestCase.test_try_in_tryc                 C   s   ddd}|  |g d d S )Nr   r&   c                 S   s    |r| r|rd S 	 d S d S 	 d S r	   r   )rG   pr*  r   r   r   r   1  s   z/TraceTestCase.test_if_in_if_in_if.<locals>.funcr	  )r   r&   r&   r   r   r   r   r   test_if_in_if_in_if0  s   

z!TraceTestCase.test_if_in_if_in_ifc                    sJ   G dd d  fdd} fdd}|  |g d |  |g d d S )	Nc                   @   r9  )z-TraceTestCase.test_early_exit_with.<locals>.Cc                 S   r   r	   r   r   r   r   r   r   D  r(   z7TraceTestCase.test_early_exit_with.<locals>.C.__enter__c                  W   r   r	   r   r   r   r   r   r   F  r(   z6TraceTestCase.test_early_exit_with.<locals>.C.__exit__Nr:  r   r   r   r   r2  C  r;  r2  c               	      s:   dD ]}    	 W d     d S 1 sw   Y  qd S )Nr&   r4   r   r  r=  r   r   
func_breakI  s   z6TraceTestCase.test_early_exit_with.<locals>.func_breakc                      r<  r	   r   r   r=  r   r   func_returnO  s   $z7TraceTestCase.test_early_exit_with.<locals>.func_return)r)   r+   r3   r>  r{   r}   r5   r3   rR   rT   rV   r<   rO   )r)   r+   )r   r*   )r,   )rJ  r.   r3   r+   r   r   r   r-   r   )r   rH  rI  r   r=  r   test_early_exit_withA  s   z"TraceTestCase.test_early_exit_withc                    s(   dd   fdd}|  |g d d S )Nc                 S   s0   | rz	d| d   W | S  t y   Y | S w | S r%   r5  r0   r   r   r   fooq  s   z;TraceTestCase.test_flow_converges_on_same_line.<locals>.fooc                     s   t dD ]}  |  qd S r   rE   r  rM  r   r   r   y     
z<TraceTestCase.test_flow_converges_on_same_line.<locals>.func)r)   r+   r3   r   r*   ir,   rT   rV   r+   r3   rP  rQ  )rx   r,   ry   )rz   r\   r{   r   rT   rV   r+   r-   r   r   r   rN  r    test_flow_converges_on_same_lineo  s
   z.TraceTestCase.test_flow_converges_on_same_linec                 C   r   )Nc               
   S   s@   d} zd|   W dS  t y } z
| r W Y d }~dS d }~ww )Nr   r&   donerL  )r#   errorr   r   r   r     s   

zCTraceTestCase.test_no_tracing_of_named_except_cleanup.<locals>.funcr7  r   r   r   r   r   'test_no_tracing_of_named_except_cleanup  r&  z5TraceTestCase.test_no_tracing_of_named_except_cleanupN);r   r   r   r   r   staticmethodr   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
  r  r  r  r  r  r   r!  r"  r%  r'  r(  r+  r3  r8  r?  rA  rB  rD  rF  rK  rR  rU  r   r   r   r   r   H  sr    

		L4$%.$r   c                       *   e Zd Z	  fddZedd Z  ZS )SkipLineEventsTraceTestCasec                    s"   dd |D }t  ||| d S )Nc                 S      g | ]
}|d  dkr|qS r+   r   r   r   r   r   r   r     r   z>SkipLineEventsTraceTestCase.compare_events.<locals>.<listcomp>)superr   )r   r   r   r   Zskip_line_events	__class__r   r   r     s   z*SkipLineEventsTraceTestCase.compare_eventsc                   C   
   t ddS )NF)r   r   r   r   r   r   r        
z'SkipLineEventsTraceTestCase.make_tracerr   r   r   r   rV  r   __classcell__r   r   r\  r   rX    s
    rX  c                       rW  )TraceOpcodesTestCasec                    sF   dd |D }t |dkr| jt |t |dd t ||| d S )Nc                 S   rY  )r&   Zopcoder   rZ  r   r   r   r     r   z7TraceOpcodesTestCase.compare_events.<locals>.<listcomp>r&   z)No 'opcode' events received by the tracer)msg)lenZ
assertLessr[  r   )r   r   r   r   Zskip_opcode_eventsr\  r   r   r     s   z#TraceOpcodesTestCase.compare_eventsc                   C   r^  )NT)r   r   r   r   r   r   r     r_  z TraceOpcodesTestCase.make_tracerr`  r   r   r\  r   rb    s
    rb  c                   @   sd   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S )RaisingTraceFuncTestCasec                 C   s   |  tjt  d S r	   r   r^   r_   r   r   r   r   r   r        zRaisingTraceFuncTestCase.setUpc                 C   s   	 || j krt| jS r	   )raiseOnEventr6  r   r   r   r   r   r     s   
zRaisingTraceFuncTestCase.tracec                 C   s    	 | j dkrd}d| }d S dS )Nr\   r   r&   )rh  )r   r#   rL   r   r   r   r     s
   
zRaisingTraceFuncTestCase.fc              	   C   sz   	 || _ z)tt d D ]}t| j z|   W n	 ty$   Y qw | d qW d S  t	y<   | d Y d S w )Nr&   zexception not raised!zrecursion counter not reset)
rh  rF   r^   getrecursionlimitr_   r   r   r6  r   rf   )r   r   ro   r   r   r   run_test_for_event  s   z+RaisingTraceFuncTestCase.run_test_for_eventc                 C      |  d d S )Nr*   rj  r   r   r   r   	test_call  r   z"RaisingTraceFuncTestCase.test_callc                 C   rk  Nr,   rl  r   r   r   r   	test_line  r   z"RaisingTraceFuncTestCase.test_linec                 C   rk  )Nr.   rl  r   r   r   r   test_return  r   z$RaisingTraceFuncTestCase.test_returnc                 C   rk  Nr\   rl  r   r   r   r   test_exception  r   z'RaisingTraceFuncTestCase.test_exceptionc                    s^   dd   fddt  z   W n ty'   dd l}|  Y d S w | d d S )Nc                  S   s   t dD ]} t|  qd S )Nr8   )rF   printr  r   r   r   r     rO  z4RaisingTraceFuncTestCase.test_trash_stack.<locals>.fc                    s&   |dkr| j  jjd krtdS )Nr,   r4   zi am crashing)r   r   r   rf   )r   whyextrar   gr   r   rw    s   z4RaisingTraceFuncTestCase.test_trash_stack.<locals>.gr   zexception not propagated)r^   r_   rf   r   Zcollectr   )r   r   r   rv  r   test_trash_stack  s   

z)RaisingTraceFuncTestCase.test_trash_stackc              	      st   dd } fdd t  }z$t   z|  W n	 ty#   Y n	w W t | d S W t | d S t | w )Nc                  S   s   d} | j  d S )Nr   )Zno_such_attrr0   r   r   r   r     s   
z<RaisingTraceFuncTestCase.test_exception_arguments.<locals>.fc                    s"   |dkr|\}}} |t  S rq  )assertIsInstancerX   )r   r   r   typer\   r   rw  r   r   r   rw    s   
z<RaisingTraceFuncTestCase.test_exception_arguments.<locals>.g)r^   r   r_   AttributeError)r   r   existingr   r{  r   test_exception_arguments  s   

z1RaisingTraceFuncTestCase.test_exception_argumentsc                    sj   t d  fdddd }| t }t |  W d    n1 s'w   Y  | |j  d S )NzBOOM!c                    s   |dkr d| _ S )Nr,   T)r   )r   r   r   r\   r   r   r   r   #  s   zRRaisingTraceFuncTestCase.test_line_event_raises_before_opcode_event.<locals>.tracec                   S   r   r	   r   r   r   r   r   r   (  r(   zNRaisingTraceFuncTestCase.test_line_event_raises_before_opcode_event.<locals>.f)r6  ZassertRaisesr^   r_   ZassertIsr\   )r   r   Zcaughtr   r  r   *test_line_event_raises_before_opcode_event!  s   
zCRaisingTraceFuncTestCase.test_line_event_raises_before_opcode_eventN)r   r   r   r   r   r   rj  rm  ro  rp  rr  rx  r~  r  r   r   r   r   re    s    	re  c                   @   s$   e Zd Z	 		dddZdd ZdS )	
JumpTracerr,   Fc                 C   s6   |j | _|| _|| _|| _|rd n| jj| _d| _d S )NF)r   codejumpFromjumpTor   r   	firstLinerS  )r   functionr  r  r   	decoratedr   r   r   r   7  s   
zJumpTracer.__init__c                 C   s   | j rd S | jd u r|j| jkr|dkr|jd | _|| jkrd| jd urd|j| j| j krd|}|d urF|j| jkrF|j}|d urF|j| jks9|d urdz	| j| j |_W n t	y`   | j|_Y nw d| _ | j
S )Nr,   r&   T)rS  r  f_coder  r   r   r  ra   r  	TypeErrorr   )r   r   r   r   r   r   r   r   r   @  s&   zJumpTracer.traceN)r,   F)r   r   r   r   r   r   r   r   r   r  4  s    
	r  c              
   C   sJ   z|  d W d S  ty$ } z|  dt|v  W Y d }~d S d }~ww )Nr4   Zinteger)r   r6  r   r   r   r   r   r   no_jump_to_non_integersZ  s    r  c               
   C   sR   zt  j} | j| _W td ty( } zdt|vr W Y d }~d S d }~ww )Nr   z'Trace-function-less jump failed to fail)r^   r`   ra   r   r6  r   AssertionError)Zprevious_framer   r   r   r   no_jump_without_trace_functionb  s   

r  c                   @   s  e Zd Zdd Zdd Z		ddd	Z		dd
dZdddZdddZedddgdd Z	eddg ddd Z
eddddgdd Zeddg ddd Zeddddgd d! Zeddg d"d#d$ Zedddgd%d& Zeddg d'd(d) Zedd*dd*gd+d, Zedd-dd-ged.fd/d0 Zedd1dd1ged.fd2d3 Zedd1ddged4fd5d6 Zedddged4fd7d8 Zeddddgd9d: Zeddg d;d<d= Zeddddgd>d? Zeddddgd@dA Zeddg dBdCdD Zeddg dBdEdF ZedddgdGdH Zeddg dIdJdK ZedddgdLdM Z eddg dNdOdP Z!edd-g dQdRdS Z"eddg dTdUdV Z#eddg dWdXdY Z$eddg dWdZd[ Z%eddg d\d]d^ Z&eddg d\d_d` Z'eddg dadbdc Z(eddg daddde Z)eddg dfdgdh Z*eddg dfdidj Z+edkd1g dldmdn Z,eddg dodpdq Z-eddg dodrds Z.eddg dtdudv Z/eddkg dwdxdy Z0edd-d-dkgdzd{ Z1edd-d-dkgd|d} Z2edddged4fd~d Z3edddgedfdd Z4edddgedfdd Z5edddgedfdd Z6edddgedfdd Z7edddgedfdd Z8eddg edfdd Z9eddg edfdd Z:eddddgedfdd Z;eddddgedfdd Z<eddg edfdd Z=eddg edfdd Z>eddg dedfdd Z?eddg dedfdd Z@eddg edfdd ZAeddddgedfdd ZBeddg edfdd ZCedddgedfdd ZDedd-dgedfdd ZEedddgdd ZFeddg ddd ZGeddg ddd ZHeddg edfdd ZIeddg edfdd ZJeddg dedfdd ZKedddgedfdd ZLed-dg dedfdd ZMed-dg dedfdd ZNeddg dddÄ ZOeddg dddń ZPedd-ddged4fddǄ ZQed-dddgedfddɄ ZRed-dddgedfdd˄ ZSdd̈́ ZTddτ ZUddф ZVddӄ ZWedddgdedfd֍dd؄ ZXedddgdedfd֍dd܄ ZYedddgdedfd֍dd߄ ZZeddddgdddd Z[eddddgdd Z\eddg dd Z]edkdg ddd Z^eddddgdd Z_eddg dd Z`edkdg ddd ZadS )JumpTestCasec                 C       |  tjt  td  d S r	   rf  r   r   r   r   r   q     zJumpTestCase.setUpc                 C   s2   ||kr|  dt| d d t|  d S d S )NzOutputs don't match:
Expected: r   z
Received: )r   repr)r   expectedZreceivedr   r   r   compare_jump_outputu  s   
z JumpTestCase.compare_jump_outputNr,   Fc           
      C   s~   t |||||}t|j g }	|d u r||	 n| j|  ||	 W d    n1 s-w   Y  td  | ||	 d S r	   )r  r^   r_   r   assertRaisesRegexr  
r   r   r  r  r  rT  r   r  r   r   r   r   r   r   {  s   


zJumpTestCase.run_testc           
      C   s   t |||||}t|j g }	|d u rt||	 n| j|  t||	 W d    n1 s3w   Y  td  td  | ||	 d S r	   )	r  r^   r_   r   asyncior   r  Zset_event_loop_policyr  r  r   r   r   run_async_test  s   

zJumpTestCase.run_async_testc                       	  fdd}|S )Nc                    "   t   fdd}|S )Nc              	         | j  dd d S NT)rT  r   r  )r   r   rT  r   r  r   r  r  r   r   test     
z7JumpTestCase.jump_test.<locals>.decorator.<locals>.testr   r   r  rT  r   r  r  r  r   r   	decorator     z)JumpTestCase.jump_test.<locals>.decoratorr   r  r  r  rT  r   r  r   r  r   	jump_test     zJumpTestCase.jump_testc                    r  )Nc                    r  )Nc              	      r  r  )r  r   r  r   r   r    r  z=JumpTestCase.async_jump_test.<locals>.decorator.<locals>.testr   r  r  r  r   r    r  z/JumpTestCase.async_jump_test.<locals>.decoratorr   r  r   r  r   async_jump_test  r  zJumpTestCase.async_jump_testr&   r6   c                 C   "   |  d |  d |  d d S Nr&   r4   r6   r   r   r   r   r   test_jump_simple_forwards     

z&JumpTestCase.test_jump_simple_forwardsr4   )r&   r&   r4   c                 C      |  d |  d d S rD   r  r  r   r   r   test_jump_simple_backwards     
z'JumpTestCase.test_jump_simple_backwardsr8   c                 C   s6   dD ]}|  d dD ]}|  d qq|  d d S )NrG  r4   r6   r=   r8   r  r   ro   r  r   r   r   test_jump_out_of_block_forwards  s   
z,JumpTestCase.test_jump_out_of_block_forwardsrJ   )r&   r6   r8   r&   r6   r8   rJ   r?   c                 C   sJ   |  d dD ]}|  d dD ]}|  d q|  d q|  d d S )Nr&   r   r6   )r4   r8   rJ   r?   r  r  r   r   r    test_jump_out_of_block_backwards  s   

z-JumpTestCase.test_jump_out_of_block_backwardsr=   c                    sJ   dD ]}t ddg2 z3 d H W }| d | d q6 | d qd S )Nr   r&   r4   r6   r=   r8   r$   r   r   ro   r   r   r   )test_jump_out_of_async_for_block_forwards  s   
z6JumpTestCase.test_jump_out_of_async_for_block_forwards)r4   r=   r4   r=   r8   rJ   c                    sR   dD ]#}|  d tdg2 z3 d H W }|  d |  d q6 |  d qd S )Nr   r4   r&   r=   r8   rJ   r   r$   r  r   r   r   *test_jump_out_of_async_for_block_backwards  s   

z7JumpTestCase.test_jump_out_of_async_for_block_backwardsc                 C   r  )Nr&   r6   r  r  r   r   r   test_jump_to_codeless_line  s   
z'JumpTestCase.test_jump_to_codeless_line)r&   r4   r6   c                 C   r  r  r  r  r   r   r   test_jump_to_same_line  r  z#JumpTestCase.test_jump_to_same_liner   c                 C   s   z%|  d W |  d z|  d W |  d n|  d w |  d d S |  d z|  d W |  d n|  d w |  d w )Nr4   r=   rJ   r   r   r  r  r   r   r   test_jump_in_nested_finally  s   

z(JumpTestCase.test_jump_in_nested_finallyr?    c              	   C   sD   z|  d dd  W |  d |  d d S |  d |  d w )Nr4   r&   r   rJ   r?   r  r  r   r   r   test_jump_in_nested_finally_2  s   


z*JumpTestCase.test_jump_in_nested_finally_2   c                 C   s   z)|  d dd  W |  d z|  d W |  d n|  d w |  d d S |  d z|  d W |  d n|  d w |  d w )Nr4   r&   r   rJ   r   rt   r  r  r  r   r   r   test_jump_in_nested_finally_3  s   


z*JumpTestCase.test_jump_in_nested_finally_3Zafterc              	   C   F   z|  d W |  d |  d d S |  d |  d    Y d S Nr4   r=   r8   r  r  r   r   r   5test_no_jump_over_return_try_finally_in_finally_block     



zBJumpTestCase.test_no_jump_over_return_try_finally_in_finally_blockc                 C   s   |  d 	 |  d q)Nr&   Tr6   r  r  r   r   r    test_no_jump_infinite_while_loop   s   

z-JumpTestCase.test_no_jump_infinite_while_loopc                 C   s8   d}|  d |dkr|  d |d7 }|dksd S d S )Nr&   r4   r=   r  r  r   r   r   #test_jump_forwards_into_while_block'  s   

z0JumpTestCase.test_jump_forwards_into_while_block)r6   r6   r6   r8   c                 C   s4   d}|dkr|  d |d7 }|dks|  d d S )Nr&   r4   r6   r8   r  r  r   r   r   $test_jump_backwards_into_while_block/  s   
z1JumpTestCase.test_jump_backwards_into_while_blockc                 C   B   t | d | d W d    n1 sw   Y  | d d S r  r   r   r  r   r   r   $test_jump_forwards_out_of_with_block7     z1JumpTestCase.test_jump_forwards_out_of_with_blockc              	      X   t | d4 I d H  | d W d   I d H  n1 I d H s w   Y  | d d S r  r   r   r  r   r   r   *test_jump_forwards_out_of_async_with_block=  
   (z7JumpTestCase.test_jump_forwards_out_of_async_with_block)r&   r4   r&   r4   r6   rU   c                 C   D   |  d t| d |  d W d    d S 1 sw   Y  d S r  r   r   r  r   r   r   %test_jump_backwards_out_of_with_blockC     
"z2JumpTestCase.test_jump_backwards_out_of_with_blockc              	      Z   |  d t| d4 I d H  |  d W d   I d H  d S 1 I d H s&w   Y  d S r  r   r   r  r   r   r   +test_jump_backwards_out_of_async_with_blockI  
   
.z8JumpTestCase.test_jump_backwards_out_of_async_with_blockc              	   C   4   z|  d W |  d n|  d w |  d d S r  r  r  r   r   r   +test_jump_forwards_out_of_try_finally_blockO     z8JumpTestCase.test_jump_forwards_out_of_try_finally_block)r&   r&   r6   r8   c              	   C   2   |  d z|  d W |  d d S |  d w Nr&   r6   r8   r  r  r   r   r   ,test_jump_backwards_out_of_try_finally_blockW     
z9JumpTestCase.test_jump_backwards_out_of_try_finally_blockc                 C   0   z|  d W n	   |  d  |  d d S Nr4   r=   rJ   r  r  r   r   r   *test_jump_forwards_out_of_try_except_block_     
z7JumpTestCase.test_jump_forwards_out_of_try_except_block)r&   r&   r6   c                 C   .   |  d z|  d W d S    |  d  r  r  r  r   r   r   +test_jump_backwards_out_of_try_except_blockh     

z8JumpTestCase.test_jump_backwards_out_of_try_except_block)r=   r?   r   c                 C   s\   zdd  W n  t y   | d | d Y n ty&   | d Y nw | d d S Nr&   r   r=   r8   r?   r   r5  r   FloatingPointErrorr  r   r   r   test_jump_between_except_blocksq  s   
z,JumpTestCase.test_jump_between_except_blocks)r=   rJ   r?   c                 C   sB   zdd  W n   |  d |  d |  d Y |  d d S )Nr&   r   r=   r8   rJ   r?   r  r  r   r   r   test_jump_within_except_block|  s   

z*JumpTestCase.test_jump_within_except_block)r&   r=   r8   r|   c                 C   x   |  d t| d |  d W d    n1 sw   Y  t| d |  d W d    d S 1 s5w   Y  d S Nr&   r4   r6   r=   r8   r  r  r   r   r   test_jump_across_with     
"z"JumpTestCase.test_jump_across_withc              	         |  d t| d4 I d H  |  d W d   I d H  n1 I d H s%w   Y  t| d4 I d H  |  d W d   I d H  d S 1 I d H sJw   Y  d S r  r  r  r   r   r   test_jump_across_async_with     
(.z(JumpTestCase.test_jump_across_async_with)r&   r6   r8   rJ   c              	   C   s`   |  d dD ]!}t| d |  d W d    n1 sw   Y  |  d q|  d d S Nr&   r   r6   r=   r8   rJ   r  r  r   r   r   ,test_jump_out_of_with_block_within_for_block  s   
z9JumpTestCase.test_jump_out_of_with_block_within_for_blockc              
      sv   |  d dD ]+}t| d4 I d H  |  d W d   I d H  n1 I d H s)w   Y  |  d q|  d d S r  r  r  r   r   r   2test_jump_out_of_async_with_block_within_for_block  s   
(z?JumpTestCase.test_jump_out_of_async_with_block_within_for_block)r&   r4   r6   r8   rU   rJ   c              	   C   s   |  d t| d' t| d |  d W d    n1 s w   Y  |  d W d    n1 s4w   Y  |  d d S Nr&   r4   r6   r=   r8   rJ   r  r  r   r   r   -test_jump_out_of_with_block_within_with_block  s   
z:JumpTestCase.test_jump_out_of_with_block_within_with_blockc              
      s   |  d t| d1 t| d4 I d H  |  d W d   I d H  n1 I d H s+w   Y  |  d W d    n1 s?w   Y  |  d d S r  )r   r   r   r  r   r   r   3test_jump_out_of_async_with_block_within_with_block  s   
(z@JumpTestCase.test_jump_out_of_async_with_block_within_with_block)r4   r=   rJ   r?   c                 C   s   z&|  d W t| d |  d W d    n1 sw   Y  |  d n t| d |  d W d    n1 s<w   Y  |  d w |  d d S Nr4   r=   r8   rJ   r?   r  r  r   r   r   0test_jump_out_of_with_block_within_finally_block  s   z=JumpTestCase.test_jump_out_of_with_block_within_finally_blockc                    s   z0|  d W t| d4 I d H  |  d W d   I d H  n1 I d H s'w   Y  |  d n*t| d4 I d H  |  d W d   I d H  n1 I d H sQw   Y  |  d w |  d d S r  r  r  r   r   r   6test_jump_out_of_async_with_block_within_finally_block  s   ((zCJumpTestCase.test_jump_out_of_async_with_block_within_finally_blockr   )r&   r6   r8   r  r  c                 C   sx   |  d dD ]-}|  d dD ]}|  d zdD ]}|  d qW |  d q|  d w |  d q|  d	 d S )
Nr&   r   r6   rG  r8   r   rt   r  r  r  )r   ro   r  kr   r   r   &test_jump_out_of_complex_nested_blocks  s   


z3JumpTestCase.test_jump_out_of_complex_nested_blocks)r&   r4   r8   c                 C   sL   |  d t| d}|  d W d    n1 sw   Y  |  d d S Nr&   r4   r=   r8   r  r   r#   r   r   r    test_jump_out_of_with_assignment  s   

z-JumpTestCase.test_jump_out_of_with_assignmentc              	      sb   |  d t| d4 I d H }|  d W d   I d H  n1 I d H s%w   Y  |  d d S r  r  r  r   r   r   &test_jump_out_of_async_with_assignment  s   
(z3JumpTestCase.test_jump_out_of_async_with_assignment)r&   rJ   r   r   c              	   C   s\   |  d z|  d | sW |  d d S |  d W |  d n|  d w |  d d S )Nr&   r6   r   rJ   r   r  r  r   r   r   *test_jump_over_return_in_try_finally_block  s   

z7JumpTestCase.test_jump_over_return_in_try_finally_block)r&   r6   r   rt   r  r  c              	   C   sr   |  d 	 |  d z|  d | sW |  d n|  d W |  d n|  d w |  d 	 |  d d S )	Nr&   Tr6   r8   rt   r   r  r  r  r  r   r   r   )test_jump_over_break_in_try_finally_block  s   



z6JumpTestCase.test_jump_over_break_in_try_finally_blockc                 C   F   |  d | sdD ]}|  d q	n
|  d |  d |  d d S Nr&   r  r=   rJ   r?   r   r  r  r   r   r   $test_jump_over_for_block_before_else	     


z1JumpTestCase.test_jump_over_for_block_before_elsec                    X   |  d | stdg2 z3 d H W }|  d q6 n
|  d |  d |  d d S Nr&   r6   r=   rJ   r?   r   r  r  r   r   r   *test_jump_over_async_for_block_before_else     


z7JumpTestCase.test_jump_over_async_for_block_before_elsec                 C   r  rD   r  r  r   r   r   test_no_jump_too_far_forwards!  r  z*JumpTestCase.test_no_jump_too_far_forwardsrU   beforec                 C   r  rD   r  r  r   r   r   test_no_jump_too_far_backwards&  r  z+JumpTestCase.test_no_jump_too_far_backwardsexceptc                 C   s$   z|  d W d S    |  d  Nr4   r=   r  r  r   r   r   test_no_jump_to_except_1,  s
   
z%JumpTestCase.test_no_jump_to_except_1c                 C   s,   z|  d W d S  ty   |  d  w r  r   r6  r  r   r   r   test_no_jump_to_except_24  s   
z%JumpTestCase.test_no_jump_to_except_2c              
   C   s8   z|  d W d S  ty } z|  d |d }~ww r  r  r  r   r   r   test_no_jump_to_except_3<  s   
z%JumpTestCase.test_no_jump_to_except_3c              
   C   s<   z|  d W d S  ttfy } z|  d |d }~ww r  )r   r6  rf   r  r   r   r   test_no_jump_to_except_4D  s   
z%JumpTestCase.test_no_jump_to_except_4Zintoc                 C   s"   |  d dD ]}|  d qd S )Nr&   rG  r6   r  r  r   r   r   $test_no_jump_forwards_into_for_blockL  s   
z1JumpTestCase.test_no_jump_forwards_into_for_blockc                    s6   |  d tddg2 z3 d H W }|  d q6 d S r  r  r  r   r   r   *test_no_jump_forwards_into_async_for_blockR  s   
z7JumpTestCase.test_no_jump_forwards_into_async_for_blockc                 C   s"   dD ]}|  d q|  d d S )NrG  r4   r6   r  r  r   r   r   %test_no_jump_backwards_into_for_blockY  s   z2JumpTestCase.test_no_jump_backwards_into_for_blockc                    s6   t ddg2 z3 d H W }| d q6 | d d S r  r  r  r   r   r   +test_no_jump_backwards_into_async_for_block_  s
   z8JumpTestCase.test_no_jump_backwards_into_async_for_blockc                 C   r  r  r  r  r   r   r   %test_no_jump_forwards_into_with_blocke  r  z2JumpTestCase.test_no_jump_forwards_into_with_blockc              	      r  r  r  r  r   r   r   +test_no_jump_forwards_into_async_with_blockk  r  z8JumpTestCase.test_no_jump_forwards_into_async_with_block)r&   r4   r   c                 C   r  r  r  r  r   r   r   &test_no_jump_backwards_into_with_blockq  r  z3JumpTestCase.test_no_jump_backwards_into_with_blockc              	      r  r  r  r  r   r   r   ,test_no_jump_backwards_into_async_with_blockw  r  z9JumpTestCase.test_no_jump_backwards_into_async_with_blockc              	   C   r  r  r  r  r   r   r   ,test_no_jump_forwards_into_try_finally_block}  r  z9JumpTestCase.test_no_jump_forwards_into_try_finally_blockc              	   C   r  r  r  r  r   r   r   -test_no_jump_backwards_into_try_finally_block  r  z:JumpTestCase.test_no_jump_backwards_into_try_finally_blockc                 C   r  r  r  r  r   r   r   +test_no_jump_forwards_into_try_except_block  r  z8JumpTestCase.test_no_jump_forwards_into_try_except_blockc                 C   r  r  r  r  r   r   r   ,test_no_jump_backwards_into_try_except_block  r  z9JumpTestCase.test_no_jump_backwards_into_try_except_blockc              
   C   sn   zdd  W n) t y   | d | d Y n ty/ } z| d W Y d }~nd }~ww | d d S r  r  r  r   r   r   $test_no_jump_between_except_blocks_2  s   
z1JumpTestCase.test_no_jump_between_except_blocks_2c              	   C   r  r  r  r  r   r   r   test_jump_into_finally_block  r  z)JumpTestCase.test_jump_into_finally_block)r4   rJ   r?   c              	   C   sR   z|  d |  d W |  d |  d n|  d |  d w |  d d S )Nr4   r6   r8   rJ   r?   r  r  r   r   r   +test_jump_into_finally_block_from_try_block  s   


z8JumpTestCase.test_jump_into_finally_block_from_try_block)r&   r6   r&   r6   r8   c              	   C   r  r  r  r  r   r   r   test_jump_out_of_finally_block  r  z+JumpTestCase.test_jump_out_of_finally_blockzinto an 'except'c                 C   s2   |  d z|  d W d S    |  d Y d S r  r  r  r   r   r   #test_no_jump_into_bare_except_block  s
   
z0JumpTestCase.test_no_jump_into_bare_except_blockc                 C   s:   |  d z|  d W d S  ty   |  d Y d S w r  r   rX   r  r   r   r   (test_no_jump_into_qualified_except_block  s   
z5JumpTestCase.test_no_jump_into_qualified_except_block)r4   r8   rJ   c                 C   sD   z|  d |  d W n   |  d |  d  |  d d S Nr4   r6   r8   rJ   r   r  r  r   r   r   2test_no_jump_into_bare_except_block_from_try_block  s   


z?JumpTestCase.test_no_jump_into_bare_except_block_from_try_blockc                 C   sL   z|  d |  d W n ty   |  d |  d  w |  d d S r(  )r   r5  r  r   r   r   7test_no_jump_into_qualified_except_block_from_try_block  s   


zDJumpTestCase.test_no_jump_into_qualified_except_block_from_try_block)r&   r6   rJ   zout of an 'except'c                 C   sD   |  d z|  d dd  W d S    |  d |  d Y d S Nr&   r6   r   rJ   r?   r  r  r   r   r   %test_no_jump_out_of_bare_except_block  s   


z2JumpTestCase.test_no_jump_out_of_bare_except_blockc                 C   sL   |  d z|  d dd  W d S  ty%   |  d |  d Y d S w r+  r&  r  r   r   r   *test_no_jump_out_of_qualified_except_block  s   


z7JumpTestCase.test_no_jump_out_of_qualified_except_block)r&   r4   r8   rU   c                 C   r  r  r  r  r   r   r   test_jump_between_with_blocks  r  z*JumpTestCase.test_jump_between_with_blocksc              	      r  r  r  r  r   r   r   #test_jump_between_async_with_blocks  r  z0JumpTestCase.test_jump_between_async_with_blocksc              	   C   r  r  r  r  r   r   r   -test_no_jump_over_return_out_of_finally_block  r  z:JumpTestCase.test_no_jump_over_return_out_of_finally_blockc                 C   r  r  r  r  r   r   r   'test_no_jump_into_for_block_before_else  r  z4JumpTestCase.test_no_jump_into_for_block_before_elsec                    r  r  r  r  r   r   r   -test_no_jump_into_async_for_block_before_else$  r
  z:JumpTestCase.test_no_jump_into_async_for_block_before_elsec                 C   s   |  tdddg d S )Nr4   ZSpamT)r   r  r   r   r   r   test_no_jump_to_non_integers/  rg  z)JumpTestCase.test_no_jump_to_non_integersc                 C   rQ   r	   )r  r   r   r   r   #test_no_jump_without_trace_function2  s   
z0JumpTestCase.test_no_jump_without_trace_functionc                 C   s0   i }t dd | |d }| |dddg d S )Na  def f(output):        # line 0
            x = 0                     # line 1
            y = 1                     # line 2
            '''                       # line 3
            %s                        # lines 4-1004
            '''                       # line 1005
            x += 1                    # line 1006
            output.append(x)          # line 1007
            return)a  







































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































r   r4   i  r   )r   r   )r   r  r   r   r   r   test_large_function7  s   	z JumpTestCase.test_large_functionc                    sj   t ddd G  fddd}t|dd}t|j dg i}t | td  | g d	|d  d S )
Nzd
# Comments don't count.
output.append(2)  # firstlineno is here.
output.append(3)
output.append(4)
z<fake module>r   c                       s   e Zd Z ZdS )z<JumpTestCase.test_jump_to_firstlineno.<locals>.fake_functionN)r   r   r   r   r   r  r   r   fake_functionO  s    r7  r=   r&   r   )r4   r6   r4   r6   r=   )compiler  r^   r_   r   r   r  )r   r7  r   r   r   r6  r   test_jump_to_firstlinenoE  s   

z%JumpTestCase.test_jump_to_firstlinenor*   z5can't jump from the 'call' trace event of a new frame)r   rT  c                    s*     d  fdd}|    d d S )Nr&   c                      s     d d S )Nr6   r  r   r  r   r   nested\  r   z3JumpTestCase.test_no_jump_from_call.<locals>.nestedr8   r  )r   r:  r   r  r   test_no_jump_from_callX  s   
z#JumpTestCase.test_no_jump_from_callr.   z'can only jump from a 'line' trace eventc                 C   rk  r%   r  r  r   r   r   test_no_jump_from_return_eventa  s   
z+JumpTestCase.test_no_jump_from_return_eventr\   c                 C   s   |  d dd  d S )Nr&   r   r  r  r   r   r   !test_no_jump_from_exception_eventg  s   
z.JumpTestCase.test_no_jump_from_exception_event)r   c                    s$    fdd}t |   d d S )Nc                   3   s      d dV  d S )Nr4   r6   r  r   r  r   r   geno  s   

z.JumpTestCase.test_jump_from_yield.<locals>.genr8   )r   r   )r   r>  r   r  r   test_jump_from_yieldm  s   
z!JumpTestCase.test_jump_from_yieldc                 C   s*   |  d dd tdD }|  d d S )Nr&   c                 S      g | ]}|qS r   r   r   ro   r   r   r   r   x      z@JumpTestCase.test_jump_forward_over_listcomp.<locals>.<listcomp>rt   r6   r   rF   r  r   r   r   test_jump_forward_over_listcompu  s   
z,JumpTestCase.test_jump_forward_over_listcompc                 C   s   d}dd t dD }d}d S )Nr&   c                 S   r@  r   r   rA  r   r   r   r     rB  zAJumpTestCase.test_jump_backward_over_listcomp.<locals>.<listcomp>rt   r6   rE   r   rG   r#   r  r   r   r    test_jump_backward_over_listcomp}  s   z-JumpTestCase.test_jump_backward_over_listcomp)r4   r?   r4   c                 C   sD   d}|  d |rd S dd tdD }d}|  d |  d d S )	NFr4   c                 S   r@  r   r   rA  r   r   r   r     rB  zDJumpTestCase.test_jump_backward_over_listcomp_v2.<locals>.<listcomp>r8   rJ   r?   r   rC  r   flagr#   r   r   r   #test_jump_backward_over_listcomp_v2  s   

z0JumpTestCase.test_jump_backward_over_listcomp_v2c                    s6   |  d dd ttd2 I d H }|  d d S )Nr&   c                       g | z3 d H W }|q6 S r	   r   rA  r   r   r   r         zFJumpTestCase.test_jump_forward_over_async_listcomp.<locals>.<listcomp>rt   r6   r   r$   rF   r  r   r   r   %test_jump_forward_over_async_listcomp  s   
z2JumpTestCase.test_jump_forward_over_async_listcompc                    s*   d}dd t td2 I d H }d}d S )Nr&   c                    rJ  r	   r   rA  r   r   r   r     rK  zGJumpTestCase.test_jump_backward_over_async_listcomp.<locals>.<listcomp>rt   r6   )r$   rF   rE  r   r   r   &test_jump_backward_over_async_listcomp  s   z3JumpTestCase.test_jump_backward_over_async_listcompc                    sP   d}|  d |rd S dd ttd2 I d H }d}|  d |  d d S )	NFr4   c                    rJ  r	   r   rA  r   r   r   r     rK  zJJumpTestCase.test_jump_backward_over_async_listcomp_v2.<locals>.<listcomp>r8   rJ   r?   r   rL  rG  r   r   r   )test_jump_backward_over_async_listcomp_v2  s   

z6JumpTestCase.test_jump_backward_over_async_listcomp_v2)Nr,   Frn  )br   r   r   r   r  r   r  r  r  r  r  r  r  r  r  r  r  r  r5  r  r  r6  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  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/  r0  r1  r2  r3  r4  r5  r9  r;  r<  r=  r?  rD  rF  rI  rM  rN  rO  r   r   r   r   r  p  sr   







	






















	






	
	

























	



	







	
	


	















r  c                   @   r   )TestEdgeCasesc                 C   r  r	   rf  r   r   r   r   r     r  zTestEdgeCases.setUpc                    s   dd }dd  G  fddd}t |  t }t | | |jj|j | |jj	t
 W d    n1 s<w   Y  | t  | d S )Nc                  W   r   r	   r   r   r   r   r   rM    r(   z*TestEdgeCases.test_reentrancy.<locals>.fooc                  W   r   r	   r   r   r   r   r   bar  r(   z*TestEdgeCases.test_reentrancy.<locals>.barc                       s    e Zd Zdd Z fddZdS )z(TestEdgeCases.test_reentrancy.<locals>.Ac                 W   r   r	   r   )r   r   r   r   r   __call__  r(   z1TestEdgeCases.test_reentrancy.<locals>.A.__call__c                    s   t   d S r	   r   r   rQ  r   r   __del__  r   z0TestEdgeCases.test_reentrancy.<locals>.A.__del__N)r   r   r   rR  rT  r   rS  r   r   r0    s    r0  )r^   r_   r   Zcatch_unraisable_exceptionZassertEqualZ
unraisableobjectrT  ry  	exc_valuerf   r   )r   rM  r0  cmr   rS  r   test_reentrancy  s   

zTestEdgeCases.test_reentrancyc                 C   s&   dd }t | ~t t   d S )Nc                  W   r   r	   r   r   r   r   r   rM    r(   z+TestEdgeCases.test_same_object.<locals>.foo)r^   r_   r   )r   rM  r   r   r   test_same_object  s   
zTestEdgeCases.test_same_objectN)r   r   r   r   rX  rY  r   r   r   r   rP    s    rP  __main__)1r  r   ZunittestZunittest.mockr   r^   r   r   	functoolsr   r  r   r   r$   r'   r   r1   r:   r;   rA   rH   rM   rP   r*   rY   rZ   rd   re   rg   rh   rj   rp   rq   rs   rv   r   ZTestCaser   rX  Zcpython_onlyrb  re  r  r  r  r  rP  r   mainr   r   r   r   <module>   s   



	








	


      hn&      <
&