B
    u9aפ                 @   s  d dl Zd dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	 d dl
mZmZ d dlZG dd deZG dd deZG dd	 d	eZG d
d deZd Zdd Zdd ZG dd dejZG dd deZG dd dZd4ddZe	dd ZeddfddZdZed Zdd  Z d!d" Z!d#d$ Z"d%d& Z#G d'd( d(ej$Z%G d)d* d*e%Z&G d+d, d,e%Z'G d-d. d.e%Z(G d/d0 d0e%Z)d1d2 Z*e+d3kre*  dS )5    N)contextmanager)islicerepeatc               @   s   e Zd ZdS )BdbExceptionN)__name__
__module____qualname__ r	   r	   /usr/lib/python3.7/test_bdb.pyr   >   s    r   c               @   s   e Zd ZdS )BdbErrorN)r   r   r   r	   r	   r	   r
   r   ?   s    r   c               @   s   e Zd ZdS )BdbSyntaxErrorN)r   r   r   r	   r	   r	   r
   r   @   s    r   c               @   s   e Zd ZdS )BdbNotExpectedErrorN)r   r   r   r	   r	   r	   r
   r   A   s    r   c               C   s   dt j_i t j_d gt j_d S )N   )_bdb
BreakpointnextZbplist
bpbynumberr	   r	   r	   r
   reset_BreakpointI   s    r   c              C   s   dd t jjD } | sdS d}x~| D ]v}|s4d}d}|jr>dnd}|jrLd	nd
}|d|j|||j|jtj	
|j|jf 7 }|jr|d|jf 7 }|d7 }q$W |S )Nc             S   s   g | ]}|r|qS r	   r	   ).0bpr	   r	   r
   
<listcomp>O   s    z$info_breakpoints.<locals>.<listcomp> Fz!BpNum Temp Enb Hits Ignore Where
Tzyes zno  Zyeszno z%-5d %s %s %-4d %-6d at %s:%dz
	stop only if %s
)r   r   r   	temporaryenabledZnumberhitsignoreospathbasenamefilelinecond)bp_listZheader_addedr   infoZdispZenabr	   r	   r
   info_breakpointsN   s"    
r%   c                   sf   e Zd Z fddZd fdd	Z fddZd	d
 Zdd Zdd Zdd Z	dd Z
dd Z  ZS )Bdbc                s   d | _ t |||S )N)	currentbpsupertrace_dispatch)selfframeeventarg)	__class__r	   r
   r)   f   s    zBdb.trace_dispatchFNc                s   t |trT|tkrt }nt|d d }|j}t||}|j}	|	j	}|	j
}|	j}t j|||||d}
t |
tr|t|
|
S )N)r   r"   funcname)
isinstancestr__file__globals	importlibimport_module__dict__eval__code__co_filenameco_firstlinenoco_namer(   	set_breakr   )r*   filenamelinenor   r"   r0   globals_modulefunccoderes)r.   r	   r
   r=   j   s    



zBdb.set_breakc                s4   t  ||\| _| _| j| j d | _| j| jfS )Nr   )r(   	get_stackstackindexr+   )r*   ft)r.   r	   r
   rE   ~   s    zBdb.get_stackc             C   s   |  |}| jd7  _d S )Nr   )get_bpbynumberr   )r*   bpnumr   r	   r	   r
   
set_ignore   s    
zBdb.set_ignorec             C   s   |  |}d|_d S )NT)rJ   r   )r*   rK   r   r	   r	   r
   
set_enable   s    
zBdb.set_enablec             C   s   |  |}d|_d S )NF)rJ   r   )r*   rK   r   r	   r	   r
   set_disable   s    
zBdb.set_disablec             C   s   |  ||}|rt|d S )N)Zclear_breakr   )r*   fnamer?   errr	   r	   r
   	set_clear   s    zBdb.set_clearc             C   s2   | j std|  j d8  _ | j| j  d | _d S )NzOldest framer   r   )rG   r   rF   r+   )r*   r	   r	   r
   set_up   s    z
Bdb.set_upc             C   s@   | j d t| jkrtd|  j d7  _ | j| j  d | _d S )Nr   zNewest framer   )rG   lenrF   r   r+   )r*   r	   r	   r
   set_down   s    zBdb.set_down)FNN)r   r   r   r)   r=   rE   rL   rM   rN   rQ   rR   rT   __classcell__r	   r	   )r.   r
   r&   c   s    r&   c                   s   e Zd Zd+ fdd	Zdd Z f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%d&Zd'd( Zd)d* Z  ZS )-TracerNFc                s<   t  j|d || _|| _|d k	r*d| nd | _|   d S )N)skipzDry-run results for %s:)r(   __init__
expect_setdry_runheader	init_test)r*   rY   rW   rZ   	test_case)r.   r	   r
   rX      s
    zTracer.__init__c             C   sB   d | _ d| _d | _tt| jdd d| _tt| jdd d| _d S )Nr      r   )
cur_exceptexpect_set_nobreakpoint_hitslistr   rY   expected_listset_list)r*   r	   r	   r
   r\      s
    zTracer.init_testc          
      sn   | j d k	r| j |dkrZyt |||}|S  tk
rV } z|| _ | jS d }~X Y qjX nt |||S d S )N	exception)r_   r(   r)   r   )r*   r+   r,   r-   rD   e)r.   r	   r
   r)      s    
zTracer.trace_dispatchc             C   s(   |  |sd S | d|| |   d S )Ncall)Z	stop_hereprocess_eventnext_set_method)r*   r+   Zargument_listr	   r	   r
   	user_call   s    
zTracer.user_callc             C   s^   |  d| | jrD| jrDt d}x|dD ]}td|  q0W |   d | _|   d S )Nr!   r   z  )	rh   rZ   ra   r%   stripsplitprintdelete_temporariesri   )r*   r+   r$   r!   r	   r	   r
   	user_line   s    zTracer.user_linec             C   s   |  d|| |   d S )Nreturn)rh   ri   )r*   r+   Zreturn_valuer	   r	   r
   user_return   s    zTracer.user_returnc             C   s   || _ | d| |   d S )Nre   )exc_inforh   ri   )r*   r+   rr   r	   r	   r
   user_exception   s    zTracer.user_exceptionc             C   s   | j g}||f| _d S )N)r'   ra   )r*   r-   r#   r	   r	   r
   do_clear   s    zTracer.do_clearc             C   s(   | j r$x| j d D ]}| | qW d S )Nr   )ra   Zclear_bpbynumber)r*   nr	   r	   r
   rn      s    zTracer.delete_temporariesc             C   sV   |  j d7  _ y| jd| _W n" tk
rB   td| j  Y nX | jd| _d S )Nr   r   z-expect_set list exhausted, cannot pop item %d)r`   rc   popexpect
IndexErrorr   rd   	set_tuple)r*   r	   r	   r
   pop_next   s    zTracer.pop_nextc                s  d }|dkrj d }|| jd k	rDjsDjg}|g f_|_  jrhj d S j	r
j	d |d   |dkrd ntj	dkr~|dkrFj	d \ }t  }jsdj  
|jd d	 
 fd
d|D fddjd D d 
t|jd d n8|dkr~tj d j	d s~djj f  d S )Nre   r^   r   zWrong event type)rg   rp      r!   z(No breakpoints hit at expect_set item %dzBreakpoint numbers do not matchc                s   g | ]} | qS r	   r	   )r   ru   )bpsr	   r
   r     s    z(Tracer.process_event.<locals>.<listcomp>c                s   g | ]}  |jqS r	   )rJ   r   )r   ru   )r*   r	   r
   r      s   zWrong breakpoint hit countr   zWrong temporary breakpointsz/Wrong exception at expect_set item %d, got '%s')rr   rE   r'   ra   r,   rz   rZ   print_stater[   rw   check_equalcheck_lno_namecheck_expect_max_sizerS   sortedkeysraise_not_expectedr`   r1   )r*   r,   r+   argstbr#   ZtemporariesZbpnumsr	   )r|   r*   r
   rh      sL    





zTracer.process_eventc             C   s&   ||krd S |  d|| j|f  d S )Nz"%s at expect_set item %d, got '%s')r   r`   )r*   Zexpectedresultmsgr	   r	   r
   r~   ,  s    zTracer.check_equalc             C   sT   t | j}|dkr.|  }| | jd |d |dkrP| | jd | jjjd d S )Nr   zWrong line numberr^   zWrong function name)rS   rw   lno_abs2relr~   r+   f_coder<   )r*   sr?   r	   r	   r
   r   2  s    
zTracer.check_lno_namec             C   s&   t | j|kr"td| j| jf d S )Nz'Invalid size of the %s expect tuple: %s)rS   rw   r   r,   )r*   sizer	   r	   r
   r   <  s    zTracer.check_expect_max_sizec             C   s<   |  | jjj}| jj}||  tkr8|| jjj d S |S )Nr   )canonicr+   r   r:   f_linenor3   r;   )r*   rO   r?   r	   r	   r
   r   A  s    zTracer.lno_abs2relc             C   s.   |r*|  ||  tkr*| jjj| d S |S )Nr   )r   r3   r+   r   r;   )r*   rO   r?   r	   r	   r
   lno_rel2absG  s    *zTracer.lno_rel2absc             C   s   |   }| jjj}d| j||f }| jrd}x:| jd D ],}|dkrL|d7 }|d|| |jf 7 }q8W |d7 }d| d t| jd  d	 }|d| 7 }n| jd
kr|d| j	d j
 7 }|d7 }|dt| j d S )Nz('%s', %d, '%s'{r   z, z%s: %s}(r   )re   z),     ,)r   r+   r   r<   r,   ra   rJ   r   r2   rr   r   ljustry   )r*   r?   r<   stater|   ru   r	   r	   r
   	get_stateL  s     

zTracer.get_statec             C   s:   |d k	r | j dkr t  t| td| j |  f  d S )Nr   z%d: %s)r`   rm   r   )r*   r[   r	   r	   r
   r}   ^  s    zTracer.print_statec             C   s6   |d7 }|dt | j 7 }|d|   7 }t|d S )Nr   z  Expected: %s
z  Got:      )r2   rw   r   r   )r*   r   r	   r	   r
   r   d  s    zTracer.raise_not_expectedc             C   sZ  | j d }t| j dkr"| j d nd }t| d| }|dkrF|  d S |dkr\|| j d S |dkrd }|r| | jjj|d }|| j| d S |r|dks|d	krH|d
kr|^}}}| ||}||g}|| ||  n"|dkr||  n|d	kr|  d | _| 	  | j
r$|   n| jr4|   | d |   ntd| j  d S )Nr   r^   r   Zset_)stepcontinuequit)r   rp   until)breakclearr   enabledisable)updown)r   r   )r   r   r   r{   z"%s" is an invalid set_tuple)ry   rS   getattrr+   r   r   r:   extendr,   rz   rZ   r}   rw   r   r   ri   r   )r*   set_typer   Z
set_methodr?   rO   Zremainr	   r	   r
   ri   j  sL    











zTracer.next_set_method)NFN)N)r   r   r   rX   r\   r)   rj   ro   rq   rs   rt   rn   rz   rh   r~   r   r   r   r   r   r}   r   ri   rU   r	   r	   )r.   r
   rV      s(   	
2

rV   c               @   s(   e Zd ZdddZdd Zd	ddZdS )
	TracerRunNc             C   s2   || _ |j| _t|j|| j| d| _d | _d S )N)rW   rZ   r]   )r]   rZ   rV   rY   idtracer_original_tracer)r*   r]   rW   r	   r	   r
   rX     s
    zTracerRun.__init__c             C   s   t   t | _| jS )N)r   sysgettracer   r   )r*   r	   r	   r
   	__enter__  s    
zTracerRun.__enter__c             C   s   t   t| j d}| jjr6|d7 }|d| jj 7 }|d k	rtt|rt	|t
r|jr|jd }|rr|d| 7 }| jrt| dS | j| n |r| jrt| n| j| d S )Nr   z+All paired tuples have not been processed, zthe last one was number %dr   r   T)r   r   settracer   r   rd   r`   
issubclassr   r1   BaseExceptionr   rZ   rm   r]   fail)r*   Ztype_value	tracebackZ	not_emptyZerr_msgr	   r	   r
   __exit__  s(    

zTracerRun.__exit__)N)NNN)r   r   r   rX   r   r   r	   r	   r	   r
   r     s   
r   c          
   C   s   dd }ddg}| | t }d|_dd |_t|tdt||_t| ( t	||d	}|
t W d Q R X W d Q R X d S )
Nc             s   s@   y&x t | }t |}|V  |V  qW W n tk
r:   d S X d S )N)r   StopIteration)abxyr	   r	   r
   gen  s    zrun_test.<locals>.gen)r   )r   Tc               S   s   d S )Nr	   r	   r	   r	   r
   <lambda>      zrun_test.<locals>.<lambda>r	   )rW   )r   BaseTestCaserZ   r   rb   r   iterrY   create_modulesr   runcalltfunc_import)modulesrd   rW   r   sltestr   r	   r	   r
   run_test  s    3


r   c             c   s   t j  tjt  z\xH| D ]@}|d }t|d}|	t
| |  W d Q R X t| q$W t  d V  W d x| D ]}t j| qW tj  X W d Q R X d S )Nz.pyw)r   supportZtemp_cwdr   r   appendr   getcwdopenwritetextwrapdedent	linecache
checkcacher5   invalidate_cachesZforgetrv   )r   mrO   rH   r	   r	   r
   r     s    


r   Fc             C   s   d|d ||| ffS )Nr   r	   )r0   rO   r   r"   r	   r	   r
   break_in_func%  s    r   test_module_for_bdbz.pyc              C   s   dd l } |   d S )Nr   )r   main)r   r	   r	   r
   r   *  s    r   c              C   s    d} t   t  d} d} d} d S )Nr^            )tfunc_firsttfunc_second)lnor	   r	   r
   
tfunc_main.  s    r   c              C   s   d} d} d} d S )Nr^   r{      r	   )r   r	   r	   r
   r   6  s    r   c              C   s   d} d S )Nr^   r	   )r   r	   r	   r
   r   ;  s    r   c               @   s   e Zd ZeZdddZdS )r   Nc             C   s   |  |d d S )N)ZfailureException)r*   r   r	   r	   r
   r   C  s    zBaseTestCase.fail)N)r   r   r   rZ   r   r	   r	   r	   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d Zdd Zdd Zdd ZdS )StateTestCasec          	   C   s8   ddddddddg| _ t| }|t W d Q R X d S )N)r!   r^   r   )r   )r!   r{   r   )rg   r   r   )r!   r^   r   )r   )rY   r   r   r   )r*   r   r	   r	   r
   	test_stepK  s    

zStateTestCase.test_stepc             C   s   xzdD ]r}| j |d\ ddddddtdffd	d
dddddig ff|fddg| _t| }|t W d Q R X W d Q R X qW d S )N)r   r   )r   )r!   r^   r   )r   )r!   r{   r   )rg   r   r   r   r{   )Noner   r   )r   r!   r   r   )r!   r   r   )r   )subTestr3   rY   r   r   r   )r*   r   r   r	   r	   r
    test_step_next_on_last_statementU  s    


z.StateTestCase.test_step_next_on_last_statementc          
   C   s<   ddddddddddg
| _ t| }|t W d Q R X d S )	N)r!   r^   r   )r   )r!   r{   r   )r   )r!   r   r   )rg   r   r   )r!   r^   r   )r   )rY   r   r   r   )r*   r   r	   r	   r
   	test_nextc  s    

zStateTestCase.test_nextc          
   C   sP   d}t |i}t|2 ddddg| _t| }|t W d Q R X W d Q R X d S )Nz9
            def main():
                lno = 3
        )r!   r^   r   )r   )r!   r{   r   )r   )TEST_MODULEr   rY   r   r   r   )r*   rC   r   r   r	   r	   r
   test_next_over_importn  s    


z#StateTestCase.test_next_over_importc          	   C   s8   ddddddddg| _ t| }|t W d Q R X d S )N)r!   r^   r   )r   )r!   r{   r   )rg   r   r   )r   )r!   r^   r   )r   )rY   r   r   r   )r*   r   r	   r	   r
   test_next_on_plain_statement|  s    

z*StateTestCase.test_next_on_plain_statementc          
   C   s<   dddddddddd	g
| _ t| }|t W d Q R X d S )
N)r!   r^   r   )r   )r!   r{   r   )rg   r   r   )r   )r   r{   r   )r   )r!   r   r   )r   )rY   r   r   r   )r*   r   r	   r	   r
   test_next_in_caller_frame  s    

z'StateTestCase.test_next_in_caller_framec             C   s@   dddddddddddd	g| _ t| }|t W d Q R X d S )
N)r!   r^   r   )r   )r!   r{   r   )rg   r   r   )r!   r^   r   )rp   )rp   r   r   )r!   r   r   )r   )rY   r   r   r   )r*   r   r	   r	   r
   test_return  s    

zStateTestCase.test_returnc          
   C   s<   dddddddddd	g
| _ t| }|t W d Q R X d S )
N)r!   r^   r   )r   )r!   r{   r   )rg   r   r   )r   )r   r{   r   )rp   )rp   r   r   )r   )rY   r   r   r   )r*   r   r	   r	   r
   test_return_in_caller_frame  s    

z)StateTestCase.test_return_in_caller_framec          
   C   s<   ddddddddddg
| _ t| }|t W d Q R X d S )	N)r!   r^   r   )r   )r!   r{   r   )rg   r   r   )r!   r^   r   )r   )r   )r!   r   r   )r   )rY   r   r   r   )r*   r   r	   r	   r
   
test_until  s    

zStateTestCase.test_untilc          	   C   sL   dt ddddddddig ffdd	d
g| _t| }|t W d Q R X d S )N)r!   r^   r   r   )r   r^   r   )r   r!   r^   r   )r   )i'  )rp   r   r   )r   )r   rY   r   r   r   )r*   r   r	   r	   r
   test_until_with_too_large_count  s    

z-StateTestCase.test_until_with_too_large_countc          
   C   s<   dddddddddd	g
| _ t| }|t W d Q R X d S )
N)r!   r^   r   )r   )r!   r{   r   )rg   r   r   )r   )r   r{   r   )r   )r   )r!   r   r   )r   )rY   r   r   r   )r*   r   r	   r	   r
   test_until_in_caller_frame  s    

z(StateTestCase.test_until_in_caller_framec          
   C   s\   d}t |i}t|> ddddg| _dt f}t| |d}|t W d Q R X W d Q R X d S )Nz9
            def main():
                lno = 3
        )r!   r^   r   )r   )r!   r{   r   )r   z
importlib*)rW   )r   r   rY   r   r   r   )r*   rC   r   rW   r   r	   r	   r
   	test_skip  s    

zStateTestCase.test_skipc          	   C   s2   ddg| _ t| }| t|jt W d Q R X d S )N)r!   r^   r   )r   )rY   r   assertRaisesr   r   r   )r*   r   r	   r	   r
   	test_down  s    

zStateTestCase.test_downc          	   C   s8   ddddddddg| _ t| }|t W d Q R X d S )N)r!   r^   r   )r   )r!   r{   r   )rg   r   r   )r   )r   r{   r   )r   )rY   r   r   r   )r*   r   r	   r	   r
   test_up  s    

zStateTestCase.test_upN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r	   r	   r
   r   H  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 )BreakpointTestCasec          	   C   s2   ddg| _ t| }| t|jt W d Q R X d S )N)r!   r^   r   )r   )z/non/existent/module.pyr   )rY   r   r   r   r   r   )r*   r   r	   r	   r
   test_bp_on_non_existent_module  s    

z1BreakpointTestCase.test_bp_on_non_existent_modulec          
   C   sZ   d}t |i}t|< ddtdffg| _t| }| t|jt W d Q R X W d Q R X d S )Nz9
            def main():
                lno = 3
        )r!   r^   r   r   r   )	r   r   TEST_MODULE_FNAMErY   r   r   r   r   r   )r*   rC   r   r   r	   r	   r
   test_bp_after_last_statement  s    

z/BreakpointTestCase.test_bp_after_last_statementc             C   s   d}t |i}t|r dtdtddtdtddddddd	d	id	gffddddd
d	id
gffdg
| _t| }|t W d Q R X W d Q R X d S )Nz
            def func():
                lno = 3

            def main():
                for i in range(2):
                    func()
        )r!   r^   r   rB   T)r   r^   r   )r   r!   r{   r   r^   )r   )r   r   r   r   rY   r   r   r   )r*   rC   r   r   r	   r	   r
   test_temporary_bp  s    



z$BreakpointTestCase.test_temporary_bpc             C   s   d}t |i}t| dtdtdtdtddddddd	dd
d
ig ffddddddd	ddd
idgffddddd	dd
dig ffdg| _t| }|t W d Q R X W d Q R X d S )Nz
            def func():
                lno = 3

            def main():
                for i in range(3):
                    func()
        )r!   r^   r   rB   )r   r^   r   T)r   )r^   )r   r!   r{   r   )r   )r^   )r   r{   rB   )r   )r   r^   )r   )r   )r   )r   r   r   r   rY   r   r   r   )r*   rC   r   r   r	   r	   r
   test_disabled_temporary_bp  s"    


z-BreakpointTestCase.test_disabled_temporary_bpc          
   C   sn   d}t |i}t|P dtdtdddddd	dd
d	ig ffdg| _t| }|t W d Q R X W d Q R X d S )Nz
            def func(a):
                lno = 3

            def main():
                for i in range(3):
                    func(i)
        )r!   r^   r   rB   Fza == 2)r   r^   r   )r   r!   r{   r   )r   )r   r   r   r   rY   r   r   r   )r*   rC   r   r   r	   r	   r
   test_bp_condition9  s    

z$BreakpointTestCase.test_bp_conditionc          
   C   sn   d}t |i}t|P dtdtdddddd	dd
d
ig ffdg| _t| }|t W d Q R X W d Q R X d S )Nzk
            def func(a):
                lno = 3

            def main():
                func(0)
        )r!   r^   r   rB   Fz1 / 0)r   r^   r   )r   r!   r{   r   )r   )r   r   r   r   rY   r   r   r   )r*   rC   r   r   r	   r	   r
   )test_bp_exception_on_condition_evaluationM  s    

z<BreakpointTestCase.test_bp_exception_on_condition_evaluationc             C   sn   d}t |i}t|P dtdtdddddddd	d
ig ffdg| _t| }|t W d Q R X W d Q R X d S )Nz
            def func():
                lno = 3

            def main():
                for i in range(2):
                    func()
        )r!   r^   r   rB   )r   r^   r   )r   )r   )r   r!   r{   r   r^   )r   )r   r   r   r   rY   r   r   r   )r*   rC   r   r   r	   r	   r
   test_bp_ignore_count`  s    

z'BreakpointTestCase.test_bp_ignore_countc             C   s   d}t |i}t| dtdtdtdtdddddddd	dd
dig ffddddd	dd
d
ig ffddd	ddd
ig ffdg| _t| }|t W d Q R X W d Q R X d S )Nz
            def func():
                lno = 3

            def main():
                for i in range(3):
                    func()
        )r!   r^   r   rB   )r   r^   r   )r   )r   )r   )r   )r   r!   r{   r^   r   )r   )r   )r   r{   rB   )r   )r   r   r   r   rY   r   r   r   )r*   rC   r   r   r	   r	   r
    test_ignore_count_on_disabled_bpu  s     

z3BreakpointTestCase.test_ignore_count_on_disabled_bpc             C   s   d}t |i}t| ddtdffddtdffddtdffddddd	d
d
ig ffdddd	dd
ig ffdtdffddddd	ddig ffdg| _t| }|t W d Q R X W d Q R X d S )Nz
            def func():
                lno = 3
                lno = 4

            def main():
                for i in range(3):
                    func()
        )r!   r^   r   r   r{   )r   r^   r   r   )r   r!   rB   r   r   )r   r   rB   r^   )r   )r   r   r   rY   r   r   r   )r*   rC   r   r   r	   r	   r
   test_clear_two_bp_on_same_line  s    	

z1BreakpointTestCase.test_clear_two_bp_on_same_linec          	   C   s:   ddt dffg| _t| }| t|jt W d Q R X d S )N)r!   r^   r   r   r   )r3   rY   r   r   r   r   r   )r*   r   r	   r	   r
   test_clear_at_no_bp  s    
z&BreakpointTestCase.test_clear_at_no_bpN)r   r   r   r   r   r   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dS )RunTestCasec          	   C   sB   d}ddddg| _ t| }|tt|dd W d Q R X d S )Nz
            lno = 2
        )r!   r^   z<module>)r   )rp   r^   z<module>)r   z<string>exec)rY   r   runcompiler   r   )r*   rC   r   r	   r	   r
   test_run_step  s
    

zRunTestCase.test_run_stepc             C   sl   d}t |i}t|N ddddddddddg
| _d	d l}t| }|d
t t  W d Q R X W d Q R X d S )Nz9
            def main():
                lno = 3
        )r!   r   z<module>)r   )rg   r^   r   )r!   r{   r   )rp   r{   r   )rp   r   z<module>)r   r   ztest_module_for_bdb.main())r   r   rY   r   r   Zrunevalr4   locals)r*   rC   r   r   r   r	   r	   r
   test_runeval_step  s    


zRunTestCase.test_runeval_stepN)r   r   r   r   r   r	   r	   r	   r
   r     s   r   c               @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )IssuesTestCasec             C   sz   d}d}t |d|i}t|T dtddddd	d
dddig ffdddddg
| _t| }|t W d Q R X W d Q R X d S )Nz
            from test_module_for_bdb_2 import func
            def main():
                func()
                lno = 5
        z9
            def func():
                lno = 3
        Ztest_module_for_bdb_2)r!   r^   r   rB   ztest_module_for_bdb_2.py)r   r^   r   )r   r!   r{   r   )r   )rp   r{   rB   )r!   r   r   )r   )r   r   r   rY   r   r   r   )r*   Zcode_1Zcode_2r   r   r	   r	   r
   +test_step_at_return_with_no_trace_in_caller  s    	


z:IssuesTestCase.test_step_at_return_with_no_trace_in_callerc             C   s   d}t |i}xdD ]}| j|d t| dtdtdddd	dd
d
ig ff|fg| _|dkr~| jdddtfdddg n| jddg t| }|	t
 W d Q R X W d Q R X W d Q R X qW d S )Nz
            def test_gen():
                yield 0
                lno = 4
                return 123

            def main():
                it = test_gen()
                next(it)
                next(it)
                lno = 11
        )r   r   rp   )r   )r!   r^   r   test_gen)r   r^   r   )r   r!   r{   r   rp   re   
   r   )r   )rp   r  r   )r   )r!   r   r  )r   r   r   r   r   rY   r   r   r   r   r   )r*   rC   r   r   r   r	   r	   r
   #test_next_until_return_in_generator  s"    



z2IssuesTestCase.test_next_until_return_in_generatorc             C   s   d}t |i}t|h dtdtdddddddig ffd	d
d	dd	dd	dddtfdddg| _t| }|t W d Q R X W d Q R X d S )Nz
            def test_gen():
                yield 0
                lno = 4
                yield 1
                return 123

            def main():
                for i in test_gen():
                    lno = 10
                lno = 11
        )r!   r^   r   r  )r   r^   r   )r   r!   r{   r   )r   )r!   r   r  )r!   r   r  )r!   r   r  re   	   r   )r   )r!      r   )r   )	r   r   r   r   r   rY   r   r   r   )r*   rC   r   r   r	   r	   r
   'test_next_command_in_generator_for_loop  s    


z6IssuesTestCase.test_next_command_in_generator_for_loopc             C   s~   d}t |i}t|` dtdtdddddddig ffd	d
d	dddtfdddg| _t| }|t W d Q R X W d Q R X d S )Na4  
            def test_subgen():
                yield 0
                return 123

            def test_gen():
                x = yield from test_subgen()
                return 456

            def main():
                for i in test_gen():
                    lno = 12
                lno = 13
        )r!   r^   r   r  )r   r^   r   )r   r!   r   r   )r   )r!      r  re   r  r   )r   )r!      r   )r   )	r   r   r   r   r   rY   r   r   r   )r*   rC   r   r   r	   r	   r
   /test_next_command_in_generator_with_subiterator;  s    


z>IssuesTestCase.test_next_command_in_generator_with_subiteratorc             C   s   d}t |i}t|h dtdtdddddddig ffd	d
ddtfd	d
ddtfdddg| _t| }|t W d Q R X W d Q R X d S )Na4  
            def test_subgen():
                yield 0
                return 123

            def test_gen():
                x = yield from test_subgen()
                return 456

            def main():
                for i in test_gen():
                    lno = 12
                lno = 13
        )r!   r^   r   Ztest_subgen)r   r^   r   )r   r!   r{   r   )rp   re   r   r  r  r   )r   )r!   r
  r   )r   )	r   r   r   r   r   rY   r   r   r   )r*   rC   r   r   r	   r	   r
   1test_return_command_in_generator_with_subiteratorZ  s    


z@IssuesTestCase.test_return_command_in_generator_with_subiteratorN)r   r   r   r  r  r  r  r  r	   r	   r	   r
   r    s
   )r  c               C   s   t jtttt d S )N)r   r   Zrun_unittestr   r   r   r  r	   r	   r	   r
   	test_mainy  s
    r  __main__)N),Zbdbr   r   r   Zunittestr   r5   r   
contextlibr   	itertoolsr   r   Ztest.supportr   	Exceptionr   r   r   r   rZ   r   r%   r&   rV   r   r   r   r3   r   r   r   r   r   r   r   ZTestCaser   r   r   r   r  r  r   r	   r	   r	   r
   <module>3   sP   @ z.
J
 ( B" (
