
    ;eʮ                        d Z ddlZddlZddlZddlZddlZddlZddlZddl	m
Z
 ddlmZmZ ddlmZ ddlmZ ddlmZ  G d d	e          Z G d
 de          Z G d de          Z G d de          ZdZd Zd Z G d dej                  Z G d de          Z G d d          Zd/dZe
d             ZeddfdZ dZ!e!dz   Z"d Z#d Z$d  Z%d! Z& G d" d#ej'                  Z( G d$ d%e(          Z) G d& d'e(          Z* G d( d)e(          Z+ G d* d+e(          Z, G d, d-ej'                  Z-e.d.k    r ej/                     dS dS )0a   Test the bdb module.

    A test defines a list of tuples that may be seen as paired tuples, each
    pair being defined by 'expect_tuple, set_tuple' as follows:

        ([event, [lineno[, co_name[, eargs]]]]), (set_type, [sargs])

    * 'expect_tuple' describes the expected current state of the Bdb instance.
      It may be the empty tuple and no check is done in that case.
    * 'set_tuple' defines the set_*() method to be invoked when the Bdb
      instance reaches this state.

    Example of an 'expect_tuple, set_tuple' pair:

        ('line', 2, 'tfunc_main'), ('step', )

    Definitions of the members of the 'expect_tuple':
        event:
            Name of the trace event. The set methods that do not give back
            control to the tracer [1] do not trigger a tracer event and in
            that case the next 'event' may be 'None' by convention, its value
            is not checked.
            [1] Methods that trigger a trace event are set_step(), set_next(),
            set_return(), set_until() and set_continue().
        lineno:
            Line number. Line numbers are relative to the start of the
            function when tracing a function in the test_bdb module (i.e. this
            module).
        co_name:
            Name of the function being currently traced.
        eargs:
            A tuple:
            * On an 'exception' event the tuple holds a class object, the
              current exception must be an instance of this class.
            * On a 'line' event, the tuple holds a dictionary and a list. The
              dictionary maps each breakpoint number that has been hit on this
              line to its hits count. The list holds the list of breakpoint
              number temporaries that are being deleted.

    Definitions of the members of the 'set_tuple':
        set_type:
            The type of the set method to be invoked. This may
            be the type of one of the Bdb set methods: 'step', 'next',
            'until', 'return', 'continue', 'break', 'quit', or the type of one
            of the set methods added by test_bdb.Bdb: 'ignore', 'enable',
            'disable', 'clear', 'up', 'down'.
        sargs:
            The arguments of the set method if any, packed in a tuple.
    N)contextmanager)islicerepeat)import_helper)	os_helper)
patch_listc                       e Zd ZdS )BdbExceptionN)__name__
__module____qualname__     $/usr/lib/python3.11/test/test_bdb.pyr
   r
   A   s          r   r
   c                       e Zd ZdZdS )BdbErrorz!Error raised by the Bdb instance.Nr   r   r   __doc__r   r   r   r   r   B   s        EEEEr   r   c                       e Zd ZdZdS )BdbSyntaxErrorzSyntax error in the test case.Nr   r   r   r   r   r   C   s        $H$H$H$Hr   r   c                       e Zd ZdZdS )BdbNotExpectedErrorzUnexpected result.Nr   r   r   r   r   r   D   s        )A)A)A)Ar   r   c                  B    t           j                                         d S N)_bdb
BreakpointclearBreakpointsr   r   r   reset_Breakpointr   L   s    O$$&&&&&r   c                  F   d t           j        j        D             } | sdS d}| D ]|}|sd}d}|j        rdnd}|j        rdnd	}|d
|j        |||j        |j        t          j	        
                    |j                  |j        fz  z  }|j        r|d|j        z  }|dz  }}|S )Nc                     g | ]}||S r   r   ).0bps     r   
<listcomp>z$info_breakpoints.<locals>.<listcomp>P   s    >>>r2>r>>>r    Fz!BpNum Temp Enb Hits Ignore Where
Tzyes zno  yeszno z%-5d %s %s %-4d %-6d at %s:%dz
	stop only if 
)r   r   
bpbynumber	temporaryenablednumberhitsignoreospathbasenamefilelinecond)bp_listheader_addedr"   infodispenabs         r   info_breakpointsr8   O   s    >>T_7>>>G rL   	 7DL1vv6
-uu0YdBGRYW%%bg..99 	: 7 	7DRWW66DKr   c                   `     e Zd ZdZ fdZ	 	 d fd	Z fdZd Zd Zd	 Z	d
 Z
d Zd Z xZS )Bdbz$Extend Bdb to enhance test coverage.c                 X    d | _         t                                          |||          S r   )	currentbpsupertrace_dispatch)selfframeeventarg	__class__s       r   r>   zBdb.trace_dispatchg   s&    ww%%eUC888r   FNc                    t          |t                    ri|t          k    rt                      }n#t	          j        |d d                   }|j        }t          ||          }|j        }	|	j	        }|	j
        }|	j        }t                                          |||||          }
t          |
t                    rt          |
          |
S )N)r(   r2   funcname)
isinstancestr__file__globals	importlibimport_module__dict__eval__code__co_filenameco_firstlinenoco_namer=   	set_breakr   )r?   filenamelinenor(   r2   rF   globals_modulefunccoderesrC   s              r   rS   zBdb.set_breakk   s    h$$ 
	$8##"99"0#2#??!?(++D=D'H(F|Hgg&I&*X   ? ?c3 	 3--
r   c                     t                                          ||          \  | _        | _        | j        | j                 d         | _        | j        | j        fS Nr   )r=   	get_stackstackindexr@   )r?   ftrC   s      r   r]   zBdb.get_stack   sI    !&!2!21a!8!8
DJZ
+A.
z4:%%r   c                 P    |                      |          }|xj        dz  c_        dS )z8Increment the ignore count of Breakpoint number 'bpnum'.   N)get_bpbynumberr,   r?   bpnumr"   s      r   
set_ignorezBdb.set_ignore   s(      ''
		Q				r   c                 >    |                      |          }d|_        d S )NTrd   r)   re   s      r   
set_enablezBdb.set_enable   s       ''


r   c                 >    |                      |          }d|_        d S )NFri   re   s      r   set_disablezBdb.set_disable   s       ''


r   c                 T    |                      ||          }|rt          |          d S r   )clear_breakr   )r?   fnamerU   errs       r   	set_clearzBdb.set_clear   s5    uf-- 	 3--	  	 r   c                     | j         st          d          | xj         dz  c_         | j        | j                  d         | _        dS )zMove up in the frame stack.zOldest framerc   r   N)r_   r   r^   r@   r?   s    r   set_upz
Bdb.set_up   sB    z 	+>***

a

Z
+A.


r   c                     | j         dz   t          | j                  k    rt          d          | xj         dz  c_         | j        | j                  d         | _        dS )zMove down in the frame stack.rc   zNewest framer   N)r_   lenr^   r   r@   rs   s    r   set_downzBdb.set_down   sQ    :>S__,,>***

a

Z
+A.


r   )FNN)r   r   r   r   r>   rS   r]   rg   rj   rl   rq   rt   rw   __classcell__rC   s   @r   r:   r:   d   s        ..9 9 9 9 9 AE     (& & & & &
  
         
/ / // / / / / / /r   r:   c                        e Zd ZdZd fd	Zd Z fdZd Zd Zd	 Z	d
 Z
d Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Z xZS )Tracerz$A tracer for testing the bdb module.NFc                     t                                          |           || _        || _        |d|z  nd | _        |                                  d S )NskipzDry-run results for %s:)r=   __init__
expect_setdry_runheader	init_test)r?   r   r~   r   	test_caserC   s        r   r   zTracer.__init__   s_    d###$ , 19<<26 	r   c                     d | _         d| _        d | _        t          t	          | j        dd d                    | _        t          t	          | j        dd d                    | _        d S )Nr      rc   )
cur_exceptexpect_set_nobreakpoint_hitslistr   r   expected_listset_listrs   s    r   r   zTracer.init_test   s\    #!&!T1"E"EFFVDOQa@@AAr   c                    | j         | j         |dk    rK	 t                                          |||          }|S # t          $ r}|| _         | j        cY d }~S d }~ww xY wt                                          |||          S N	exception)r   r=   r>   r
   )r?   r@   rA   rB   rZ   erC   s         r   r>   zTracer.trace_dispatch   s    
 ?&/!K+gg,,UE3??
 + + +"#*******+ 77))%<<<s   $< 
AAAAc                     |                      |          sd S |                     d||           |                                  d S )Ncall)	stop_hereprocess_eventnext_set_method)r?   r@   argument_lists      r   	user_callzTracer.user_call   sM     ~~e$$ 	F65-888r   c                 B   |                      d|           | j        rR| j        rKt                                          d          }|                    d          D ]}t          d|z              |                                  d | _        |                                  d S )Nr1   r&   z  )	r   r   r   r8   stripsplitprintdelete_temporariesr   )r?   r@   r5   r1   s       r   	user_linezTracer.user_line   s    65)))< 	#D0 	##%%++D11D

4(( # #dTk""""!!!#r   c                 \    |                      d||           |                                  d S )Nreturn)r   r   )r?   r@   return_values      r   user_returnzTracer.user_return   s2    8UL999r   c                 h    || _         |                     d|           |                                  d S r   )exc_infor   r   )r?   r@   r   s      r   user_exceptionzTracer.user_exception   s7     ;...r   c                 (    | j         g}||f| _        d S r   )r<   r   )r?   rB   r3   s      r   do_clearzTracer.do_clear   s    >" '1r   c                 b    | j         r%| j         d         D ]}|                     |           d S d S Nrc   )r   clear_bpbynumber)r?   ns     r   r   zTracer.delete_temporaries   sO     	))!, ) )%%a((((	) 	)) )r   c                     | xj         dz  c_         	 | j                            d          | _        n%# t          $ r t          d| j         z            w xY w| j                            d          | _        d S )Nrc   r   z-expect_set list exhausted, cannot pop item %d)r   r   popexpect
IndexErrorr   r   	set_tuplers   s    r   pop_nextzTracer.pop_next   s    a	$,0033DKK 	$ 	$ 	$%?"#$ $ $	$ **1--s	   2 "Ac                 x    d }|dk    r j         d         }                     ||            j         j        s j        g}|g f _        | _                                           j        r                      j                   d S  j	        r6 
                     j	        d         |d                                             |dv r                     d           d S t           j	                  dk    r:|dk    r j	        d         \  }t                                                    } j        s                     d j        z              
                    | j        d         d	            
                    fd
|D              fd j        d         D             d            
                    t          |           j        d         d           d S |dk    rNt%           j         d          j	        d                   s*                     d j         j         fz             d S d S d S d S )Nr   r   r   zWrong event type)r   r      r1   z(No breakpoints hit at expect_set item %dzBreakpoint numbers do not matchc                      g | ]
}|         S r   r   )r!   r   bpss     r   r#   z(Tracer.process_event.<locals>.<listcomp>   s    !9!9!9Q#a&!9!9!9r   c                 D    g | ]}                     |          j        S r   )rd   r+   )r!   r   r?   s     r   r#   z(Tracer.process_event.<locals>.<listcomp>!  s:     6 6 6 ((++0 6 6 6r   zWrong breakpoint hit countrc   zWrong temporary breakpointsz/Wrong exception at expect_set item %d, got '%s')r   r]   r<   r   rA   r   r   print_stater   r   check_equalcheck_lno_namecheck_expect_max_sizerv   sortedkeysraise_not_expectedr   rG   )	r?   rA   r@   argstbr3   temporariesbpnumsr   s	   `       @r   r   zTracer.process_event   s    Kq!Bub!!! >%d.B%~&G$+R=D  
< 	T[)))F ; 	"T[^U4FGGG!!!&&&&&q)))))!!#';q> [

+++ ,++B*+, , ,   )=a)@57 7 7  !9!9!9!9&!9!9!96 6 6 6!1!46 6 602 2 2   !4!4d6J16M13 3 3 3 3 +%%!$-"2DKNCC =++I+T];<= = = = =' "!" &%= =r   c                 V    ||k    rd S |                      d|| j        |fz             d S )Nz"%s at expect_set item %d, got '%s')r   r   )r?   expectedresultmsgs       r   r   zTracer.check_equal-  sO    vF D!$d&8& A!B 	C 	C 	C 	C 	Cr   c                    t          | j                  }|dk    r6|                                 }|                     | j        d         |d           |dk    r3|                     | j        d         | j        j        j        d           dS dS )z+Check the line number and function co_name.rc   zWrong line numberr   zWrong function nameN)rv   r   lno_abs2relr   r@   f_coderR   )r?   srU   s      r   r   zTracer.check_lno_name3  s    q55%%''FT[^V5HIIIq55T[^TZ->-F0EG G G G G 5r   c                 t    t          | j                  |k    rt          d| j        d| j                  d S )NzInvalid size of the z expect tuple: )rv   r   r   rA   )r?   sizes     r   r   zTracer.check_expect_max_size=  sG    t{d"" ."&***dkk"; < < < #"r   c                     |                      | j        j        j                  }| j        j        }||                      t
                    k    r|| j        j        j        z
  dz   n|S r   )canonicr@   r   rP   f_linenorI   rQ   r?   ro   rU   s      r   r   zTracer.lno_abs2relB  s^    TZ.:;;$X.... $*+::Q>>4:	<r   c                     |rH|                      |          |                      t                    k    r| j        j        j        |z   dz
  n|S r   )r   rI   r@   r   rQ   r   s      r   lno_rel2abszTracer.lno_rel2absH  sO    <<..$,,x2H2HHH 
!069A==	r   c                    |                                  }| j        j        j        }d| j        ||fz  }| j        rsd}| j        d         D ]/}|dk    r|dz  }||d|                     |          j        z  }0|dz  }d|z   dz   t          | j        d                   z   d	z   }|d|z   z  }n#| j        d
k    r|d| j	        d         j
        z   z  }|dz  }|                    d          t          | j                  z   dz   S )Nz('%s', %d, '%s'{r   z, z: }(rc   )r   z),     ,)r   r@   r   rR   rA   r   rd   r+   rH   r   r   ljustr   )r?   rU   rR   stater   r   s         r   	get_statezTracer.get_stateM  s+   !!##*#+!TZ$AA 
	6C)!, C C#::4KC111d&9&9!&<&<&A&ABB3JC)d"S)=a)@%A%AACGCTCZEEZ;&&TDM!,555E{{2T^!4!44s::r   c                     |(| j         dk    rt                       t          |           t          d| j         |                                 fz             d S )Nrc   z%d: %s)r   r   r   )r?   r   s     r   r   zTracer.print_state_  sT    $"4"9"9GGG&MMMh$,dnn.>.>??@@@@@r   c                     |dz  }|dt          | j                  z  z  }|d|                                 z   z  }t          |          )Nr&   z  Expected: %s
z  Got:      )rH   r   r   r   r?   r   s     r   r   zTracer.raise_not_expectede  sL    t!C$4$444~ 0 000!#&&&r   c                 T   | j         d         }t          | j                   dk    r| j         d         nd }t          | d|z             }|dv r |             d S |dv r || j                   d S |dk    rBd }|r+|                     | j        j        j        |d                   } || j        |           d S |r|dv s|d	v r|d
v r:|^}}}|                     ||          }||g}|                    |            ||  n|dv r ||  n|d	v r
 |             d | _        | 	                                 | j
        r|                                  n0| j        r|                                  |                     d           |                                  d S t!          d| j         z            )Nr   r   rc   set_)stepcontinuequit)nextr   until)breakclearr,   enabledisable)updown)r   r   )r,   r   r   r   z"%s" is an invalid set_tuple)r   rv   getattrr@   r   r   rP   extendrA   r   r   r   r   r   r   r   r   )r?   set_typer   
set_methodrU   ro   remains          r   r   zTracer.next_set_methodk  s+   >!$$'$7$71$<$<t~a  $T6H#455
 333JLLLF+++Jtz"""F  F 3))$**;*G*.q'3 3Jtz6***F  	1X "/ / /3;~3M3M---)-&v))%88vF###
D!!!<<<
D!!!^++
 DJMMOOO| .  """"; *'')))**1---  """"" !?!%"0 1 1 1r   )NFNr   )r   r   r   r   r   r   r>   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rx   ry   s   @r   r{   r{      s}       ..     B B B= = = = =$        
2 2 2
) ) )
. . .0= 0= 0=dC C CG G G< < <
< < <  
; ; ;$A A A A' ' '01 01 01 01 01 01 01r   r{   c                   (    e Zd ZdZddZd ZddZdS )	TracerRunzAProvide a context for running a Tracer instance with a test case.Nc                     || _         |j        | _        t          |j        || j        |                                          | _        d | _        d S )N)r~   r   r   )r   r   r{   r   idtracer_original_tracer)r?   r   r~   s      r   r   zTracerRun.__init__  sP    " (Y1%)\Y\\^^M M M $r   c                 \    t                       t          j                    | _        | j        S r   )r   sysgettracer   r   rs   s    r   	__enter__zTracerRun.__enter__  s$     #{r   c                    t                       t          j        | j                   d}| j        j        r|dz  }|d| j        j        z  z  }|{t          t          |          rft          |t                    rQ|j        rJ|j        d         }|r|d|z   z  }| j        rt          |           dS | j                            |           	 |r4| j        rt          |           d S | j                            |           d S d S )Nr$   z+All paired tuples have not been processed, zthe last one was number %dr   r&   T)r   r   settracer   r   r   r   
issubclassr   rG   BaseExceptionr   r   r   r   fail)r?   type_value	traceback	not_emptyerr_msgs         r   __exit__zTracerRun.__exit__  s0   T*+++	; 	5FFI6+34 5I ,?!G!G%// 
DEJ 
D*Q- 0ti//G< 1'NNN4N''0000  	/| /i     ##I.....		/ 	/r   r   )NNN)r   r   r   r   r   r   r  r   r   r   r   r     sQ        KK% % % %  / / / / / /r   r   c                    d }ddg}|                     |           t                      }d|_        d |_        t	           |t          d          t          |                              |_        t          |           5  t          ||          5 }|
                    t                     ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )	a{  Run a test and print the dry-run results.

    'modules':  A dictionary mapping module names to their source code as a
                string. The dictionary MUST include one module named
                'test_module' with a main() function.
    'set_list': A list of set_type tuples to be run on the module.

    For example, running the following script outputs the following results:

    *****************************   SCRIPT   ********************************

    from test.test_bdb import run_test, break_in_func

    code = '''
        def func():
            lno = 3

        def main():
            func()
            lno = 7
    '''

    set_list = [
                break_in_func('func', 'test_module.py'),
                ('continue', ),
                ('step', ),
                ('step', ),
                ('step', ),
                ('quit', ),
            ]

    modules = { 'test_module': code }
    run_test(modules, set_list)

    ****************************   results   ********************************

    1: ('line', 2, 'tfunc_import'),    ('next',),
    2: ('line', 3, 'tfunc_import'),    ('step',),
    3: ('call', 5, 'main'),            ('break', ('test_module.py', None, False, None, 'func')),
    4: ('None', 5, 'main'),            ('continue',),
    5: ('line', 3, 'func', ({1: 1}, [])), ('step',),
      BpNum Temp Enb Hits Ignore Where
      1     no   yes 1    0      at test_module.py:2
    6: ('return', 3, 'func'),          ('step',),
    7: ('line', 7, 'main'),            ('step',),
    8: ('return', 7, 'main'),          ('quit',),

    *************************************************************************

    c              3   z   K   	 	 t          |           }t          |          }|V  |V  '# t          $ r Y d S w xY wr   )r   StopIteration)abxys       r   genzrun_test.<locals>.gen  sa      	GGGG	
  	 	 	FF	s   (, 
::r   r   Tc                      d S r   r   r   r   r   <lambda>zrun_test.<locals>.<lambda>  s    t r   r   r}   N)r   BaseTestCaser   r   r   r   iterr   create_modulesr   runcalltfunc_import)modulesr   r~   r  sltestr   s          r   run_testr    sY   f   j	!BIIh>>DDLmDG33vbzz4884455DO		 	  ) )t$''' 	)6NN<(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )s6   CB:.C:B>	>CB>	CCCc           	   #     K   t          j                    5  t          j                            t          j                               	 | D ]r}|dz   }t          |dd          5 }|                    t          j
        | |                              d d d            n# 1 swxY w Y   t          j        |           st          j                     d V  | D ]}t          j        |           t          j                                         n<# | D ]}t          j        |           t          j                                         w xY w	 d d d            d S # 1 swxY w Y   d S )N.pywzutf-8)encoding)r   temp_cwdr   r.   appendr-   getcwdopenwritetextwrapdedent	linecache
checkcacherK   invalidate_cachesr   forgetr   )r  mro   r`   s       r   r  r    s     				  	$$$	 , ,E	%w777 91GGHOGAJ778889 9 9 9 9 9 9 9 9 9 9 9 9 9 9$U++++')))EEE ( ($Q''''HLLNNNN  ( ($Q''''HLLNNNNN                 sM   1ED#.BDB!!D$B!%/D8E9EEEEFc                     d|d ||| ffS )Nr   r   )rF   ro   r(   r2   s       r   break_in_funcr+  &  s    UD)T8<<<r   test_module_for_bdbr  c                  6    dd l } |                                  d S r\   )r,  main)r,  s    r   r  r  +  s&    r   c                  N    d} t                       t                       d} d} d} d S )Nr            )tfunc_firsttfunc_secondlnos    r   
tfunc_mainr7  /  s,    
CMMMNNN
C
C
CCCr   c                      d} d} d} d S )Nr   r      r   r5  s    r   r3  r3  7  s    
C
C
CCCr   c                  
    d} d S )Nr   r   r5  s    r   r4  r4  <  s    
CCCr   c                       e Zd ZdZeZddZdS )r  zBase class for all tests.Nc                 .    |                      |          d r   )failureExceptionr   s     r   r   zBaseTestCase.failD  s     ##C((d2r   r   )r   r   r   r   r   r   r   r   r   r  r  ?  s3        ##G3 3 3 3 3 3r   r  c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Z eej                  d             Zd Zd Zd ZdS )StateTestCasez;Test the step, next, return, until and quit 'set_' methods.c                     g d| _         t          |           5 }|                    t                     d d d            d S # 1 swxY w Y   d S )N)r1   r   r7  r  r1   r   r7  r  r   rc   r3  r  r1   r   r3  r   r   r   r  r7  r?   r   s     r   	test_stepzStateTestCase.test_stepL      
 
 
 t__ 	'NN:&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'   AAAc                 8   dD ]}|                      |          5  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          |           5 }|                    t
                     d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )N)r   r   r   rA  r  rB  rC  r   r   )Nonerc   r3  r   r1   r3  rc   r1   r9  r3  rE  )subTestrI   r   r   r  r7  )r?   r   r   s      r    test_step_next_on_last_statementz.StateTestCase.test_step_next_on_last_statementV  s;   ( 	/ 	/Hx00 
/ 
/-Z-Z.gRS}=U.^Q1r{;h\.Z# t__ /NN:.../ / / / / / / / / / / / / / /
/ 
/ 
/ 
/ 
/ 
/ 
/ 
/ 
/ 
/ 
/ 
/ 
/ 
/ 
/	/ 	/s5   5BA7+B7A;;B>A;?BB	B	c                     g d| _         t          |           5 }|                    t                     d d d            d S # 1 swxY w Y   d S )N)
rA  r  rB  r  r1   r9  r7  r  )r   rc   r4  r  )r1   r   r4  rE  rF  rG  s     r   	test_nextzStateTestCase.test_nextd      
 
 
 t__ 	'NN:&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'rJ  c                     d}t           |i}t          |          5  g d| _        t          |           5 }|                    t
                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )N9
            def main():
                lno = 3
        )r1   r   r  r  r1   r   r  rE  )TEST_MODULEr  r   r   r  r  r?   rY   r  r   s       r   test_next_over_importz#StateTestCase.test_next_over_importo  s     'G$$ 	- 	-  DO 4 -F|,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s4   A3AA3A	A3"A	#A33A7:A7c                     g d| _         t          |           5 }|                    t                     d d d            d S # 1 swxY w Y   d S )N)rA  r  rB  r  rC  r  rD  rE  rF  rG  s     r   test_next_on_plain_statementz*StateTestCase.test_next_on_plain_statement}  s    
 
 
 t__ 	'NN:&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'rJ  c                     g d| _         t          |           5 }|                    t                     d d d            d S # 1 swxY w Y   d S )N)
rA  r  rB  r  rC  r   rM  r   r7  r  rS  rE  rF  rG  s     r   test_next_in_caller_framez'StateTestCase.test_next_in_caller_frame  s    
 
 
 t__ 	'NN:&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'rJ  c                     g d| _         t          |           5 }|                    t                     d d d            d S # 1 swxY w Y   d S )N)rA  r  rB  r  rC  r  rD  r   r   r9  r3  r  rS  rE  rF  rG  s     r   test_returnzStateTestCase.test_return  s    
 
 
 t__ 	'NN:&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'rJ  c                     g d| _         t          |           5 }|                    t                     d d d            d S # 1 swxY w Y   d S )N)
rA  r  rB  r  rC  r`  ra  rd  )r   r2  r7  rE  rF  rG  s     r   test_return_in_caller_framez)StateTestCase.test_return_in_caller_frame  rU  rJ  c                     g d| _         t          |           5 }|                    t                     d d d            d S # 1 swxY w Y   d S )N)
rA  r  rB  r  rC  r  rD  )r   )r9  rO  rE  rF  rG  s     r   
test_untilzStateTestCase.test_until  rU  rJ  c           	          dt          d          dddddddig ffdd	d
g| _        t          |           5 }|                    t                     d d d            d S # 1 swxY w Y   d S )NrA  r3  )rM  r   r7  rN  r1   r   rc   )r   )i'  re  rE  )r+  r   r   r  r7  rG  s     r   test_until_with_too_large_countz-StateTestCase.test_until_with_too_large_count  s    %]=5Q5Q%^Q1r{35H(Z	
 t__ 	'NN:&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   AA #A c                     g d| _         t          |           5 }|                    t                     d d d            d S # 1 swxY w Y   d S )N)
rA  r  rB  r  rC  r`  ra  )r   )r1  )r1   r1  r7  rE  rF  rG  s     r   test_until_in_caller_framez(StateTestCase.test_until_in_caller_frame  rU  rJ  c                 d   d t           j        D             t           j        d d <   d}t          |i}t          |          5  g d| _        dddt          f}t          | |          5 }|                    t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nc              3   N   K   | ] }|j                             d           |V  !dS )_frozen_importlibN)r   
startswith)r!   items     r   	<genexpr>z*StateTestCase.test_skip.<locals>.<genexpr>  sM       
 
))*=>>

 
 
 
 
 
r   rW  )rX  r  rY  rE  z
importlib*	zipimportzencodings.*r}   )r   	meta_pathrZ  r  r   r   r  r  )r?   rY   r  r~   r   s        r   	test_skipzStateTestCase.test_skip  sL   
 

 
 
aaa  'G$$ 	- 	-  DO !+}kJD4d+++ -v|,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s6    &B%&BB%B	B%B	B%%B),B)c                 z    t          dg          }|                     |                    d           d           d S )Nz	anything*r}   F)r:   assertIsis_skipped_module)r?   bdbs     r   test_skip_with_no_name_modulez+StateTestCase.test_skip_with_no_name_module  s>     }%%%c++D11599999r   c                     ddg| _         t          |           5 }|                     t          |j        t
                     d d d            d S # 1 swxY w Y   d S )NrA  )r   )r   r   assertRaisesr   r  r7  rG  s     r   	test_downzStateTestCase.test_down  s     &z
 t__ 	Dh
CCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D   'AAAc                     g d| _         t          |           5 }|                    t                     d d d            d S # 1 swxY w Y   d S )N)rA  r  rB  r  rC  r`  ra  rE  rF  rG  s     r   test_upzStateTestCase.test_up  rI  rJ  N)r   r   r   r   rH  rQ  rT  r\  r^  rb  rf  rh  rj  rl  rn  r   r   rv  rw  r|  r  r  r   r   r   r?  r?  I  s       EE' ' '/ / /	' 	' 	'- - -
' 
' 
'' ' '
' 
' 
'	' 	' 	'	' 	' 	'' ' '	' 	' 	' Z- - -2: : :D D D' ' ' ' 'r   r?  c                   T    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )BreakpointTestCasezTest the breakpoint set method.c                     ddg| _         t          |           5 }|                     t          |j        t
                     d d d            d S # 1 swxY w Y   d S )NrX  )r   )z/non/existent/module.pyrc   )r   r   r~  r   r  r  rG  s     r   test_bp_on_non_existent_modulez1BreakpointTestCase.test_bp_on_non_existent_module  s    ')R
 t__ 	FhEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fr  c                 *   d}t           |i}t          |          5  ddt          dffg| _        t	          |           5 }|                     t          |j        t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrW  rX  r   r9  )	rZ  r  TEST_MODULE_FNAMEr   r   r~  r   r  r  r[  s       r   test_bp_after_last_statementz/BreakpointTestCase.test_bp_after_last_statement
  s>     'G$$ 	J 	J+g8I17M-NDO 4 JF!!(FNLIIIJ J J J J J J J J J J J J J J		J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	Js4   "B'A0$B0A4	4B7A4	8BBBc                    d}t           |i}t          |          5  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          |           5 }|                    t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )N
            def func():
                lno = 3

            def main():
                for i in range(2):
                    func()
        rX  rX   TrM  r   r  rN  r1   r   rc   r   rE  rZ  r  r+  r  r   r   r  r  r[  s       r   test_temporary_bpz$BreakpointTestCase.test_temporary_bp  s]     'G$$ 	- 	-+!&*;TBB+!&*;TBB+>FaUQCL1>FaUQCL1:DO 4 -F|,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s6   AB56BB5B!	!B5$B!	%B55B9<B9c                    d}t           |i}t          |          5  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          |           5 }|                    t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )N
            def func():
                lno = 3

            def main():
                for i in range(3):
                    func()
        rX  rX   r  T)r   r   rN  r1   r   rc   )r   r  rM  r   rX   r   rc   r   r   r  rE  r  r[  s       r   test_disabled_temporary_bpz-BreakpointTestCase.test_disabled_temporary_bp.  s     'G$$ 	- 	-+!&*;<<+!&*;TBB+3E+>FaUBK03D#3E#>FaUQCL13D#>FaUBK0:DO 4 -F|,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s6   A+CB-!C-B1	1C4B1	5CC	C	c           
      B   d}t           |i}t          |          5  dt          dt          dd          dddd	dd
d	ig ffdg| _        t          |           5 }|                    t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nz
            def func(a):
                lno = 3

            def main():
                for i in range(3):
                    func(i)
        rX  rX   Fza == 2r  rN  r1   r   rc   rE  r  r[  s       r   test_bp_conditionz$BreakpointTestCase.test_bp_conditionJ  s2     'G$$ 	- 	-+!&*;UHMM+>FaUBK0:	DO 4 -F|,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-5   :BA<0B<B 	 BB 	BBBc           
      B   d}t           |i}t          |          5  dt          dt          dd          dddd	dd
d
ig ffdg| _        t          |           5 }|                    t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nzk
            def func(a):
                lno = 3

            def main():
                func(0)
        rX  rX   Fz1 / 0r  rN  r1   r   rc   rE  r  r[  s       r   )test_bp_exception_on_condition_evaluationz<BreakpointTestCase.test_bp_exception_on_condition_evaluation^  s2     'G$$ 	- 	-+!&*;UGLL+>FaUBK0:	DO 4 -F|,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-r  c                 B   d}t           |i}t          |          5  dt          dt                    dddddddd	d
ig ffdg| _        t          |           5 }|                    t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr  rX  rX   r  r,   r  rN  r1   r   rc   r   rE  r  r[  s       r   test_bp_ignore_countz'BreakpointTestCase.test_bp_ignore_countq  s4     'G$$ 		- 		-+!&*;<<+2C+.FaUBK0*DO 4 -F|,,,- - - - - - - - - - - - - - -		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 		- 		-r  c                    d}t           |i}t          |          5  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          |           5 }|                    t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr  rX  rX   r  r  r  rN  r1   r   r   rc   r  r  rE  r  r[  s       r    test_ignore_count_on_disabled_bpz3BreakpointTestCase.test_ignore_count_on_disabled_bp  s}     'G$$ 	- 	-+!&*;<<+!&*;<<+2C+2D+.FaUBK02C#.FaUBK0.FaUBK0*DO 4 -F|,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s6   A'CB)C)B-	-C0B-	1CCCc                    d}t           |i}t          |          5  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	          |           5 }|                    t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nz
            def func():
                lno = 3
                lno = 4

            def main():
                for i in range(3):
                    func()
        rX  r   r   r  r9  rN  r1   rX   rc   r   )rM  r9  rX   r   rE  )rZ  r  r  r   r   r  r  r[  s       r   test_clear_two_bp_on_same_linez1BreakpointTestCase.test_clear_two_bp_on_same_line  s     'G$$ 	- 	-+7=NPQ<R2S+7=NPQ<R2S+7=NPQ<R2S+.FaUBK0.FaUBK07=NPQ<R2S#.FaUBK0*	DO 4 -F|,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s6   A#B=>B%B=%B)	)B=,B)	-B==CCc                     ddt           dffg| _        t          |           5 }|                     t          |j        t                     d d d            d S # 1 swxY w Y   d S )NrX  r   rc   )rI   r   r   r~  r   r  r  rG  s     r   test_clear_at_no_bpz&BreakpointTestCase.test_clear_at_no_bp  s    ''Ha=)A
 t__ 	FhEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs   'AAAc                 ~	   t                       t                      }|                    t                    }|                    t          d           |                     |                                |dgi           t                      }|                    t          d           |                    t          d           |                    t          d           |                     |                                |dgi           |                     |                                |g di           |                    t          d           |                     |                                |dgi           |                     |                                |g di           t                      }|                     |                                |dgi           |                     |                                |g di           |                     |                                |g di           |                    t          d           |                     |                                |dgi           |                     |                                |ddgi           |                     |                                |g di           t                      }|                    t          d           |                     |                                |dgi           |                     |                                |ddgi           |                     |                                |g di           |                     |                                |g di           t                       t                      }|                    t          d	           |                     |                                |dgi           |                     |                                |ddgi           |                     |                                |g di           |                     |                                |g di           |                     |                                |d	gi           d S )
Nrc   r   r   r9  )rc   r   r   r9  )r   r   r9  r0  )r   r9  r0  r1  )r   r:   r   rI   rS   assertEqualget_all_breaksrn   )r?   db1ro   db2db3db4db5s          r   (test_load_bps_from_previous_Bdb_instancez;BreakpointTestCase.test_load_bps_from_previous_Bdb_instance  s?   eeH%%h"""++--s|<<<eeh"""h"""h"""++--s|<<<++--|||/DEEE!$$$++--s|<<<++--yyy/ABBBee++--s|<<<++--yyy/ABBB++--yyy/ABBB!$$$++--s|<<<++--1v???++--yyy/ABBBeeh"""++--s|<<<++--1v???++--yyy/ABBB++--yyy/ABBBeeh"""++--s|<<<++--1v???++--yyy/ABBB++--yyy/ABBB++--s|<<<<<r   N)r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r   r   r   r  r     s        ))F F FJ J J- - -.- - -8- - -(- - -&- - -*- - -6- - -2F F F(= (= (= (= (=r   r  c                       e Zd ZdZd Zd ZdS )RunTestCasez Test run, runeval and set_trace.c                     d}g d| _         t          |           5 }|                    t          t	          j        |          dd                     d d d            d S # 1 swxY w Y   d S )Nz
            lno = 2
        ))r1   r   <module>r  )r   r   r  rE  z<string>exec)r   r   runcompiler#  r$  )r?   rY   r   s      r   test_run_stepzRunTestCase.test_run_step  s    
 
 
 t__ 	KJJwxt44j&IIJJJ	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	Ks   7AA#&A#c                 2   d}t           |i}t          |          5  g d| _        dd l}t	          |           5 }|                    dt                      t                                 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrW  )
)r1   rc   r  r  )r   r   r.  r  )r1   r   r.  r  )r   r   r.  r  )r   rc   r  rE  r   ztest_module_for_bdb.main())rZ  r  r   r,  r   runevalrJ   locals)r?   rY   r  r,  r   s        r   test_runeval_stepzRunTestCase.test_runeval_step  sI     'G$$ 
	R 
	R  DO '&&&4 RF;WYYQQQ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s4   B0A4(B4A8	8B;A8	<BBBN)r   r   r   r   r  r  r   r   r   r  r    s@        **
K 
K 
KR R R R Rr   r  c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )IssuesTestCasezTest fixed bdb issues.c                 D   d}d}t           |d|i}t          |          5  dt          dd          ddd	d
dddig ffdddddg
| _        t	          |           5 }|                    t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nz
            from test_module_for_bdb_2 import func
            def main():
                func()
                lno = 5
        z9
            def func():
                lno = 3
        test_module_for_bdb_2rX  rX   ztest_module_for_bdb_2.pyr  rN  r1   r   rc   r  )r   r   rX   )r1   r0  r.  rE  )rZ  r  r+  r   r   r  r  )r?   code_1code_2r  r   s        r   +test_step_at_return_with_no_trace_in_callerz:IssuesTestCase.test_step_at_return_with_no_trace_in_caller  sH   
 #V
 G$$ 
	- 
	-+!&*DEE+.FaUBK0*%*#*DO 4 -F|,,,- - - - - - - - - - - - - - -
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	- 
	-s5   7BA=1B=B	BB	BBBc                 <   d}t           |i}dD ]}|                     |          5  t          |          5  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          |           5 }|	                    t                     d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   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   r   rL  rX  test_genr  rN  r1   r   rc   r   r   
   r.  r  )r   r  r.  rE  r1   r9  r  )rZ  rP  r  r+  r  r   r   r  r   r  r  )r?   rY   r  r   r   s        r   #test_next_until_return_in_generatorz2IssuesTestCase.test_next_until_return_in_generator/  s   
  '3 	5 	5Hx00 5 5#G,, 5 53)*6GHH3nJ!A<xl	'DO  8++..)2v}Ey3z    ..4jB   #4 5F|4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5%5 5 5 5 5 5 5 5 5 5 5 5 5 5 55 5 5 5 5 5 5 5 5 5 5 5 5 5 5	5 	5sY   DBC8:C!	C8!C%%C8(C%)C8,D8C<<D?C< DD	D	c                 d   d}t           |i}t          |          5  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          |           5 }|                    t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   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
        rX  r  r  rN  r1   r   rc   r  r  )r1   r0  r  )r1   r1  r  r   	   r.  r  )r1      r.  rE  	rZ  r  r+  r  r  r   r   r  r  r[  s       r   'test_next_command_in_generator_for_loopz6IssuesTestCase.test_next_command_in_generator_for_loopX  sP     'G$$ 	- 	-+!*.?@@+J!A4'''a7$DO 4 -F|,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s6   AB%&BB%B	B%B	B%%B),B)c                 \   d}t           |i}t          |          5  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          |           5 }|                    t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )N4  
            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
        rX  r  r  rN  r1   r2  rc   r  )r1      r  r   r  r.  r  r1      r.  rE  r  r[  s       r   /test_next_command_in_generator_with_subiteratorz>IssuesTestCase.test_next_command_in_generator_with_subiteratorw  sF     'G$$ 	- 	-+!*.?@@+.J!A4*'*b&-8*$*	DO 4 -F|,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s6   AB!"B	=B!	B	B!B	B!!B%(B%c                 n   d}t           |i}t          |          5  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          |           5 }|                    t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr  rX  test_subgenr  rN  r1   r   rc   rd  r   r2  r  r  r.  r  r  rE  r  r[  s       r   1test_return_command_in_generator_with_subiteratorz@IssuesTestCase.test_return_command_in_generator_with_subiterator  sO     'G$$ 	- 	-+!-1BCC+nMQqE2;7la];lb&-8j$j	DO 4 -F|,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s6   AB*+BB*B	B*B	B**B.1B.N)	r   r   r   r   r  r  r  r  r  r   r   r   r  r    sf          - - -<'5 '5 '5R- - ->- - ->- - - - -r   r  c                       e Zd Zd ZdS )TestRegressionsc                     |                      dt                                          t          j                    d f                     d S )NzWarning: lineno is None)assertInr:   format_stack_entryr   	_getframers   s    r   !test_format_stack_entry_no_linenoz1TestRegressions.test_format_stack_entry_no_lineno  sJ    /ee../FGG	I 	I 	I 	I 	Ir   N)r   r   r   r  r   r   r   r  r    s(        I I I I Ir   r  __main__r   )0r   r{  r   r   r-   unittestr#  rK   r%  
contextlibr   	itertoolsr   r   test.supportr   r   r   	Exceptionr
   r   r   r   r   r   r8   r:   r{   r   r  r  rI   r+  rZ  r  r  r7  r3  r4  TestCaser  r?  r  r  r  r  r   r.  r   r   r   <module>r     s  0 0d     



 				           % % % % % % $ $ $ $ $ $ $ $ & & & & & & " " " " " " # # # # # # $ # # # #9 # # # E E E E E| E E E H H H H H\ H H H A A A A A, A A A ' ' '  *>/ >/ >/ >/ >/$( >/ >/ >/@w1 w1 w1 w1 w1S w1 w1 w1r,/ ,/ ,/ ,/ ,/ ,/ ,/ ,/\H) H) H) H)T     #+e$ = = = = $%'       
  3 3 3 3 38$ 3 3 3u' u' u' u' u'L u' u' u'ni= i= i= i= i= i= i= i=X R  R  R  R  R,  R  R  RDe- e- e- e- e-\ e- e- e-PI I I I Ih' I I I zHMOOOOO r   