
    /hh$p                     ^   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rSSK	r	 SSK
r
SSKJrJrJrJrJrJrJr  SSKJr  SSKJrJr  SSKJr  SSKJrJr  \S   rS	 rS
 rS r  " S S\RB                  5      r"S r# " S S\RB                  5      r$ " S S\RB                  5      r%S r&S r'S r(S r)S r*\+" 5       4S jr,S r-S r.S r/ " S S\RB                  5      r0\" SS9(       Ga  \
Gb  \
Rb                  r2\
Rf                  " S\
Rh                  5      r5\2Rl                  r7\54\7l8        \
Rr                  \7l:        \2Rv                  r<\
Rz                  \
Rr                  \
Rh                  4\<l8        \
R|                  \<l:        \2R~                  r@\
Rz                  \
Rr                  \
R                  " \
Rh                  5      4\@l8        \
R|                  \@l:        SqBS  rC\5" \C5      rD\7" \D5      rE " S! S"\RB                  5      rFS# rG\HS$:X  a  \R                  " 5         gg! \ a    Sr
 GNf = f)%a  This module includes tests of the code object representation.

>>> def f(x):
...     def g(y):
...         return x + y
...     return g
...

>>> dump(f.__code__)
name: f
argcount: 1
posonlyargcount: 0
kwonlyargcount: 0
names: ()
varnames: ('x', 'g')
cellvars: ('x',)
freevars: ()
nlocals: 2
flags: 3
consts: ('None', '<code object g>')

>>> dump(f(4).__code__)
name: g
argcount: 1
posonlyargcount: 0
kwonlyargcount: 0
names: ()
varnames: ('y',)
cellvars: ()
freevars: ('x',)
nlocals: 1
flags: 19
consts: ('None',)

>>> def h(x, y):
...     a = x + y
...     b = x - y
...     c = a * b
...     return c
...

>>> dump(h.__code__)
name: h
argcount: 2
posonlyargcount: 0
kwonlyargcount: 0
names: ()
varnames: ('x', 'y', 'a', 'b', 'c')
cellvars: ()
freevars: ()
nlocals: 5
flags: 3
consts: ('None',)

>>> def attrs(obj):
...     print(obj.attr1)
...     print(obj.attr2)
...     print(obj.attr3)

>>> dump(attrs.__code__)
name: attrs
argcount: 1
posonlyargcount: 0
kwonlyargcount: 0
names: ('print', 'attr1', 'attr2', 'attr3')
varnames: ('obj',)
cellvars: ()
freevars: ()
nlocals: 1
flags: 3
consts: ('None',)

>>> def optimize_away():
...     'doc string'
...     'not a docstring'
...     53
...     0x53

>>> dump(optimize_away.__code__)
name: optimize_away
argcount: 0
posonlyargcount: 0
kwonlyargcount: 0
names: ()
varnames: ()
cellvars: ()
freevars: ()
nlocals: 0
flags: 3
consts: ("'doc string'", 'None')

>>> def keywordonly_args(a,b,*,k1):
...     return a,b,k1
...

>>> dump(keywordonly_args.__code__)
name: keywordonly_args
argcount: 2
posonlyargcount: 0
kwonlyargcount: 1
names: ()
varnames: ('a', 'b', 'k1')
cellvars: ()
freevars: ()
nlocals: 3
flags: 3
consts: ('None',)

>>> def posonly_args(a,b,/,c):
...     return a,b,c
...

>>> dump(posonly_args.__code__)
name: posonly_args
argcount: 3
posonlyargcount: 2
kwonlyargcount: 0
names: ()
varnames: ('a', 'b', 'c')
cellvars: ()
freevars: ()
nlocals: 3
flags: 3
consts: ('None',)

    N)cpython_onlycheck_impl_detailrequires_debug_ranges
gc_collectPy_GIL_DISABLEDsuppress_immortalization skip_if_suppress_immortalization)assert_python_ok)threading_helperimport_helper)instructions_with_positions)opmapopnameCOPY_FREE_VARSc              #      #    U  H;  n[        U5      nUR                  S5      (       a  SUR                  -  v   M7  Uv   M=     g7f)z.Yield a doctest-safe sequence of object reprs.z<code objectz<code object %s>N)repr
startswithco_name)teltrs      7/opt/python-3.13.8/usr/lib/python3.13/test/test_code.pyconstsr      s;     I<<''$s{{22G s   AAc           
          S H"  n[        U< S[        U SU-   5      < 35        M$     [        S[        [        U R                  5      5      5        g)z1Print out a text representation of a code object.)
nameargcountposonlyargcountkwonlyargcountnamesvarnamescellvarsfreevarsnlocalsflagsz: co_zconsts:N)printgetattrtupler   	co_consts)coattrs     r   dumpr,      sB    = 	$EDL 9:;= 
)U6",,/01    c                 :    S[        5       R                  U5       3$ )NzForeign getitem: )super__getitem__)selfis     r   external_getitemr3      s    uw2215677r-   c                       \ rS rSr\S 5       r\S 5       rS rS rS r	S r
S rS	 rS
 rS r\" 5       S 5       rS rS r\" 5       S 5       rS rS rS rS r\S 5       rSrg)CodeTest   c                 r   [         R                  " S5      nUR                  SSS5      nU R                  UR                  S5        U R                  UR
                  S5        U R                  UR                  S5        U R                  [        5         [        U5        S S S 5        g ! , (       d  f       g = f)N	_testcapifilenamefuncname   )
r   import_modulecode_newemptyassertEqualco_filenamer   co_firstlinenoassertRaises	Exceptionexec)r1   r8   r*   s      r   test_newemptyCodeTest.test_newempty   s    !//<	$$ZR@4Z0**B/y)H *))s   B((
B6c                   ^^^ SSK Jm  S mS mUUU4S jn " S S[        5      nU" US[        5        UR                  nUR
                  S   R                  nU R                  XB5        U" / S	Q5      nU R                  US   S
5        g )Nr   )FunctionTypec                 $   ^  U 4S jR                   $ )Nc                     > T $ N 	__class__s   r   <lambda>ICodeTest.test_closure_injection.<locals>.create_closure.<locals>.<lambda>   s    Ir-   )__closure__rL   s   `r   create_closure7CodeTest.test_closure_injection.<locals>.create_closure   s    %222r-   c                 t    U R                  U R                  S-   [        [        S/5      U R                  -   S9$ )z9A new code object with a __class__ cell added to freevarsrL      )co_freevarsco_code)replacerU   bytesr   rV   )cs    r   new_code1CodeTest.test_closure_injection.<locals>.new_code   s7    99)GQVXfhiWjQklmluluQu9vvr-   c                    > T" UR                   5      nUR                  (       a   eT" U 5      nUR                  n[        XT" U[	        5       XU5      5        g rJ   )__code__rP   __defaults__setattrglobals)	clsr   fcodeclosuredefaultsrG   rQ   rZ   s	         r   add_foreign_method;CodeTest.test_closure_injection.<locals>.add_foreign_method   sH    AJJ'D}}$$$S)G~~HC|D')TWUVr-   c                       \ rS rSrSrg)-CodeTest.test_closure_injection.<locals>.List   rK   N__name__
__module____qualname____firstlineno____static_attributes__rK   r-   r   Listri          r-   rq   r0   )rT         zForeign getitem: 1)	typesrG   listr3   r0   rP   cell_contentsassertIsr>   )	r1   rf   rq   function	class_refobjrG   rQ   rZ   s	         @@@r   test_closure_injectionCodeTest.test_closure_injection   s     	'	3	w	W	4 	 	40@A ##((+99	i& 9oQ!56r-   c                    S nUR                   n[        U5      nU" UR                  UR                  UR                  UR
                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  UR                   UR"                  UR$                  UR&                  5        g )Nc                      g rJ   rK   rK   r-   r   func'CodeTest.test_constructor.<locals>.func   s    Dr-   )r]   typeco_argcountco_posonlyargcountco_kwonlyargcount
co_nlocalsco_stacksizeco_flagsrV   r)   co_namesco_varnamesr?   r   co_qualnamer@   co_linetableco_exceptiontablerU   co_cellvars)r1   r   r*   CodeTypes       r   test_constructorCodeTest.test_constructor   s    ]]8 	--,,



)),,#	(r-   c                     U R                  [        R                  R                  R                  [        R                  R
                  5        g rJ   )r>   r5   test_qualnamer]   r   rn   r1   s    r   r   CodeTest.test_qualname   s4    ""++77""//	
r-   c                    S nUR                   nS nUR                   nSSSSSSUR                  [        R                  -  4S	S
UR                  4SUR
                  4SSSSSSSUR                  44 H~  u  pVU R                  XVS9   UR                  " S0 XV0D6nU R                  [        Xu5      U5        [        R                  " U40 XV0D6nU R                  [        Xu5      U5        S S S 5        M     UR                  UR                  UR                  S9nU R                  UR                  UR                  5        U R                  UR                  UR                  5        [        R                  " X$R                  UR                  S9nU R                  UR                  UR                  5        U R                  UR                  UR                  5        g ! , (       d  f       GMx  = f)Nc                  
    Sn U $ NrT   rK   xs    r   r   #CodeTest.test_replace.<locals>.func       AHr-   c                      Sn SnU $ )Nrs   rt   rK   )yzs     r   func2$CodeTest.test_replace.<locals>.func2  s    AAHr-   )r   r   )r   r   )r   r   )r   rT   )r   rT   r   )r@   d   rV   r)   )r   )myname)r   )spam)rU   )freevar)r   )cellvar)r?   newfilename)r   newnamer   )r+   value)r   r   rK   )r]   r   inspectCO_COROUTINErV   r)   r   subTestrW   r>   r'   copyr   r   )r1   r   rc   r   code2r+   r   rZ   s           r   test_replaceCodeTest.test_replace   s   	 }}	  %$)=)==>#&%//*%&))*"U//0!
KD$ 45<<84-8  !8%@<<>>  !8%@	 65%
0 <<E,=,=+0+;+;   =--u/@/@A,,e.>.>?<<2C2C+0+;+;=--u/@/@A,,e.>.>? 65s   A"G
G*	c                    S nUR                   nUR                  S:  d   e[        U5      nS H  nU R                  [        5         U" UR
                  UR                  UR                  UR                  U-   UR                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  UR                   UR"                  UR$                  UR&                  UR(                  UR*                  5        S S S 5        M     U R                  [        5         UR-                  UR                  S-
  S9  S S S 5        U R                  [        5         UR-                  UR                  S-   S9  S S S 5        g ! , (       d  f       GMz  = f! , (       d  f       N\= f! , (       d  f       g = f)Nc                  
    Sn U $ r   rK   r   s    r   r   ,CodeTest.test_nlocals_mismatch.<locals>.func,  r   r-   r   )rT   rT   )r   )r]   r   r   rA   
ValueErrorr   r   r   r   r   rV   r)   r   r   r?   r   r   r@   r   r   rU   r   rW   )r1   r   r*   r   diffs        r   test_nlocals_mismatchCodeTest.test_nlocals_mismatch+  sS   	 ]]}}q    8D"":...---**--% /. . z*JJ"--!"3J4 +z*JJ"--!"3J4 +*1 /., +***s%   CF9F,3F=
F)	,
F:=
Gc                 b    S nUR                   nUR                  SS9nU R                  X#5        g )Nc                    ^  U 4S j$ )Nc                     > T $ rJ   rK   args   r   rN   BCodeTest.test_shrinking_localsplus.<locals>.func.<locals>.<lambda>T  s    3r-   rK   r   s   `r   r   0CodeTest.test_shrinking_localsplus.<locals>.funcS  s	    r-   r   )r   )r]   rW   r>   )r1   r   rc   newcodes       r   test_shrinking_localsplus"CodeTest.test_shrinking_localsplusP  s.    	}},,v,.'r-   c                     S nUR                   R                  SS9=p#U R                  [        UR	                  5       5      / 5        g )Nc                      g rJ   rK   rK   r-   r   r   +CodeTest.test_empty_linetable.<locals>.funcZ      r-   r-   r   )r]   rW   r>   rv   co_lines)r1   r   rZ   rc   s       r   test_empty_linetableCodeTest.test_empty_linetableY  s?    	--//S/AAh//12B7r-   c                     S nU R                  [        5         UR                  R                    S S S 5        g ! , (       d  f       g = f)Nc                      g rJ   rK   rK   r-   r   r   3CodeTest.test_co_lnotab_is_deprecated.<locals>.func`  r   r-   )assertWarnsDeprecationWarningr]   	co_lnotab)r1   r   s     r   test_co_lnotab_is_deprecated%CodeTest.test_co_lnotab_is_deprecated_  s1    	 01MM## 211s	   9
Ac                    S nU R                  [        S   S5        UR                  R                  SUR                  R                  SS  -   S9Ul        SnU R                  [        U5         U" 5         S S S 5        g ! , (       d  f       g = f)Nc                      g rJ   rK   rK   r-   r   foo+CodeTest.test_invalid_bytecode.<locals>.foog  r   r-      z<229>   rT   rV   zunknown opcode 229)r>   r   r]   rW   rV   assertRaisesRegexSystemError)r1   r   msgs      r   test_invalid_bytecodeCodeTest.test_invalid_bytecodef  s{    	 	g. ||++cll221266 , 8 ###K5E 655s   -A>>
Bc                    SS K n0 n[        [        R                  " S5      U5        US   nUR                  nUR
                  R                  n/ n[        UR                  " U5      UR                  5       5       HK  u  pxU R                  UR                  S 5      / SQ5        [        U5      (       a  M:  UR                  U5        MM     U R                  U V	s/ s H  n	U	R                  U	R                   4PM     sn	/ SQ5        g s  sn	f )Nr   zX        try:
            1/0
        except Exception as e:
            exc = e
        exc)r   rt      ))PUSH_EXC_INFON)
LOAD_CONSTN)
STORE_NAMEe)DELETE_NAMEr   RERAISErT   )COPYrt   )
POP_EXCEPTNr   )disrC   textwrapdedent__traceback__tb_framef_coder   get_instructionsco_positionsassertIncountanyappendr>   r   argval)
r1   r   	namespacer   	tracebackrc   artificial_instructionsinstr	positionsinstructions
             r   )test_co_positions_artificial_instructions2CodeTest.test_co_positions_artificial_instructionsu  s    	X__  
 	 %%	!!(("$ ;  &(9(9(;!
E MM)//$/;y>>'..u5!
 	 $;#:K ##[%7%78#:		
s   "Dc                 L    [         R                  " S5      n[        SSSU5        g )N#  
            def f():
                pass

            positions = f.__code__.co_positions()
            for line, end_line, column, end_column in positions:
                assert line == end_line
                assert column is None
                assert end_column is None
            z-Xno_debug_ranges-cr   r   r
   r1   rc   s     r   6test_endline_and_columntable_none_when_no_debug_ranges?CodeTest.test_endline_and_columntable_none_when_no_debug_ranges  s(      	  	 	0$=r-   c                 F    [         R                  " S5      n[        SUSS9  g )Nr  r  1)PYTHONNODEBUGRANGESr  r  s     r   :test_endline_and_columntable_none_when_no_debug_ranges_envCCodeTest.test_endline_and_columntable_none_when_no_debug_ranges_env  s#     	  	 	t=r-   c                     S nUR                   R                  SS9nUR                  5       nU H5  u  pEpgU R                  U5        U R	                  XRR
                  S-   5        M7     g )Nc                      Sn g r   rK   r   s    r   r   8CodeTest.test_co_positions_empty_linetable.<locals>.func  s    Ar-   r-   r   rT   )r]   rW   r   assertIsNoner>   r@   )r1   r   rZ   r   lineend_linecolumn
end_columns           r   !test_co_positions_empty_linetable*CodeTest.test_co_positions_empty_linetable  sb    	==((c(:))+	2;.DFd#X'>'>'BC 3<r-   c                 H   S nUR                   nUR                  SS9nUR                  SS9nUR                  SS9nU R                  X#5        U R                  X$5        U R                  X%5        U R                  X45        U R                  X55        U R                  XE5        g )Nc                       [        5         [        5         [        5         g !   [        5          N= f! [        5         f = frJ   )arY   bdrK   r-   r   rb   &CodeTest.test_code_equality.<locals>.f  s,      s   
! 
2 /2 >r-   r   )r   )r]   rW   assertNotEqual)r1   rb   code_acode_bcode_ccode_ds         r   test_code_equalityCodeTest.test_code_equality  s    	 S1#6#6F+F+F+F+F+F+r-   c                 *   S R                   nS R                   nU R                  X5        U R                  [        U5      [        U5      5        UR                  SS9nU R                  X5        U R                  [        U5      [        U5      5        g )Nc                      gr   rK   rK   r-   r   rN   :CodeTest.test_code_hash_uses_firstlineno.<locals>.<lambda>      ar-   c                      gr   rK   rK   r-   r   rN   r&    r'  r-      )r@   )r]   r  hashrW   )r1   c1c2c3s       r   test_code_hash_uses_firstlineno(CodeTest.test_code_hash_uses_firstlineno  st    !!!!B#DHd2h/ZZrZ*B#DHd2h/r-   c                 Z   SSS.S jR                   nU R                  UR                  S5        U R                  UR                  S5        U R                  UR                  S5        UR                  SSS9nU R                  X5        U R                  [        U5      [        U5      5        g )NrT   )r   wc                    gr   rK   )r   r   r   r1  s       r   rN   4CodeTest.test_code_hash_uses_order.<locals>.<lambda>  s    qr-   rs   r   )r   r   )r]   r>   r   r   r   rW   r  r*  )r1   rY   swappeds      r   test_code_hash_uses_order"CodeTest.test_code_hash_uses_order  s     A(22*--q1,,a0))qA)FA'DGT']3r-   c                     S R                   nS R                   nUR                  UR                  S9nU R                  X5        U R                  [	        U5      [	        U5      5        g )Nc                 
    X-   $ rJ   rK   r   r   s     r   rN   7CodeTest.test_code_hash_uses_bytecode.<locals>.<lambda>      !%r-   c                 
    X-  $ rJ   rK   r9  s     r   rN   r:    r;  r-   r   )r]   rW   rV   r  r*  )r1   rY   r  r+  s       r   test_code_hash_uses_bytecode%CodeTest.test_code_hash_uses_bytecode  sR    ))))YYqyyY)A"DGT"X.r-   c                     [        SSS5      n[        SSS5      nS[        R                  " 5       l        [        R                  " S 5        [        US/ 05        [        US/ 05        U R                  X5        [        R                  " S5        g)	zGH-109052

Make sure the instrumentation doesn't affect the code equality
The validity of this test relies on the fact that "x is x" and
"x in x" have only one different instruction and the instructions
have the same argument.

zx is xz
example.pyevalzx in xTc                      g rJ   rK   )argss    r   rN   ?CodeTest.test_code_equal_with_instrumentation.<locals>.<lambda>
  s    4r-   r   N)compilesys	_getframef_trace_opcodessettracerC   r  )r1   code1r   s      r   $test_code_equal_with_instrumentation-CodeTest.test_code_equal_with_instrumentation  sq     ,7,7*.''(US"IUS"IE)Tr-   rK   N)rl   rm   rn   ro   r   rD   r|   r   r   r   r   r   r   r   r   r   r   r  r  r  r"  r.  r5  r=  rJ  rp   rK   r-   r   r5   r5      s      7 7@(2
,@\#5J(8$ -
 -
^>>  D D,*04/  r-   r5   c                 D    U [         R                  " SU -   S-   SS 5      L $ )N_rT   r   )rE  intern)ss    r   
isinternedrP    s%    

C!GcM1R0111r-   c                      \ rS rSrS rS rS r\S 5       r\S 5       r	\S 5       r
\S 5       r\\R                  " \S	5      S
 5       5       r\\R                   " \S5      \" 5       S 5       5       5       r\S 5       rSrg)CodeConstsTesti  c                 l    U H  nX2:X  d  M
  Us  $    U R                  X!5        U R                  S5        g )NzShould never be reached)r   fail)r1   r   r   vs       r   
find_constCodeConstsTest.find_const  s1    Az  	e$		+,r-   c                 R    [        U5      (       d  U R                  SU< S35        g g )NString z is not internedrP  rT  r1   rO  s     r   assertIsInternedCodeConstsTest.assertIsInterned  s    !}}IIQ89 r-   c                 R    [        U5      (       a  U R                  SU< S35        g g )NrY  z is internedrZ  r[  s     r   assertIsNotInterned"CodeConstsTest.assertIsNotInterned!  s    a==II45 r-   c                 x    [        SSS5      nU R                  UR                  S5      nU R                  U5        g )Nzres = "str_value"?rC   	str_valuerD  rV  r)   r\  r1   r*   rU  s      r   test_interned_string#CodeConstsTest.test_interned_string%  s3    (#v6OOBLL+6a r-   c                 ~    [        SSS5      nU R                  UR                  S5      nU R                  US   5        g )Nzres = ("str_value",)rb  rC   rc  r   rd  re  s      r   test_interned_string_in_tuple,CodeConstsTest.test_interned_string_in_tuple+  s7    +S&9OOBLL.9ad#r-   c                     [        SSS5      nU R                  UR                  [        S5      5      nU R	                  [        U5      S   5        g )Nzres = a in {"str_value"}rb  rC   ri  r   )rD  rV  r)   	frozensetr\  r(   re  s      r   !test_interned_string_in_frozenset0CodeConstsTest.test_interned_string_in_frozenset1  s@    /f=OOBLL)N*CDeAhqk*r-   c                 :    SS jnU R                  U" 5       5        g )Nc                     U $ rJ   rK   )r  s    r   rb   6CodeConstsTest.test_interned_string_default.<locals>.f9  s    Hr-   ri  )r\  r1   rb   s     r   test_interned_string_default+CodeConstsTest.test_interned_string_default7  s    	ac"r-   z0free-threaded build interns all string constantsc                 x    [        SSS5      nU R                  UR                  S5      nU R                  U5        g )Nzres = "str\0value!"rb  rC   z
str value!)rD  rV  r)   r_  re  s      r   test_interned_string_with_null-CodeConstsTest.test_interned_string_with_null=  s5     +S&9OOBLL-8  #r-   zdoes not intern all constantsc                     0 n[        [        R                  " S5      U5        [        [        R                  " S5      U5        U R                  US   " 5       US   " 5       L 5        g )NzP
            def func1():
                return (0.0, (1, 2, "hello"))
        zP
            def func2():
                return (0.0, (1, 2, "hello"))
        func1r   )rC   r   r   
assertTrue)r1   r`   s     r   test_interned_constants&CodeConstsTest.test_interned_constantsD  sh     X__   	
 	X__   	
 	(*gg.>.@@Ar-   c                 .    " S S5      n " S S[         5      n[        SSS5      nUR                  SU" 5       U" S5      U" S5      4S	9nU R                  UR                  S   U5        U R                  UR                  S
   UR                  S   5        g )Nc                       \ rS rSrS rSrg)9CodeConstsTest.test_unusual_constants.<locals>.Unhashablei\  c                     [        S5      e)Nzunhashable type)	TypeErrorr   s    r   __hash__BCodeConstsTest.test_unusual_constants.<locals>.Unhashable.__hash__]  s     122r-   rK   N)rl   rm   rn   ro   r  rp   rK   r-   r   
Unhashabler  \  s    3r-   r  c                       \ rS rSrSrg)4CodeConstsTest.test_unusual_constants.<locals>.MyInti`  rK   Nrk   rK   r-   r   MyIntr  `  rr   r-   r  za = 1z<string>rC   rT   )r)   rs   rt   )intrD  rW   assertIsInstancer)   r>   )r1   r  r  rc   s       r   test_unusual_constants%CodeConstsTest.test_unusual_constantsW  s    
	3 	3	C 	 w
F3||q*,a%(&K|LdnnQ/<*DNN1,=>r-   rK   N)rl   rm   rn   ro   rV  r\  r_  r   rf  rj  rn  rt  unittestskipIfr   rw  
skipUnlessr	   r|  r  rp   rK   r-   r   rR  rR    s    -:6 ! !
 $ $
 + +
 # #
 ___&XY$ Z $
 *IJ%'B ( K B  ? ?r-   rR  c                   .    \ rS rSr\" 5       S 5       rSrg)CodeWeakRefTestii  c                 d  ^  0 n[        S[        5       U5        US   nAST l        U 4S jn[        R                  " UR
                  U5      nT R                  [        U" 5       5      5        A[        5         T R                  [        U" 5       5      5        T R                  T R                  5        g )Nzdef f(): passrb   Fc                    > STl         g )NTcalled)rc   r1   s    r   callback,CodeWeakRefTest.test_basic.<locals>.callbacku  s
    DKr-   )
rC   r`   r  weakrefrefr]   r{  boolr   assertFalse)r1   r   rb   r  coderefs   `    r   
test_basicCodeWeakRefTest.test_basick  s     	_gi3cN	 ++ajj(3WY(gi)$r-   r  N)rl   rm   rn   ro   r   r  rp   rK   r-   r   r  r  i  s    %  %r-   r  c                     [        U 5      $ rJ   )next)its    r   readr    s    8Or-   c                     [        U 5      nUS-  nSnUS-  (       a&  [        U 5      nUS-  nX!S-  U-  -  nUS-  (       a  M&  U$ )N?   r   @      )r  )r  r  valshifts       r   read_varintr    sT    RA
b&CE
b&H
" b&& Jr-   c                 B    [        U 5      nUS-  (       a  US-	  * $ US-	  $ r   )r  )r  uvals     r   read_signed_varintr    s(    r?Dax|qyr-   c              #     #    U R                   n[        U R                  5      n  [        U5      nUS-	  S-  n US-  S-   nU S:X  a
  XS S S S 4v   OU S:X  aW  [        U5      nX-  nU[        U5      -   n[        U5      nUS:X  a  S nOUS-  n[        U5      nUS:X  a  S nOUS-  nXXXx4v   OU S:X  a  [        U5      nX-  nXXS S 4v   ObU S;   a'  U S	-
  nX-  n[        U5      n	[        U5      n
XXX4v   O5SU s=::  a  S	:  d   e   e[        U5      nU S-  US
-	  -  n	XXXUS-  -   4v   GM  ! [         a     g f = f7f)Nrt   r;      rT      r      )
         r  r   )r@   iterr   r  StopIterationr  r  )rc   r  r  
first_bytelength
line_deltar  colend_colr  r  second_bytes               r   parse_location_tabler    s    D	d	 B
	bJ a2%q.A%2:tT488RZ+B/JDk"o-Hb/Caxq!"oG!|1>>RZ+B/JDT488\!JD"XFbJV@@NN#N#Nr(KQY+"23FV{R?O5PQQM   		s(   #ED1 D E1
D>;E=D>>Ec              #   h   #    [        U 5       H  u  pp4pV[        U5       H	  nX4XV4v   M     M!     g 7frJ   )r  range)rc   rM  r  r  r  r  r  s          r   positions_from_location_tabler    s5     3G3M/43vA300  4Ns   02c              #   8   #    U  H  nX!:w  d  M
  Uv   UnM     g 7frJ   rK   )lstprevitems      r   dedupr    s     <JD s   	c                 &    [        S U  5       5      $ )Nc              3   .   #    U  H  u  n    o!v   M     g 7frJ   rK   ).0lrM  s      r   	<genexpr>&lines_from_postions.<locals>.<genexpr>  s     1y|1ays   )r  )r   s    r   lines_from_postionsr    s    1y111r-   c                  Z    SW -   n[         [        -   [        -   n U(       a  [        $ [        $ )z






    r   )r  r  r  qp)r   r   s     r   
misshappenr    sK     	
 	
		
  	
	
 	  	
   	r-   c                  6    SR                  5       n [        5       e)Nz
            )stripr   )!example_report_generation_messages    r   bug93662r    s    eg & ,r-   c                   <    \ rS rSrS rS rS rS r\S 5       r	Sr
g)	CodeLocationTesti  c                    [        UR                  R                  5       5      n[        [        UR                  5      5      n[	        X#5       H  u  pEU R                  XE5        M     U R                  [        U5      [        U5      5        g rJ   )rv   r]   r   r  zipr>   len)r1   r   pos1pos2l1l2s         r   check_positions CodeLocationTest.check_positions  sc    DMM..011$--@A$oFBR$ &TCI.r-   c                     U R                  [        5        U R                  [        5        U R                  [        5        g rJ   )r  r  r  r  r   s    r   test_positionsCodeLocationTest.test_positions  s-    12Z(X&r-   c                    UR                   nUR                  5        VVs/ s H  u    p4UPM
     nnnU R                  U[        [	        U5      5      5        [        [        [        U5      5      5      n[        XV5       H  u  pxU R                  Xx5        M     U R                  [        U5      [        U5      5        g s  snnf rJ   )	r]   r   r>   rv   r  r  r  r  r  )	r1   r   r*   rM  r  lines1lines2r  r  s	            r   check_linesCodeLocationTest.check_lines  s    ]])+7:1a$7eFm!45)*G*KLM&)FBR$ *Vc&k2 8s   B=c                     U R                  [        5        U R                  [        5        U R                  [        5        g rJ   )r  r  r  r  r   s    r   
test_linesCodeLocationTest.test_lines  s-    -.$"r-   c                    S nSnUR                   R                  SS[        [        R                  S   S[        R                  S   S[        R                  S   S/5      [        S	US
-  -  S-  S/5      S9Ul         U R                  [        U5        U R                  [        UR                   R                  5       5      S
S/-  5        g )Nc                      g rJ   rK   rK   r-   r   rb   /CodeLocationTest.test_code_new_empty.<locals>.f  r   r-   r  rT   *   RESUMEr   LOAD_ASSERTION_ERRORRAISE_VARARGS   rt   rs   )r   r@   rV   r   )r  r  NN)
r]   rW   rX   r   r   rA   AssertionErrorr>   rv   r   )r1   rb    PY_CODE_LOCATION_INFO_NO_COLUMNSs      r   test_code_new_empty$CodeLocationTest.test_code_new_empty  s    
	+-(ZZ''IIh'II45qIIo. 71<> 	 ( 

& 	.!,((*+%&&	
r-   rK   N)rl   rm   rn   ro   r  r  r  r  r   r  rp   rK   r-   r   r  r    s*    /'
3#
 
 
r-   r  T)cpythonc                     U q g rJ   )
LAST_FREED)ptrs    r   myfreer  I  s    
r-   c                       \ rS rSrS rS rS r\" 5       S 5       rS r	\
R                  " 5       \" 5       S 5       5       rSrg	)
CoExtraiP  c                     [        S5      $ )Nz	lambda:42)r@  r   s    r   get_funcCoExtra.get_funcQ  s     $$r-   c           	          U R                  5       nU R                  [        [        S[        [
        R                  " S5      5        U R                  [        [        S[        [
        R                  " S5      5        g )Nr  r   )r  rA   r   SetExtra
FREE_INDEXctypesc_voidpGetExtrars  s     r   test_get_non_codeCoExtra.test_get_non_codeW  sQ    Ak8R$nnS13k8R$nnS13r-   c           	      ,   U R                  5       nU R                  [        [        UR                  [
        S-   [        R                  " S5      5        U R                  [        UR                  [
        S-   [        R                  " S5      5      S5        g )Nr   r   )
r  rA   r   r  r]   r  r  r  r>   r  rs  s     r   test_bad_indexCoExtra.test_bad_index_  sh    Ak8QZZ(nfnnS.ACXajj*S.$nnS13457r-   c                     U R                  5       n[        UR                  [        [        R
                  " S5      5        A[        5         U R                  [        S5        g )Nr   )	r  r  r]   r  r  r  r   r>   r  rs  s     r   test_free_calledCoExtra.test_free_calledf  s@     AQZZV^^C-@ALZ-r-   c                    U R                  5       n[        R                  " 5       n[        UR                  [
        [        R                  " S5      5        [        UR                  [
        [        R                  " S5      5        U R                  [        S5        [        R                  " 5       n[        UR                  [
        U5        U R                  UR                  S5        Ag )N   i,  )
r  r  r  r  r]   r  r>   r  r  r   )r1   rb   extras      r   test_get_setCoExtra.test_get_setq  s    ANN$EQZZV^^C-@AQZZV^^C-@AZ-NN$EQZZU3U[[#.r-   c                 F   U R                  5       n " S S[        R                  5      n[        UR                  [
        [        R                  " S5      5        U" X5      nAUR                  5         UR                  5         [        5         U R                  [        S5        g )Nc                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )6CoExtra.test_free_different_thread.<locals>.ThreadTesti  c                 :   > [         TU ]  5         Xl        X l        g rJ   )r/   __init__rb   test)r1   rb   r  rM   s      r   r  ?CoExtra.test_free_different_thread.<locals>.ThreadTest.__init__  s    G$&F $Ir-   c                 t    U ? [        5         [        (       d!  U R                  R	                  [
        S5        g g )N  )rb   r   r   r  r>   r  r   s    r   run:CoExtra.test_free_different_thread.<locals>.ThreadTest.run  s,    L +?		--j#> +r-   )rb   r  )rl   rm   rn   ro   r  r  rp   __classcell__rL   s   @r   
ThreadTestr    s    %? ?r-   r  r  )r  	threadingThreadr  r]   r  r  r  startjoinr   r>   r  )r1   rb   r  tts       r   test_free_different_thread"CoExtra.test_free_different_thread  sp    
 A?Y-- ? QZZV^^C-@AA$BHHJGGILZ-r-   rK   N)rl   rm   rn   ro   r  r  r	  r   r  r  r   requires_working_threadingr%  rp   rK   r-   r   r  r  P  sU    	%	3	7 
"	#	. 
$	.	  
	4	4	6	!	#	. 
$ 
7	.r-   r  c                 N    UR                  [        R                  " 5       5        U$ rJ   )addTestdoctestDocTestSuite)loadertestspatterns      r   
load_testsr/    s    	MM'&&()Lr-   __main__)J__doc__r   r   rE  r   r*  r  r   r  r   r  ImportErrortest.supportr   r   r   r   r   r   r	   test.support.script_helperr
   r   r   test.support.bytecode_helperr   opcoder   r   r   r   r,   r3   TestCaser5   rP  rR  r  r  r  r  r  r  objectr  r  r  r  r  	pythonapipy	CFUNCTYPEr  freefunc%PyUnstable_Eval_RequestCodeExtraIndexRequestCodeExtraIndexargtypes	c_ssize_trestypePyUnstable_Code_SetExtrar  	py_objectc_intPyUnstable_Code_GetExtrar  POINTERr  r  	FREE_FUNCr  r  r/  rl   mainrK   r-   r   <module>rI     s-  }~   
      
< < <
 8 8 D  '(28^x   ^B2R?X&& R?j%h'' %6)RV1
 H 2@;
x(( ;
| T""v'9			BV^^4HDD&.["$*$4$4!**H))6+;+;V^^LH||H**H))6+;+;79H||HJ  I&y1JK.(## K.\
 zMMO o  Fs   H   H,+H,