
    /hhb                     h   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSKJrJr  SSKJr  SSKJr  SSKJr   " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      rSrS rS r " S S\R4                  5      r " S S\5      r " S S5      rS/S jr\
S 5       r\SS4S jr Sr!\!S-   r"S r#S r$S  r%S! r& " S" S#\RN                  5      r( " S$ S%\(5      r) " S& S'\(5      r* " S( S)\(5      r+ " S* S+\(5      r, " S, S-\RN                  5      r-\.S.:X  a  \R^                  " 5         gg)0a8  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                       \ rS rSrSrg)BdbExceptionA    N)__name__
__module____qualname____firstlineno____static_attributes__r       6/opt/python-3.13.8/usr/lib/python3.13/test/test_bdb.pyr
   r
   A   s    tr   r
   c                       \ rS rSrSrSrg)BdbErrorB   z!Error raised by the Bdb instance.r   Nr   r   r   r   __doc__r   r   r   r   r   r   B   s    Er   r   c                       \ rS rSrSrSrg)BdbSyntaxErrorC   zSyntax error in the test case.r   Nr   r   r   r   r   r   C   s    $Hr   r   c                       \ rS rSrSrSrg)BdbNotExpectedErrorD   zUnexpected result.r   Nr   r   r   r   r   r   D   s    )Ar   r   c                  @    [         R                  R                  5         g N)_bdb
BreakpointclearBreakpointsr   r   r   reset_Breakpointr$   L   s    OO$$&r   c                     [         R                  R                   V s/ s H  o (       d  M  U PM     nn U(       d  gSnU H  n U(       d  SnSnU R                  (       a  SOSnU R                  (       a  SOSnWS	U R
                  XEU R                  U R                  [        R                  R                  U R                  5      U R                  4-  -  nU R                  (       a  US
U R                  < 3-  nUS-  nM     W$ s  sn f )N 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bp_listheader_addedinfodispenabs         r   info_breakpointsr;   O   s    !__77>7r2r7G>L7DLv6

u0YYBGGRYYWW%%bgg.99 	: 77RWW66D  K% ?s
   
DDc                   p   ^  \ rS rSrSrU 4S jr  SU 4S jjrU 4S jrS rS r	S r
S	 rS
 rS rSrU =r$ )Bdbd   z$Extend Bdb to enhance test coverage.c                 2   > S U l         [        TU ]	  XU5      $ r    )	currentbpsupertrace_dispatch)selfframeeventarg	__class__s       r   rB   Bdb.trace_dispatchg   s    w%eC88r   c                 z  > [        U[        5      (       au  U[        :X  a  [        5       nO%[        R
                  " US S 5      nUR                  n[        XV5      nUR                  n	U	R                  nU	R                  nU	R                  n[        TU ]5  XUXES9n
[        U
[        5      (       a  [        U
5      eU
$ )N)r*   r4   funcname)
isinstancestr__file__globals	importlibimport_module__dict__eval__code__co_filenameco_firstlinenoco_namerA   	set_breakr   )rC   filenamelinenor*   r4   rK   globals_modulefunccoderesrG   s              r   rX   Bdb.set_breakk   s    h$$8#"9"00#2?!??+D==D''H((F||HgI&*   ?c33-
r   c                    > [         TU ]  X5      u  U l        U l        U R                  U R                     S   U l        U R                  U R                  4$ Nr   )rA   	get_stackstackindexrD   )rC   ftrG   s      r   rc   Bdb.get_stack   sG    !&!21!8
DJZZ

+A.
zz4::%%r   c                 P    U R                  U5      nU=R                  S-  sl        g)z8Increment the ignore count of Breakpoint number 'bpnum'.   N)get_bpbynumberr.   rC   bpnumr5   s      r   
set_ignoreBdb.set_ignore   s      '
		Q	r   c                 4    U R                  U5      nSUl        g )NTrk   r+   rl   s      r   
set_enableBdb.set_enable   s      '
r   c                 4    U R                  U5      nSUl        g )NFrq   rl   s      r   set_disableBdb.set_disable   s      '
r   c                 J    U R                  X5      nU(       a  [        U5      eg r    )clear_breakr   )rC   fnamerZ   errs       r   	set_clearBdb.set_clear   s$    u-3- r   c                     U R                   (       d  [        S5      eU =R                   S-  sl         U R                  U R                      S   U l        g)zMove up in the frame stack.zOldest framerj   r   N)re   r   rd   rD   rC   s    r   set_up
Bdb.set_up   s:    zz>**

a
ZZ

+A.
r   c                     U R                   S-   [        U R                  5      :X  a  [        S5      eU =R                   S-  sl         U R                  U R                      S   U l        g)zMove down in the frame stack.rj   zNewest framer   N)re   lenrd   r   rD   r~   s    r   set_downBdb.set_down   sK    ::>S_,>**

a
ZZ

+A.
r   )r@   rD   re   rd   )FNN)r   r   r   r   r   rB   rX   rc   rn   rr   ru   r{   r   r   r   __classcell__rG   s   @r   r=   r=   d   sB    .9 AE(&

 
// /r   r=   c                      ^  \ rS rSrSrSU 4S jjrS rU 4S jrS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rSS jrS rS rSrU =r$ )Tracer   z$A tracer for testing the bdb module.c                 v   > [         TU ]  US9  Xl        X0l        Ub  SU-  OS U l        U R                  5         g )NskipzDry-run results for %s:)rA   __init__
expect_setdry_runheader	init_test)rC   r   r   r   	test_caserG   s        r   r   Tracer.__init__   sA    d#$ , 19<26 	r   c                     S U l         SU l        S U l        [        [	        U R
                  SS S5      5      U l        [        [	        U R
                  SS S5      5      U l        g )Nr      rj   )
cur_exceptexpect_set_nobreakpoint_hitslistr   r   expected_listset_listr~   s    r   r   Tracer.init_test   sP    #!&!T1"EFVDOOQa@Ar   c                    > U R                   b  U R                   eUS:X  a   [        TU ]	  XU5      nU$ [        TU ]	  XU5      $ ! [         a  nXPl         U R                  s S nA$ S nAff = fN	exception)r   rA   rB   r
   )rC   rD   rE   rF   r_   erG   s         r   rB   Tracer.trace_dispatch   ss    
 ??&//!K+g,U3?

 7)%<<	   +"#***+s   A 
A*A%A*%A*c                 v    U R                  U5      (       d  g U R                  SX5        U R                  5         g )Ncall)	stop_hereprocess_eventnext_set_method)rC   rD   argument_lists      r   	user_callTracer.user_call   s2     ~~e$$658r   c                 8   U R                  SU5        U R                  (       aP  U R                  (       a?  [        5       R	                  S5      nUR                  S5       H  n[        SU-   5        M     U R                  5         S U l        U R                  5         g )Nr3   r(   z  )	r   r   r   r;   stripsplitprintdelete_temporariesr   )rC   rD   r8   r3   s       r   	user_lineTracer.user_line   ss    65)<<D00#%++D1D

4(dTk" )!#r   c                 H    U R                  SX5        U R                  5         g )Nreturnr   r   )rC   rD   return_values      r   user_returnTracer.user_return   s    8U9r   c                 T    X l         U R                  SU5        U R                  5         g r   )exc_infor   r   )rC   rD   r   s      r   user_exceptionTracer.user_exception   s#     ;.r   c                 H    U R                  SU5        U R                  5         g )Nopcoder   )rC   rD   s     r   user_opcodeTracer.user_opcode   s    8U+r   c                 .    U R                   /nX"4U l        g r    )r@   r   )rC   rF   r6   s      r   do_clearTracer.do_clear   s    >>" '1r   c                 v    U R                   (       a(  U R                   S    H  nU R                  U5        M     g g Nrj   )r   clear_bpbynumber)rC   ns     r   r   Tracer.delete_temporaries   s3    ))!,%%a( -  r   c                     U =R                   S-  sl          U R                  R                  S5      U l        U R                  R                  S5      U l        g ! [         a    [        SU R                   -  5      ef = f)Nrj   r   z-expect_set list exhausted, cannot pop item %d)r   r   popexpect
IndexErrorr   r   	set_tupler~   s    r   pop_nextTracer.pop_next   sw    a	$,,003DK
 **1-	  	$%?""#$ $	$s    A #A;c           	         S nUS:X  a  U R                   S   nU R                  X$5        U R                  b'  U R                  (       d  U R                  /nU/ 4U l        Xl        U R                  5         U R                  (       a  U R                  U R                  5        g U R                  (       a0  U R                  U R                  S   US5        U R                  5         US;   a  U R                  S5        g [        U R                  5      S:  Gac  US:X  a  U R                  S   u  pg[        UR                  5       5      nU R                  (       d  U R!                  SU R"                  -  5        U R                  XR                  S   S	5        U R                  U V	s/ s H  oU	   PM	     sn	U R                  S    V	s/ s H  n	U R%                  U	5      R&                  PM      sn	S
5        U R                  [        U5      U R                  S   S5        g US:X  aW  [)        U R                   S   U R                  S   5      (       d+  U R!                  SU R"                  U R                   4-  5        g g g g s  sn	f s  sn	f )Nr   r   r   zWrong event type)r   r      r3   z(No breakpoints hit at expect_set item %dzBreakpoint numbers do not matchzWrong breakpoint hit countrj   zWrong temporary breakpointsz/Wrong exception at expect_set item %d, got '%s')r   rc   r@   r   rE   r   r   print_stater   r   check_equalcheck_lno_namecheck_expect_max_sizer   sortedkeysraise_not_expectedr   rk   r-   rL   )
rC   rE   rD   argstbr6   bpstemporariesbpnumsr   s
             r   r   Tracer.process_event   s6    Kq!Bu! >>%d.B.B~~&G$+R=D  
<<T[[) ;;T[[^U4FG!&&&&q)!#';;q> 
+++++B**+,   )=)=a)@57  &!9&Qa&&!9!11!464 ((+004602   !4d6J6J16M13 +%!$--"2DKKNCC++I++T]];<= D &# " ":6s    I7%I<
c                 P    X:X  a  g U R                  SX0R                  U4-  5        g )Nz"%s at expect_set item %d, got '%s')r   r   )rC   expectedresultmsgs       r   r   Tracer.check_equal1  s1     D!$&8&8& A!B 	Cr   c                 $   [        U R                  5      nUS:  a0  U R                  5       nU R                  U R                  S   US5        US:  a?  U R                  U R                  S   U R                  R
                  R                  S5        gg)z+Check the line number and function co_name.rj   zWrong line numberr   zWrong function nameN)r   r   lno_abs2relr   rD   f_coderW   )rC   srZ   s      r   r   Tracer.check_lno_name7  sz    q5%%'FT[[^V5HIq5T[[^TZZ->->-F-F0EG r   c                     [        U R                  5      U:  a'  [        SU R                  < SU R                  < 35      eg )NzInvalid size of the z expect tuple: )r   r   r   rE   )rC   sizes     r   r   Tracer.check_expect_max_sizeA  s7    t{{d" "&**dkk"; < < #r   c                 
   U R                  U R                  R                  R                  5      nU R                  R                  nXR                  [
        5      :X  a%  X R                  R                  R                  -
  S-   $ U$ r   )canonicrD   r   rU   f_linenorN   rV   rC   ry   rZ   s      r   r   Tracer.lno_abs2relF  sh    TZZ..::;$$X.. **++:::Q> 	<4:	<r   c                     U(       aN  U R                  U5      U R                  [        5      :X  a&  U R                  R                  R                  U-   S-
  $ U$ r   )r   rN   rD   r   rV   r   s      r   lno_rel2absTracer.lno_rel2absL  sJ    4<<.$,,x2HH 

!!0069A= 		r   c                 T   U R                  5       nU R                  R                  R                  nSU R                  X4-  nU R
                  (       ay  SnU R
                  S    H2  nUS:w  a  US-  nXE< SU R                  U5      R                  < 3-  nM4     US-  nSU-   S-   [        U R
                  S   5      -   S	-   nUSU-   -  nO/U R                  S
:X  a  USU R                  S   R                  -   -  nUS-  nUR                  S5      [        U R                  5      -   S-   $ )Nz('%s', %d, '%s'{r   z, z: }(rj   )r   z),     ,)r   rD   r   rW   rE   r   rk   r-   rM   r   r   ljustr   )rC   rZ   rW   stater   r   s         r   	get_stateTracer.get_stateQ  s    !!#**##++!TZZ$AAC))!,#:4KC1d&9&9!&<&A&ABB - 3JC)d"S)=)=a)@%AACGCTCZEZZ;&TDMM!,5555E{{2T^^!44s::r   c                     Ub%  U R                   S:X  a  [        5         [        U5        [        SU R                   U R                  5       4-  5        g )Nrj   z%d: %s)r   r   r   )rC   r   s     r   r   Tracer.print_statec  s@    $"4"4"9G&Mh$,,dnn.>??@r   c                     US-  nUS[        U R                  5      -  -  nUSU R                  5       -   -  n[        U5      e)Nr(   z  Expected: %s
z  Got:      )rM   r   r   r   rC   r   s     r   r   Tracer.raise_not_expectedi  sE    t!C$444~ 000!#&&r   c                 v   U R                   S   n[        U R                   5      S:X  a  U R                   S   OS n[        U SU-   5      nUS;   a  U" 5         g US;   a  U" U R                  5        g US:X  aP  S nU(       a3  U R	                  U R                  R
                  R                  US   5      nU" U R                  U5        g U(       a  US;   d  US	;   a  US
;   a/  UtpTnU R	                  XT5      nXT/nUR                  U5        U" U6   OUS;   a  U" U6   OUS	;   a  U" 5         S U l        U R                  5         U R                  (       a  U R                  5         O2U R                  (       a  U R                  5         U R                  S5        U R                  5         g [!        SU R                   -  5      e)Nr   r   rj   set_)step	stepinstrcontinuequit)nextr   until)breakclearr.   enabledisable)updown)r
  r  )r.   r  r  r   z"%s" is an invalid set_tuple)r   r   getattrrD   r   r   rU   extendrE   r   r   r   r   r   r   r   r   )rC   set_typer   
set_methodrZ   ry   remains          r   r   Tracer.next_set_methodo  s   >>!$$'$71$<t~~a $T6H#45
 @@L++tzz" F))$***;*;*G*G*.q'3tzz6* X "/ /3;~3M--)-&))%8F#D!<<D!^+ DJMMO||  ";;'')**1-  " !?!%"0 1 1r   )r   r   r   rE   r   r   r   r   r   r   r   r   )NFNr    )r   r   r   r   r   r   r   rB   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r      sy    .B=$
2
)
.0=dCG<
<
;$A'01 01r   r   c                   2    \ rS rSrSrSS jrS rS	S jrSrg)
	TracerRuni  zAProvide a context for running a Tracer instance with a test case.Nc                     Xl         UR                  U l        [        UR                  UU R                  UR	                  5       S9U l        S U l        g )N)r   r   r   )r   r   r   r   idtracer_original_tracer)rC   r   r   s      r   r   TracerRun.__init__  sB    " ((Y11%)\\Y\\^M $r   c                 b    [        5         [        R                  " 5       U l        U R                  $ r    )r$   sysgettracer  r  r~   s    r   	__enter__TracerRun.__enter__  s      #{{r   c                    [        5         [        R                  " U R                  5        SnU R                  R
                  (       aC  US-  nUSU R                  R                  -  -  nU[        U R                  R
                  5      -  nUb  [        [        U5      (       a  [        U[        5      (       ah  UR                  (       aW  UR                  S   nU(       a  USU-   -  nU R                  (       a  [        U5        gU R                  R!                  U5        O S5       eU(       a9  U R                  (       a  [        U5        g U R                  R!                  U5        g g )Nr&   z+All paired tuples have not been processed, zthe last one was number %d
r   r(   Tz#BdbNotExpectedError with empty args)r$   r  settracer  r  r   r   repr
issubclassr   rL   BaseExceptionr   r   r   r   fail)rC   type_value	traceback	not_emptyerr_msgs         r   __exit__TracerRun.__exit__  s   T**+	;;FFI8++334 5Idkk2233I ,?!G!G%//EJJ**Q-ti//G<<'NNN''0CCCu||i ##I.	 r   )r  r   r   r  r    )NNN)	r   r   r   r   r   r   r   r-  r   r   r   r   r  r    s    K%/r   r  c                 r   S nSS/nUR                  U5        [        5       nSUl        S Ul        [	        U" [        S5      [        U5      5      5      Ul        [        U 5         [        XRS9 nUR                  [        5        SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f)	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   n   #      [        U 5      n[        U5      nUv   Uv   M   ! [         a     g f = f7fr    )r  StopIteration)abxys       r   genrun_test.<locals>.gen  sA     	GG	 
  		s   5!% 
2525r  r  Tc                      g r    r   r   r   r   <lambda>run_test.<locals>.<lambda>  s    tr   r   r   N)r  BaseTestCaser   r  r   r   iterr   create_modulesr  runcalltfunc_import)modulesr   r   r6  sltestr  s          r   run_testrE    s    f j	!BIIh>DDLDG3vbz4845DO		 t'6NN<( ( 
!	 '' 
!	 s$   &
B(0BB(
B%	!B((
B6c           	   #     #    [         R                  " 5          [        R                  R	                  [
        R                  " 5       5         U  HY  nUS-   n[        USSS9 nUR                  [        R                  " X   5      5        S S S 5        [        R                  " U5        M[     [        R                  " 5         S v   U  H  n[        R                   " U5        M     [        R                  R#                  5          S S S 5        g ! , (       d  f       N= f! U  H  n[        R                   " U5        M     [        R                  R#                  5         f = f! , (       d  f       g = f7f)N.pywzutf-8)encoding)r   temp_cwdr  r0   appendr/   getcwdopenwritetextwrapdedent	linecache
checkcacherP   invalidate_cachesr   forgetr   )rB  mry   rf   s       r   r?  r?    s     						$	E	%w71GGHOOGJ78 8$$U+	 
 '')$$Q' HHLLN 
	
 87 $$Q' HHLLN 
	sL   E/3ED!(D	;D=E	E/
DD?EE
E,(E/Fc                     SUS X#U 44$ )Nr
  r   )rK   ry   r*   r4   s       r   break_in_funcrW  +  s    UD)8<<<r   test_module_for_bdbrG  c                  ,    SS K n U R                  5         g rb   )rX  main)rX  s    r   rA  rA  0  s    r   c                  <    Sn [        5         [        5         Sn Sn Sn g )Nr            )tfunc_firsttfunc_secondlnos    r   
tfunc_mainrc  4  s     
CMN
C
C
Cr   c                      Sn Sn Sn g )Nr   r      r   ra  s    r   r_  r_  <  s    
C
C
Cr   c                      Sn g )Nr   r   ra  s    r   r`  r`  A  s    
Cr   c                   &    \ rS rSrSr\rSS jrSrg)r=  iD  zBase class for all tests.Nc                 &    U R                  U5      S er    )failureExceptionr   s     r   r'  BaseTestCase.failI  s     ##C(d2r   r   r    )r   r   r   r   r   r   r'  r   r   r   r   r=  r=  D  s    #G3r   r=  c                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS r\" \R&                  5      S 5       rS rS rS rSrg)StateTestCaseiN  z;Test the step, next, return, until and quit 'set_' methods.c                     / SQU l         [        U 5       nUR                  [        5        S S S 5        g ! , (       d  f       g = f)N)r3   r   rc  r9  r3   r   rc  r9  r   rj   r_  r9  r3   r   r_  r  r   r  r@  rc  rC   r  s     r   	test_stepStateTestCase.test_stepQ  ,    
 t_NN:& __	   4
Ac                 &   S Hh  nU R                  US9   SSSSSS[        S44S	S
SSSSS0/ 44U4SS/U l        [        U 5       nUR	                  [
        5        S S S 5        S S S 5        Mj     g ! , (       d  f       N= f! , (       d  f       M  = f)N)r  r  r  rn  r9  ro  rp  r
  r   )Nonerj   r_  r  r3   r_  rj   r3   re  r_  rr  )subTestrN   r   r  r@  rc  )rC   r  r  s      r    test_step_next_on_last_statement.StateTestCase.test_step_next_on_last_statement[  s    (Hx0-Z-Z.gRS}=U.^Q1r{;h\.Z# t_NN:. % 10 ) %_ 10s#   0BA0B0
A>:B
B	c                     / SQU l         [        U 5       nUR                  [        5        S S S 5        g ! , (       d  f       g = f)N)rn  )r  )r   r   rc  r8  ro  rr  rs  rt  s     r   test_stepinstrStateTestCase.test_stepinstri  s,    

 t_NN:& __rx  c                     / SQU l         [        U 5       nUR                  [        5        S S S 5        g ! , (       d  f       g = f)N)
rn  r9  ro  r8  r3   re  rc  r9  )r   rj   r`  r9  )r3   r   r`  rr  rs  rt  s     r   	test_nextStateTestCase.test_nextr  ,    
 t_NN:& __rx  c                     Sn[         U0n[        U5         / SQU l        [        U 5       nUR	                  [
        5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)N9
            def main():
                lno = 3
        )r3   r   rA  r8  r3   r   rA  rr  )TEST_MODULEr?  r   r  r@  rA  rC   r^   rB  r  s       r   test_next_over_import#StateTestCase.test_next_over_import}  s[      'G$DO 4F|, ! %$
 ! %$s"   A#AA#
A 	A##
A1c                     / SQU l         [        U 5       nUR                  [        5        S S S 5        g ! , (       d  f       g = f)N)rn  r9  ro  r9  rp  r8  rq  rr  rs  rt  s     r   test_next_on_plain_statement*StateTestCase.test_next_on_plain_statement  s,    
 t_NN:& __rx  c                     / SQU l         [        U 5       nUR                  [        5        S S S 5        g ! , (       d  f       g = f)N)
rn  r9  ro  r9  rp  r  r{  r   rc  r8  r  rr  rs  rt  s     r   test_next_in_caller_frame'StateTestCase.test_next_in_caller_frame  s,    
 t_NN:& __rx  c                     / SQU l         [        U 5       nUR                  [        5        S S S 5        g ! , (       d  f       g = f)N)rn  r9  ro  r9  rp  r9  rq  r   r   re  r_  r9  r  rr  rs  rt  s     r   test_returnStateTestCase.test_return  s,    
 t_NN:& __rx  c                     / SQU l         [        U 5       nUR                  [        5        S S S 5        g ! , (       d  f       g = f)N)
rn  r9  ro  r9  rp  r  r  r  )r   r^  rc  rr  rs  rt  s     r   test_return_in_caller_frame)StateTestCase.test_return_in_caller_frame  r  rx  c                     / SQU l         [        U 5       nUR                  [        5        S S S 5        g ! , (       d  f       g = f)N)
rn  r9  ro  r9  rp  r9  rq  )r	  )re  r}  rr  rs  rt  s     r   
test_untilStateTestCase.test_until  r  rx  c           	          S[        S5      SSSSSSS0/ 44SS	S
/U l        [        U 5       nUR                  [        5        S S S 5        g ! , (       d  f       g = f)Nrn  r_  )r{  r   rc  r|  r3   r   rj   )r	  )i'  r  rr  )rW  r   r  r@  rc  rt  s     r   test_until_with_too_large_count-StateTestCase.test_until_with_too_large_count  sW    %]=5Q%^Q1r{35H(Z	
 t_NN:& __s   A
Ac                     / SQU l         [        U 5       nUR                  [        5        S S S 5        g ! , (       d  f       g = f)N)
rn  r9  ro  r9  rp  r  r  )r	  )r]  )r3   r]  rc  rr  rs  rt  s     r   test_until_in_caller_frame(StateTestCase.test_until_in_caller_frame  r  rx  c                 H   S [         R                   5       [         R                  S S & Sn[        U0n[        U5         / SQU l        SSS[        4n[        XS9 nUR                  [        5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nc              3   j   #    U  H)  nUR                   R                  S 5      (       d  M%  Uv   M+     g7f)_frozen_importlibN)r   
startswith).0items     r   	<genexpr>*StateTestCase.test_skip.<locals>.<genexpr>  s,      
%))*=> D%s   $3	3r  )r  r9  r  rr  z
importlib*	zipimportzencodings.*r   )r  	meta_pathr  r?  r   r  r@  rA  )rC   r^   rB  r   r  s        r   	test_skipStateTestCase.test_skip  s    

a  'G$DO !+}kJD4+v|, , %$ ,+ %$s#   BB1B
B	B
B!c                 Z    [        S/S9nU R                  UR                  S 5      S5        g )Nz	anything*r   F)r=   assertIsis_skipped_module)rC   bdbs     r   test_skip_with_no_name_module+StateTestCase.test_skip_with_no_name_module  s)     }%c++D159r   c                     SS/U l         [        U 5       nU R                  [        UR                  [
        5        S S S 5        g ! , (       d  f       g = f)Nrn  )r  )r   r  assertRaisesr   r@  rc  rt  s     r   	test_downStateTestCase.test_down  s=     &z
 t_h
C __   &A
Ac                     / SQU l         [        U 5       nUR                  [        5        S S S 5        g ! , (       d  f       g = f)N)rn  r9  ro  r9  rp  r  r  rr  rs  rt  s     r   test_upStateTestCase.test_up  rw  rx  r   N)r   r   r   r   r   ru  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r   r   r   r   rl  rl  N  sn    E'/'	'-
''
'	'	''	' - -2:D'r   rl  c                   Z    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rSrg)BreakpointTestCasei  zTest the breakpoint set method.c                     SS/U l         [        U 5       nU R                  [        UR                  [
        5        S S S 5        g ! , (       d  f       g = f)Nr  )r
  )z/non/existent/module.pyrj   )r   r  r  r   r@  rA  rt  s     r   test_bp_on_non_existent_module1BreakpointTestCase.test_bp_on_non_existent_module  s<    ')R
 t_hE __r  c                    Sn[         U0n[        U5         SS[        S44/U l        [	        U 5       nU R                  [        UR                  [        5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nr  r  r
  re  )	r  r?  TEST_MODULE_FNAMEr   r  r  r   r@  rA  r  s       r   test_bp_after_last_statement/BreakpointTestCase.test_bp_after_last_statement  su      'G$+g8I17M-NDO 4F!!(FNNLI !	 %$ !	 %$s"   A;&A*A;*
A8	4A;;
B	c                 X   Sn[         U0n[        U5         S[        S[        S5      S[        S[        S5      SSSSSS	S	0S	/44SSSSS
S	0S
/44S/
U l        [        U 5       nUR                  [        5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)N
            def func():
                lno = 3

            def main():
                for i in range(2):
                    func()
        r  r]   Tr{  r   rA  r|  r3   r   rj   r   rr  r  r?  rW  r  r   r  r@  rA  r  s       r   test_temporary_bp$BreakpointTestCase.test_temporary_bp%  s      'G$+!&*;TB+!&*;TB+>FaUQCL1>FaUQCL1:DO 4F|, ! %$ ! %$s$   AB#B
9B

B	B
B)c                 x   Sn[         U0n[        U5         S[        S[        5      S[        S[        S5      SSSSSS	SS
S
0/ 44SSSSSSS	SSS
0S/44SSSSS	SS
S0/ 44S/U l        [        U 5       nUR                  [        5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)N
            def func():
                lno = 3

            def main():
                for i in range(3):
                    func()
        r  r]   r  T)r  r   r|  r3   r   rj   )r  r  r{  r   r]   r  rj   r   r  r  rr  r  r  s       r   test_disabled_temporary_bp-BreakpointTestCase.test_disabled_temporary_bp<  s      'G$+!&*;<+!&*;TB+3E+>FaUBK03D#3E#>FaUQCL13D#>FaUBK0:DO 4F|, ! %$ ! %$s$   AB+3B	B+
B(	$B++
B9c           
          Sn[         U0n[        U5         S[        S[        SS5      SSSS	SS
S	0/ 44S/U l        [        U 5       nUR                  [        5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nz
            def func(a):
                lno = 3

            def main():
                for i in range(3):
                    func(i)
        r  r]   Fza == 2r  r|  r3   r   rj   rr  r  r  s       r   test_bp_condition$BreakpointTestCase.test_bp_conditionX  s      'G$+!&*;UHM+>FaUBK0:	DO 4F|, ! %$ ! %$#   1A?A.A?.
A<	8A??
Bc           
          Sn[         U0n[        U5         S[        S[        SS5      SSSS	SS
S
0/ 44S/U l        [        U 5       nUR                  [        5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nzk
            def func(a):
                lno = 3

            def main():
                func(0)
        r  r]   Fz1 / 0r  r|  r3   r   rj   rr  r  r  s       r   )test_bp_exception_on_condition_evaluation<BreakpointTestCase.test_bp_exception_on_condition_evaluationl  s      'G$+!&*;UGL+>FaUBK0:	DO 4F|, ! %$ ! %$r  c                     Sn[         U0n[        U5         S[        S[        5      SSSSSSSS	S
0/ 44S/U l        [        U 5       nUR                  [        5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nr  r  r]   r  r.   r  r|  r3   r   rj   r   rr  r  r  s       r   test_bp_ignore_count'BreakpointTestCase.test_bp_ignore_count  s      'G$+!&*;<+2C+.FaUBK0*DO 4F|, ! %$ ! %$r  c                 p   Sn[         U0n[        U5         S[        S[        5      S[        S[        5      SSSSSSSS	SS
S0/ 44SSSSS	SS
S
0/ 44SSS	SSS
0/ 44S/U l        [        U 5       nUR                  [        5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nr  r  r]   r  r  r  r|  r3   r   r   rj   r  r  rr  r  r  s       r    test_ignore_count_on_disabled_bp3BreakpointTestCase.test_ignore_count_on_disabled_bp  s      'G$+!&*;<+!&*;<+2C+2D+.FaUBK02C#.FaUBK0.FaUBK0*DO 4F|, ! %$ ! %$s$   AB'/BB'
B$	 B''
B5c                 t   Sn[         U0n[        U5         SS[        S44SS[        S44SS[        S44SSSSS	S
S
0/ 44SSSS	SS
0/ 44S[        S44SSSSS	SS0/ 44S/U l        [	        U 5       nUR                  [        5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nz
            def func():
                lno = 3
                lno = 4

            def main():
                for i in range(3):
                    func()
        r  r
  r   r  re  r|  r3   r]   rj   r  )r{  re  r]   r   rr  )r  r?  r  r   r  r@  rA  r  s       r   test_clear_two_bp_on_same_line1BreakpointTestCase.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|, ! %$ ! %$s$   AB)1BB)
B&	"B))
B7c                     SS[         S44/U l        [        U 5       nU R                  [        UR
                  [        5        S S S 5        g ! , (       d  f       g = f)Nr  r  rj   )rN   r   r  r  r   r@  rA  rt  s     r   test_clear_at_no_bp&BreakpointTestCase.test_clear_at_no_bp  sD    ''Ha=)A
 t_hE __s   &A
Ac                    [        5         [        5       nUR                  [        5      nUR	                  [        S5        U R                  UR                  5       US/05        [        5       nUR	                  [        S5        UR	                  [        S5        UR	                  [        S5        U R                  UR                  5       US/05        U R                  UR                  5       U/ SQ05        UR                  [        S5        U R                  UR                  5       US/05        U R                  UR                  5       U/ SQ05        [        5       nU R                  UR                  5       US/05        U R                  UR                  5       U/ SQ05        U R                  UR                  5       U/ SQ05        UR                  [        S5        U R                  UR                  5       US/05        U R                  UR                  5       USS/05        U R                  UR                  5       U/ SQ05        [        5       nUR	                  [        S5        U R                  UR                  5       US/05        U R                  UR                  5       USS/05        U R                  UR                  5       U/ SQ05        U R                  UR                  5       U/ SQ05        [        5         [        5       nUR	                  [        S	5        U R                  UR                  5       US/05        U R                  UR                  5       USS/05        U R                  UR                  5       U/ SQ05        U R                  UR                  5       U/ SQ05        U R                  UR                  5       US	/05        g )
Nrj   r   r   re  )rj   r   r   re  )r   r   re  r\  )r   re  r\  r]  )r$   r=   r   rN   rX   assertEqualget_all_breaksrx   )rC   db1ry   db2db3db4db5s          r   (test_load_bps_from_previous_Bdb_instance;BreakpointTestCase.test_load_bps_from_previous_Bdb_instance  s   eH%h"++-s|<eh"h"h"++-s|<++-|/DE!$++-s|<++-y/ABe++-s|<++-y/AB++-y/AB!$++-s|<++-1v?++-y/ABeh"++-s|<++-1v?++-y/AB++-y/ABeh"++-s|<++-1v?++-y/AB++-y/AB++-s|<r   r  N)r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r  r    s?    )FJ-.-8-(-&-*-6-2F(=r   r  c                   $    \ rS rSrSrS rS rSrg)RunTestCasei  z Test run, runeval and set_trace.c                     Sn/ SQU l         [        U 5       nUR                  [        [        R
                  " U5      SS5      5        S S S 5        g ! , (       d  f       g = f)N
            lno = 2
        )r3   r   <module>r9  r   r   r   rr  <string>execr   r  runcompilerO  rP  rC   r^   r  s      r   test_run_stepRunTestCase.test_run_step  sE    
 t_JJwxt4j&IJ __   1A
Ac                    Sn[         U0n[        U5         / SQU l        SS Kn[	        U 5       nUR                  S[        5       [        5       5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nr  )
)r3   rj   r   r9  )r   r   rZ  r9  )r3   r   rZ  r9  )r   r   rZ  r9  )r   rj   r   rr  r   ztest_module_for_bdb.main())r  r?  r   rX  r  runevalrO   locals)rC   r^   rB  rX  r  s        r   test_runeval_stepRunTestCase.test_runeval_step	  sg      'G$DO '4F;WYQ ! %$ ! %$s"   A5$A$A5$
A2	.A55
Br  N)r   r   r   r   r   r  r  r   r   r   r   r  r    s    *
KRr   r  c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)IssuesTestCasei  zTest fixed bdb issues.c                 $   SnSn[         USU0n[        U5         S[        SS5      SSS	S
SSS0/ 44SSSSS/
U l        [	        U 5       nUR                  [        5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nz
            from test_module_for_bdb_2 import func
            def main():
                func()
                lno = 5
        z9
            def func():
                lno = 3
        test_module_for_bdb_2r  r]   ztest_module_for_bdb_2.pyr  r|  r3   r   rj   r9  )r   r   r]   )r3   r\  rZ  rr  )r  r?  rW  r   r  r@  rA  )rC   code_1code_2rB  r  s        r   +test_step_at_return_with_no_trace_in_caller:IssuesTestCase.test_step_at_return_with_no_trace_in_caller  s    
 #V
 G$+!&*DE+.FaUBK0*%*#*DO 4F|, ! %$ ! %$s#   /B	A0B0
A>	:B
Bc                    Sn[         U0nS H  nU R                  US9   [        U5         S[        S[        5      SSSS	SS
S
0/ 44U4/U l        US:X  a(  U R
                  R                  SSS[        4SSS/5        OU R
                  R                  SS/5        [        U 5       nUR                  [        5        S S S 5        S S S 5        S S S 5        M     g ! , (       d  f       N#= f! , (       d  f       N,= f! , (       d  f       M  = f)Nz
            def test_gen():
                yield 0
                lno = 4
                return 123

            def main():
                it = test_gen()
                next(it)
                next(it)
                lno = 11
        )r  r	  r   rz  r  test_genr  r|  r3   r   rj   r   r   
   rZ  r9  )r   r  rZ  rr  r3   re  r  )r  r~  r?  rW  r  r   r  r1  r  r@  rA  )rC   r^   rB  r  r  s        r   #test_next_until_return_in_generator2IssuesTestCase.test_next_until_return_in_generator=  s    
  '3Hx0#G,3)*6GH3nJ!A<xl	'DO  8+..)2v}Ey3z ..4jB #4F|4 )% - 10 4( )% -, 10s;   C;A;C*&C	<C*C;
C'#C**
C84C;;
D
	c                 @   Sn[         U0n[        U5         S[        S[        5      SSSSSSS0/ 44S	S
S	SS	SS	SSS[        4SSS/U l        [        U 5       nUR                  [        5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)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|  r3   r   rj   r8  r  )r3   r\  r  )r3   r]  r  r   	   rZ  r9  )r3      rZ  rr  	r  r?  rW  r  r1  r   r  r@  rA  r  s       r   'test_next_command_in_generator_for_loop6IssuesTestCase.test_next_command_in_generator_for_loopf  s      'G$+!*.?@+J!A4'''a7$DO 4F|, ! %$ ! %$s$   ABA>-B>
B	B
Bc                 8   Sn[         U0n[        U5         S[        S[        5      SSSSSSS0/ 44S	S
S	SSS[        4SSS/U l        [        U 5       nUR                  [        5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)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
        r  r  r  r|  r3   r^  rj   r8  )r3      r  r   r   rZ  r9  r3      rZ  rr  r!  r  s       r   /test_next_command_in_generator_with_subiterator>IssuesTestCase.test_next_command_in_generator_with_subiterator  s      'G$+!*.?@+.J!A4*'*b&-8*$*	DO 4F|, ! %$ ! %$s#   =BA:)B:
B	B
Bc                 H   Sn[         U0n[        U5         S[        S[        5      SSSSSSS0/ 44S	S
SS[        4S	S
SS[        4SSS/U l        [        U 5       nUR                  [        5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nr%  r  test_subgenr  r|  r3   r   rj   r  r   r^  r  r   rZ  r9  r'  rr  r!  r  s       r   1test_return_command_in_generator_with_subiterator@IssuesTestCase.test_return_command_in_generator_with_subiterator  s      'G$+!-1BC+nMQqE2;7la];lb&-8j$j	DO 4F|, ! %$ ! %$s$   ABB1B
B	B
B!c                     Sn/ SQU l         [        U 5       nUR                  [        [        R
                  " U5      SS5      5        S S S 5        g ! , (       d  f       g = f)Nr  )r  r9  r  r8  r  r  r  r  s      r   test_next_to_botframe$IssuesTestCase.test_next_to_botframe  sE    
 t_JJwxt4j&IJ __r
  r  N)r   r   r   r   r   r  r  r"  r)  r-  r0  r   r   r   r   r  r    s%     -<'5R->->->Kr   r  c                       \ rS rSrS rSrg)TestRegressionsi  c                     U R                  S[        5       R                  [        R                  " 5       S 45      5        g )NzWarning: lineno is None)assertInr=   format_stack_entryr  	_getframer~   s    r   !test_format_stack_entry_no_lineno1TestRegressions.test_format_stack_entry_no_lineno  s-    /e../FG	Ir   r   N)r   r   r   r   r8  r   r   r   r   r3  r3    s    Ir   r3  __main__r    )0r   r  r!   r  r/   unittestrO  rP   rQ  
contextlibr   	itertoolsr   r   test.supportr   r   r   	Exceptionr
   r   r   r   r   r$   r;   r=   r   r  rE  r?  rN   rW  r  r  rA  rc  r_  r`  TestCaser=  rl  r  r  r  r3  r   rZ  r   r   r   <module>rA     sZ  0d  
 	     % $ & " # $9 # E| E H\ H A, A '*>/$(( >/@{1S {1z-/ -/^H)T    #+e$ = $%' 
38$$ 3~'L ~'@i= i=X R,  RDrK\ rKjIh'' I zMMO r   