o
    g                     @   sN  d dl m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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d/d0 Zg d1e_d2d3 Zg d4e_d5d6 Zg d7e_d8d9 Zg d:e_d;d< Zd=d> Z g d?d@dAgdB  d@dCg e _G dDdE dEZ!G dFdG dGej"Z#G dHdI dIe#Z$ej%G dJdK dKe#Z&G dLdM dMej"Z'G dNdO dOZ(dPdQ Z)dRdS Z*G dTdU dUej"Z+e,dVkr%e-  dS dS )W    )supportNwrapsc                   @   (   e Zd ZdZdd Zdd Zdd ZdS )	tracecontextz/Context manager that traces its enter and exit.c                 C      || _ || _d S Noutputvalueselfr
   r    r   L/Users/admin/.pyenv/versions/3.10.0/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____doc__r   r   r   r   r   r   r   r      
    r   c                   @   r   )	asynctracecontextz>Asynchronous context manager that traces its aenter and aexit.c                 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   r   c                 C  s   | D ]}|V  qdS )z0Convert an iterable to an asynchronous iterator.Nr   )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 Nr&   r   r   r#   r   r   r   arigo_example0:      r2   )r)   r+      r,      r,      r,   r9   r.   c                  C   r/   r0   r   r1   r   r   r   arigo_example1H   r3   r;   c                  C   r/   r%   r   r1   r   r   r   arigo_example2V   s
   r<   )r)   r+   r4   r6      r,      r,   r@   r.   c                  C   s   d} ~ d} d S r%   r   r1   r   r   r   one_instr_linei   s   rB   r)   r+   r4   r6   r7   r.   c                  C   s$   d} t dD ]	}|rd} qd} qd S Nr&   r5   range)r#   ar   r   r   no_pop_topst   s   rI   )
r)   r+   r4   r6      r,   r4   r6   r=   r4   r5   r.   c                  C   s   d} | st  | rd}d S r%   )Zbla)yr#   r   r   r   no_pop_blocks   s
   rN   r)   r+   r4   r=   r>   r.   c                  C   s   d} d S r%   r   r1   r   r   r   called   s   rQ   c                   C   
   t   d S r   )rQ   r   r   r   r   r*      s   
r*   )r)   r+   r*   r,   rV   r.   r-   c                   C   s   t r   	Exceptionr   r   r   r   raises   r(   rZ   c                   C   s"   zt   W d S  ty   Y d S w r   )rZ   rY   r   r   r   r   
test_raise   s
   r[   )r)   r+   r4   rS   rU   rV   	exceptionrW   r5   r]   r6   r=   rP   c                 C   s   t |  | t  j_d S r   )syssettrace	_getframef_backf_traceZ	tracefuncr   r   r   _settrace_and_return   s   
re   c                 C   s   t |  d S r   )re   rd   r   r   r   settrace_and_return   s   rf   r-   c                 C   s   t |  | t  j_tr   )r_   r`   ra   rb   rc   RuntimeErrorrd   r   r   r   _settrace_and_raise   s   
rh   c                 C   s$   zt |  W d S  ty   Y d S w r   )rh   rg   rd   r   r   r   settrace_and_raise   s
   ri   )r^   r6   r=   rP   c                  C   s"   d} d}| |kr| d }d S 	 d S )Nr9   r&   r   )rH   br   r   r   ireturn_example   s
   rk   r)   r+   r4   r6   r=   rP   c                  C   s8   t dd} zd}	 | | }|d7 }q	 ty   Y d S w )Nr   r7   r&   rG   
IndexError)itemsirj   r   r   r   tightloop_example   s   
rq   )r)   r+   r4   r6   r=   r8   r=   r8   r=   r8   r=   r8   )r9   r]   rJ   r?   rA   c                  C   s.   t dd} zd}| | }q ty   Y d S w )Nr&   r>   r   rm   )ro   rp   r   r   r   tighterloop_example   s   

rr   )r)   r+   r4   r6   r=   r=   r=   r=   )r>   r]   r8   rJ   rK   r.   c                   c   s    zdV  W d S w )NTr   r   r   r   r   generator_function  s
   rt   c                  C   s    t t } tdD ]} | }q	d S )N
   )anyrt   rG   )r#   rM   r   r   r   generator_example  s   
rw   )
r)   r4   r*   r,   r,   r}   r.   )r}   r*   r}   r]   )r,   )r   r.   r8   rJ   ru   r:   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   0  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_frame5  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>B  s    z)Tracer.traceWithGenexp.<locals>.<genexpr>r&   r   r   r   r   r   traceWithGenexp@  s   
zTracer.traceWithGenexp)NN)r   r   r   r   r   r   r   r   r   r   r   r   /  s
    
r   c                   @   s  e Zd Zdd Zdd Z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 Z9dmS )nTraceTestCasec                 C   s(   t  | _t   | tjt  d S r   )gc	isenabledusing_gcdisable
addCleanupr_   r`   gettracer   r   r   r   setUpK  s   
zTraceTestCase.setUpc                 C   s   | j r	t  d S d S r   )r   r   enabler   r   r   r   tearDownP  s   zTraceTestCase.tearDownc                   C   s   t  S )z@Helper to allow test subclasses to configure tracers differentlyNr   r   r   r   r   make_tracerT  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>Z      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_eventsY  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_comparea  s   

zTraceTestCase.run_and_comparec                 C   s   |  ||j d S r   )r   r   r   r   r   r   r   run_testi  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_test2l  s   


zTraceTestCase.run_test2c                 C   s   t d  d S r   r_   r`   r   r   r   r   test_set_and_retrieve_nones     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   fnx  r(   z4TraceTestCase.test_set_and_retrieve_func.<locals>.fnr   )r   r   r   r   r   test_set_and_retrieve_funcw  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   r2   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   rB   r   r   r   r   test_03_one_instr  r   zTraceTestCase.test_03_one_instrc                 C   r   r   )r   rN   r   r   r   r   test_04_no_pop_blocks  r   z#TraceTestCase.test_04_no_pop_blocksc                 C   r   r   )r   rI   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   r[   r   r   r   r   test_07_raise  r   zTraceTestCase.test_07_raisec                 C   r   r   )r   rf   r   r   r   r   test_08_settrace_and_return  r   z)TraceTestCase.test_08_settrace_and_returnc                 C   r   r   )r   ri   r   r   r   r   test_09_settrace_and_raise  r   z(TraceTestCase.test_09_settrace_and_raisec                 C   r   r   )r   rk   r   r   r   r   test_10_ireturn  r   zTraceTestCase.test_10_ireturnc                 C   r   r   )r   rq   r   r   r   r   test_11_tightloop  r   zTraceTestCase.test_11_tightloopc                 C   r   r   )r   rr   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   rw   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   r1   r   r   r   onliners  s   z2TraceTestCase.test_14_onliner_if.<locals>.onliners)r)   r+   r6   rD   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 Nr5   rF   r1   r   r   r   for_example  s   z0TraceTestCase.test_15_loops.<locals>.for_example)r)   r+   r4   r+   r4   r+   r-   c                  S   s$   d} | dkr| d8 } | dksd S d S )Nr5   r   r&   r   r1   r   r   r   while_example  s   z2TraceTestCase.test_15_loops.<locals>.while_example)r)   r4   r6   r=   r6   r=   r6   rD   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_   ra   rc   )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 )N	SomethingrX   )r   r#   rM   r   r   r   r     s   z4TraceTestCase.test_18_except_with_name.<locals>.func)
r)   r+   r4   r6   r7   r]   r=   r8      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 )Nr      rX   )rM   rj   r   r   r   r     s   
z7TraceTestCase.test_19_except_with_finally.<locals>.func)	r)   r+   r4   r6   r   r8   rJ   r?   rA   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                   @   s$   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#   rM   )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.   rx   rz   r|   r~   r&   r]   r4   r+   rx   rz   r|   r~   r   r4   r+   rx   rz   r|   r~   r   r4   r+   rx   rz   r|   r   rT   r,   rU   r\   rW   r   r6   rD   )r   r   rY   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                 C   r   )Nc                   S   s   	 d S r   r   r   r   r   r   r   c  s   z1TraceTestCase.test_21_repeated_pass.<locals>.funcr)   r+   r4   rL   r   r   r   r   r   test_21_repeated_passb  s   z#TraceTestCase.test_21_repeated_passc                 C   r   )Nc                  S   s   zdD ]} qW dS    Y dS )Nr   r&   r5   r   rp   r   r   r   r   p  s
   
z3TraceTestCase.test_loop_in_try_except.<locals>.funcrC   r   r   r   r   r   test_loop_in_try_exceptm  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+   r4   rJ   rs   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 )Nr5   r&   rF   )rp   jrH   r   r   r   r     s
   
z-TraceTestCase.test_nested_loops.<locals>.func)r)   r+   r4   r6   r4   r6   r4   r+   r4   r6   r4   r6   r4   r+   r=   rP   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)seqnr   r   r   r     s   z)TraceTestCase.test_if_break.<locals>.func)r)   r+   r4   r6   r=   r4   r6   r=   r8   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	  r7   r9   r   ru   r      rF   )rH   cdrp   r   r   r   r     s   
z6TraceTestCase.test_break_through_finally.<locals>.func)r)   r+   r4   r6   r=   r8   rJ   r   ru   r,   r6   r=   r8   rJ   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	  r5   r9   r   ru   r   r  rF   )rH   rj   r  r  rp   r   r   r   r     s   
z9TraceTestCase.test_continue_through_finally.<locals>.func)r)   r+   r4   r6   r=   r8   rJ   r   r  r6   r=   r8   rJ   r?   r  r6   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     s   z7TraceTestCase.test_return_through_finally.<locals>.funcrO   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 )Nr5   r   rK   )rn   r   r   r   r   r     s   z;TraceTestCase.test_try_except_with_wrong_type.<locals>.func)r)   r+   r4   r^   r6   rJ   rs   r   r   r   r   r   test_try_except_with_wrong_type  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   /  s   z3TraceTestCase.test_break_to_continue1.<locals>.func)
r)   r+   r4   r6   r=   r8   rJ   r?   r6   rD   r   r   r   r   r   test_break_to_continue1-     	z%TraceTestCase.test_break_to_continue1c                 C   r   )Nc                  S   s*   d} dg}|r|   | rqq|sd S d S r%   r
  r  r   r   r   r   F  s   z3TraceTestCase.test_break_to_continue2.<locals>.func)	r)   r+   r4   r6   r=   r8   rJ   r6   rD   r   r   r   r   r   test_break_to_continue2D  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+   r4   r6   r=   r8   r:   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>   rK   r   r   )rH   rj   r#   rM   zr   r   r   r   o  s   z+TraceTestCase.test_nested_ifs.<locals>.funcrl   r   r   r   r   r   test_nested_ifsm  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>.funcTFrC   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hellor7   r   raiser@   )ZeroDivisionError
ValueError)r#   r   r   r   r   r     s   
z.TraceTestCase.test_nested_try_if.<locals>.func	r)   r+   r4   r6   r   r=   r8   r?   rA   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   r+        r+  c                      .     
 	 W d    d S 1 sw   Y  d S NFr   r   r+  r   r   r     s   "z1TraceTestCase.test_if_false_in_with.<locals>.func)r)   r+   r{   r*   r|   r~   r4   r+   rS   rU   rW   r-   r   r   r   r7  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 r6  )rY   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>.Ar7   r   r&   r5   N)r   r   r   rH   r   r   r   r   r)    s    r)  r   )r)  r   r   r   r     r   z9TraceTestCase.test_implicit_return_in_class.<locals>.func)r)   r+   )r&   r*   r+   r4   r6   rD   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   rX   )exr   r   r   r     s   z+TraceTestCase.test_try_in_try.<locals>.funcrC   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   )rH   pr#  r   r   r   r     s   z/TraceTestCase.test_if_in_if_in_if.<locals>.funcr   )r   r&   r&   r   r   r   r   r   test_if_in_if_in_if  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                   @   r2  )z-TraceTestCase.test_early_exit_with.<locals>.Cc                 S   r   r   r   r   r   r   r   r     r(   z7TraceTestCase.test_early_exit_with.<locals>.C.__enter__c                  W   r   r   r   r   r   r   r   r     r(   z6TraceTestCase.test_early_exit_with.<locals>.C.__exit__Nr3  r   r   r   r   r+    r4  r+  c               	      s:   dD ]}    	 W d     d S 1 sw   Y  qd S )Nr&   r5   r   r  r7  r   r   
func_break  s   z6TraceTestCase.test_early_exit_with.<locals>.func_breakc                      r5  r   r   r   r7  r   r   func_return  s   $z7TraceTestCase.test_early_exit_with.<locals>.func_return)r)   r+   r4   r8  r|   r~   r6   r4   rS   rU   rW   r=   rP   )r)   r+   )r   r*   )r,   )rD  r.   r4   r+   r   r   r   r-   r   )r   rB  rC  r   r7  r   test_early_exit_with  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%   r.  r1   r   r   r   foo<  s   z;TraceTestCase.test_flow_converges_on_same_line.<locals>.fooc                     s   t dD ]}  |  qd S r   rF   r  rG  r   r   r   D     
z<TraceTestCase.test_flow_converges_on_same_line.<locals>.func)r)   r+   r4   r   r*   ir,   rU   rW   r+   r4   rJ  rK  )ry   r,   rz   )r{   r]   r|   r   rU   rW   r+   r-   r   r   r   rH  r    test_flow_converges_on_same_line:  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&   donerF  )r#   errorr   r   r   r   `  s   

zCTraceTestCase.test_no_tracing_of_named_except_cleanup.<locals>.funcr0  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,  r1  r9  r;  r<  r>  r@  rE  rL  rO  r   r   r   r   r   G  sp    

		L$%.$r   c                       ,   e Zd ZdZ fddZedd Z  ZS )SkipLineEventsTraceTestCasez8Repeat the trace tests, but with per-line events skippedc                    s"   dd |D }t  ||| d S )Nc                 S      g | ]
}|d  dkr|qS r+   r   r   r   r   r   r   r   y  r   z>SkipLineEventsTraceTestCase.compare_events.<locals>.<listcomp>)superr   )r   r   r   r   Zskip_line_events	__class__r   r   r   x  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   r   rP  r   __classcell__r   r   rV  r   rR  u  s
    rR  c                       rQ  )TraceOpcodesTestCasez;Repeat the trace tests, but with per-opcodes events enabledc                    sF   dd |D }t |dkr| jt |t |dd t ||| d S )Nc                 S   rS  )r&   Zopcoder   rT  r   r   r   r     r   z7TraceOpcodesTestCase.compare_events.<locals>.<listcomp>r&   z)No 'opcode' events received by the tracer)msg)lenZ
assertLessrU  r   )r   r   r   r   Zskip_opcode_eventsrV  r   r   r     s   z#TraceOpcodesTestCase.compare_eventsc                   C   rX  )NT)r   r   r   r   r   r   r     rY  z TraceOpcodesTestCase.make_tracerrZ  r   r   rV  r   r\    s
    r\  c                   @   s\   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zd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 )zXA trace function that raises an exception in response to a
        specific trace event.N)raiseOnEventr/  r   r   r   r   r   r     s   
zRaisingTraceFuncTestCase.tracec                 C   s   | j dkrd}d| }dS dS )zThe function to trace; raises an exception if that's the case
        we're testing, so that the 'exception' trace event fires.r]   r   r&   N)rb  )r   r#   rM   r   r   r   r     s   
zRaisingTraceFuncTestCase.fc              	   C   sx   || _ 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 )zTTests that an exception raised in response to the given event is
        handled OK.r&   zexception not raised!zrecursion counter not resetN)
rb  rG   r_   getrecursionlimitr`   r   r   r/  r   rg   )r   r   rp   r   r   r   run_test_for_event  s   z+RaisingTraceFuncTestCase.run_test_for_eventc                 C      |  d d S )Nr*   rd  r   r   r   r   	test_call  r   z"RaisingTraceFuncTestCase.test_callc                 C   re  Nr,   rf  r   r   r   r   	test_line  r   z"RaisingTraceFuncTestCase.test_linec                 C   re  )Nr.   rf  r   r   r   r   test_return  r   z$RaisingTraceFuncTestCase.test_returnc                 C   re  Nr]   rf  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 )Nr9   )rG   printr  r   r   r   r     rI  z4RaisingTraceFuncTestCase.test_trash_stack.<locals>.fc                    s&   |dkr| j  jjd krtdS )Nr,   r5   zi am crashing)r   r   r   rg   )r   whyextrar   gr   r   rq    s
   z4RaisingTraceFuncTestCase.test_trash_stack.<locals>.gr   zexception not propagated)r_   r`   rg   r   Zcollectr   )r   r   r   rp  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_attrr1   r   r   r   r     s   
z<RaisingTraceFuncTestCase.test_exception_arguments.<locals>.fc                    s"   |dkr|\}}} |t  S rk  )ZassertIsInstancerY   )r   r   r   typer]   r   rq  r   r   r   rq    s   
z<RaisingTraceFuncTestCase.test_exception_arguments.<locals>.g)r_   r   r`   AttributeError)r   r   existingr   rt  r   test_exception_arguments  s   

z1RaisingTraceFuncTestCase.test_exception_argumentsN)r   r   r   r   r   r   rd  rg  ri  rj  rl  rr  rw  r   r   r   r   r_    s    	r_  c                   @   s&   e Zd ZdZ		d	ddZdd ZdS )

JumpTracerz>Defines a trace function that jumps from one place to another.r,   Fc                 C   s6   |j | _|| _|| _|| _|rd n| jj| _d| _d S r6  )r   codejumpFromjumpTor   r   	firstLinerM  )r   functionrz  r{  r   	decoratedr   r   r   r     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)rM  r|  f_codery  r   r   rz  rb   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   rx    s    
	rx  c              
   C   sJ   z|  d W d S  ty$ } z|  dt|v  W Y d }~d S d }~ww )Nr5   Zinteger)r   r/  r   r
   r   r   r   r   no_jump_to_non_integers  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_   ra   rb   r   r/  r   AssertionError)Zprevious_framer   r   r   r   no_jump_without_trace_function  s   

r  c                   @   sB  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[dS )JumpTestCasec                 C   s    |  tjt  td  d S r   r`  r   r   r   r   r   .  s   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_output2  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   )rx  r_   r`   r   assertRaisesRegexr  
r   r   rz  r{  r  rN  r   r~  r   r
   r   r   r   r   8  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   )	rx  r_   r`   r   asyncior   r  Zset_event_loop_policyr  r  r   r   r   run_async_testE  s   

zJumpTestCase.run_async_testc                        fdd}|S )zqDecorator that creates a test that makes a jump
        from one place to another in the following code.
        c                    "   t   fdd}|S )Nc              	         | j  dd d S NT)rN  r   r~  )r   r   rN  r   r  r   rz  r{  r   r   testX     
z7JumpTestCase.jump_test.<locals>.decorator.<locals>.testr   r   r  rN  r   r  rz  r{  r   r   	decoratorW     z)JumpTestCase.jump_test.<locals>.decoratorNr   rz  r{  r  rN  r   r  r   r  r   	jump_testS     zJumpTestCase.jump_testc                    r  )z~Decorator that creates a test that makes a jump
        from one place to another in the following asynchronous code.
        c                    r  )Nc              	      r  r  )r  r   r  r   r   r  d  r  z=JumpTestCase.async_jump_test.<locals>.decorator.<locals>.testr   r  r  r  r   r  c  r  z/JumpTestCase.async_jump_test.<locals>.decoratorNr   r  r   r  r   async_jump_test_  r  zJumpTestCase.async_jump_testr&   r7   c                 C   "   |  d |  d |  d d S Nr&   r5   r7   r   r
   r   r   r   test_jump_simple_forwardsm     

z&JumpTestCase.test_jump_simple_forwardsr5   )r&   r&   r5   c                 C      |  d |  d d S rE   r  r  r   r   r   test_jump_simple_backwardss     
z'JumpTestCase.test_jump_simple_backwardsr9   c                 C   s6   dD ]}|  d dD ]}|  d qq|  d d S )NrA  r5   r7   r>   r9   r  r
   rp   r  r   r   r   test_jump_out_of_block_forwardsx  s   
z,JumpTestCase.test_jump_out_of_block_forwardsrK   )r&   r7   r9   r&   r7   r9   rK   r@   c                 C   sJ   |  d dD ]}|  d dD ]}|  d q|  d q|  d d S )Nr&   r   r7   )r5   r9   rK   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&   r5   r7   r>   r9   r$   r   r
   rp   r   r   r   )test_jump_out_of_async_for_block_forwards  s   
z6JumpTestCase.test_jump_out_of_async_for_block_forwards)r5   r>   r5   r>   r9   rK   c                    sR   dD ]#}|  d tdg2 z3 d H W }|  d |  d q6 |  d qd S )Nr   r5   r&   r>   r9   rK   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&   r7   r  r  r   r   r   test_jump_to_codeless_line  s   
z'JumpTestCase.test_jump_to_codeless_line)r&   r5   r7   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 )Nr5   r>   rK   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 )Nr5   r&   r   rK   r@   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 )	Nr5   r&   r   rK   r   ru   r  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 )Nr5   r>   r9   r   ru   r  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&   Tr7   r>   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&   r5   r>   r  r  r   r   r   #test_jump_forwards_into_while_block  s   

z0JumpTestCase.test_jump_forwards_into_while_block)r7   r7   r7   r9   c                 C   s4   d}|dkr|  d |d7 }|dks|  d d S )Nr&   r5   r7   r9   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_block     z1JumpTestCase.test_jump_forwards_out_of_with_blockc              	      X   t | d4 I d H  | d W d   I d H  q%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&   r5   r&   r5   r7   rV   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_block      
"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_block  
   
.z8JumpTestCase.test_jump_backwards_out_of_async_with_blockc              	   C   4   z|  d W |  d n|  d w |  d d S Nr5   r>   r9   r  r  r   r   r   +test_jump_forwards_out_of_try_finally_block     z8JumpTestCase.test_jump_forwards_out_of_try_finally_block)r&   r&   r7   r9   c              	   C   2   |  d z|  d W |  d d S |  d w Nr&   r7   r9   r  r  r   r   r   ,test_jump_backwards_out_of_try_finally_block     
z9JumpTestCase.test_jump_backwards_out_of_try_finally_blockc                 C   0   z|  d W n	   |  d  |  d d S Nr5   r>   rK   r  r  r   r   r   *test_jump_forwards_out_of_try_except_block     
z7JumpTestCase.test_jump_forwards_out_of_try_except_block)r&   r&   r7   c                 C   .   |  d z|  d W d S    |  d  r  r  r  r   r   r   +test_jump_backwards_out_of_try_except_block%     

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>   r9   r@   r   r.  r   FloatingPointErrorr  r   r   r   test_jump_between_except_blocks.  s   
z,JumpTestCase.test_jump_between_except_blocks)r>   rK   r@   c                 C   sB   zdd  W n   |  d |  d |  d Y |  d d S )Nr&   r   r>   r9   rK   r@   r  r  r   r   r   test_jump_within_except_block9  s   

z*JumpTestCase.test_jump_within_except_block)r&   r>   r9   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&   r5   r7   r>   r9   r  r  r   r   r   test_jump_across_withC     
"z"JumpTestCase.test_jump_across_withc              	         |  d t| d4 I d H  |  d W d   I d H  q*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_withK     
(.z(JumpTestCase.test_jump_across_async_with)r&   r7   r9   rK   c              	   C   s`   |  d dD ]!}t| d |  d W d    n1 sw   Y  |  d q|  d d S Nr&   r   r7   r>   r9   rK   r  r  r   r   r   ,test_jump_out_of_with_block_within_for_blockS  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  q.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&   r5   r7   r9   rV   rK   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&   r5   r7   r>   r9   rK   r  r  r   r   r   -test_jump_out_of_with_block_within_with_blocke  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  q01 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_blockn  s   
(z@JumpTestCase.test_jump_out_of_async_with_block_within_with_block)r5   r>   rK   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 Nr5   r>   r9   rK   r@   r  r  r   r   r   0test_jump_out_of_with_block_within_finally_blockw  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  q,1 I d H s'w   Y  |  d n*t| d4 I d H  |  d W d   I d H  qV1 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&   r7   r9   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   r7   rA  r9   r   ru   r  r  r  )r
   rp   r  kr   r   r   &test_jump_out_of_complex_nested_blocks  s   


z3JumpTestCase.test_jump_out_of_complex_nested_blocks)r&   r5   r9   c                 C   sL   |  d t| d}|  d W d    n1 sw   Y  |  d d S Nr&   r5   r>   r9   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  q*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&   rK   r   r   c              	   C   s\   |  d z|  d | sW |  d d S |  d W |  d n|  d w |  d d S )Nr&   r7   r   rK   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&   r7   r   ru   r  r  c              	   C   sr   |  d 	 |  d z|  d | sW |  d q2|  d W |  d n|  d w |  d 	 |  d d S )	Nr&   Tr7   r9   ru   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   D   |  d | sdD ]}|  d q	|  d |  d |  d d S Nr&   r  r>   rK   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&   r7   r>   rK   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  rE   r  r  r   r   r   test_no_jump_too_far_forwards  r  z*JumpTestCase.test_no_jump_too_far_forwardsrV   beforec                 C   r  rE   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  Nr5   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   r/  r  r   r   r   test_no_jump_to_except_2  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   r/  rg   r  r   r   r   test_no_jump_to_except_4  s   
z%JumpTestCase.test_no_jump_to_except_4Zintoc                 C   s"   |  d dD ]}|  d qd S )Nr&   rA  r7   r  r  r   r   r   $test_no_jump_forwards_into_for_block	  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_block  s   
z7JumpTestCase.test_no_jump_forwards_into_async_for_blockc                 C   s"   dD ]}|  d q|  d d S )NrA  r5   r7   r  r  r   r   r   %test_no_jump_backwards_into_for_block  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_block"  r  z2JumpTestCase.test_no_jump_forwards_into_with_blockc              	      r  r  r  r  r   r   r   +test_no_jump_forwards_into_async_with_block(  r  z8JumpTestCase.test_no_jump_forwards_into_async_with_block)r&   r5   r   c                 C   r  r  r  r  r   r   r   &test_no_jump_backwards_into_with_block.  r  z3JumpTestCase.test_no_jump_backwards_into_with_blockc              	      r  r  r  r  r   r   r   ,test_no_jump_backwards_into_async_with_block4  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_blockB  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_blockJ  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_blockS  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_blockh  r  z)JumpTestCase.test_jump_into_finally_block)r5   rK   r@   c              	   C   sR   z|  d |  d W |  d |  d n|  d |  d w |  d d S )Nr5   r7   r9   rK   r@   r  r  r   r   r   +test_jump_into_finally_block_from_try_blockp  s   


z8JumpTestCase.test_jump_into_finally_block_from_try_block)r&   r7   r&   r7   r9   c              	   C   r  r  r  r  r   r   r   test_jump_out_of_finally_blockz  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   rY   r  r   r   r   (test_no_jump_into_qualified_except_block  s   
z5JumpTestCase.test_no_jump_into_qualified_except_block)r5   r9   rK   c                 C   sD   z|  d |  d W n   |  d |  d  |  d d S Nr5   r7   r9   rK   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   r.  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&   r7   rK   zout of an 'except'c                 C   sD   |  d z|  d dd  W d S    |  d |  d Y d S Nr&   r7   r   rK   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&   r5   r9   rV   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  )Nr5   r>   r9   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 )Nr5   ZSpamT)r   r  r   r   r   r   test_no_jump_to_non_integers  ra  z)JumpTestCase.test_no_jump_to_non_integersc                 C   rR   r   )r  r   r   r   r   #test_no_jump_without_trace_function  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   r5   i  r   )r   r   )r   r  r   r   r   r   test_large_function  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   ry  r   r   fake_function  s    r,  r>   r&   r
   )r5   r7   r5   r7   r>   )compilerx  r_   r`   r   r   r  )r   r,  r   r   r   r+  r   test_jump_to_firstlineno  s   

z%JumpTestCase.test_jump_to_firstlinenor*   z5can't jump from the 'call' trace event of a new frame)r   rN  c                    s*     d  fdd}|    d d S )Nr&   c                      s     d d S )Nr7   r  r   r  r   r   nested  r   z3JumpTestCase.test_no_jump_from_call.<locals>.nestedr9   r  )r
   r/  r   r  r   test_no_jump_from_call  s   
z#JumpTestCase.test_no_jump_from_callr.   z'can only jump from a 'line' trace eventc                 C   re  r%   r  r  r   r   r   test_no_jump_from_return_event  s   
z+JumpTestCase.test_no_jump_from_return_eventr]   c                 C   s   |  d dd  d S r0   r  r  r   r   r   !test_no_jump_from_exception_event$  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 )Nr5   r7   r  r   r  r   r   gen,  s   

z.JumpTestCase.test_jump_from_yield.<locals>.genr9   )r   r   )r
   r3  r   r  r   test_jump_from_yield*  s   
z!JumpTestCase.test_jump_from_yield)Nr,   Frh  )\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  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  r4  r   r   r   r   r  -  sZ   


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

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

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

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

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



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





r  __main__).r  r   Zunittestr_   r   r   	functoolsr   r  r   r   r$   r'   r   r2   r;   r<   rB   rI   rN   rQ   r*   rZ   r[   re   rf   rh   ri   rk   rq   rr   rt   rw   r   ZTestCaser   rR  Zcpython_onlyr\  r_  rx  r  r  r  r   mainr   r   r   r   <module>   s   



	

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

      4`&      
