python (3.12.0)

(root)/
lib/
python3.12/
test/
__pycache__/
test_finalization.cpython-312.opt-1.pyc

͑e:bdZddlZddlZddlZddlZ	ddlmZ	ddlmZddl	m
Z
Gdd	ZGd
deZeGdd
eZ
eGddeZGddeZGddeZGddZGddeej$ZGddZGddeeZGddeeZGddeeZGd d!eej$ZGd"d#ZGd$d%eeZGd&d'eeZGd(d)eeZGd*d+eej$ZGd,d-eZeGd.d/eZeGd0d1eZ eGd2d3eeZ!e
jDGd4d5eej$Z#e$d6k(rejJyy#e$rdZYwxYw#e$rdZYwxYw)7zB
Tests for object finalization semantics, as outlined in PEP 442.
N)with_tp_delc$Gddt}|S)NceZdZdZy)with_tp_del.<locals>.Cctd)Nzrequires _testcapi.with_tp_del	TypeErrorclsargskwargss   J/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/test/test_finalization.py__new__zwith_tp_del.<locals>.C.__new__s @AAN__name__
__module____qualname__rrrCrs
Brr)objectrrs  rrr
s	B	Br)
without_gccGdd}|S)NceZdZdZy)without_gc.<locals>.Cctd)Nzrequires _testcapi.without_gcrr
s   rrzwithout_gc.<locals>.C.__new__s ?@@rNrrrrrrs
Arrrrs  rrrs	A	Ar)supportcxeZdZdZgZgZgZgZdZdZ	e
dZe
ejdZdZdZdZy	)
NonGCSimpleBasezd
    The base class for all the objects under test, equipped with various
    testing features.
    Frc8|jj|jjtjjtj
|jj|jjyN)	survivorsclearerrorsgcgarbagecollect	del_callstp_del_callsrs r_cleanupzNonGCSimpleBase._cleanup.s]











 rc#Ktj5|jj|jjdt
_	d|jr|jd	dt
_|j	dddy#dt
_|jwxYw#1swYyxYww)zI
        A context manager to use around all finalization tests.
        FNrT)	r
disable_gcr)r$r*r 	_cleaningr%r,r+s rtestzNonGCSimpleBase.test7s


!
	MM!""$(-O%
::**Q-'-1)
	
	-1)
	
	s5C	AB=B8B=	C	B::B==CC	cy)z8
        Check the object is sane (non-broken).
        Nrselfs rcheck_sanityzNonGCSimpleBase.check_sanityIrc
	|jsE|jjt||j	|jyy#t$r%}|jj|Yd}~yd}~wwxYw)z
        PEP 442 finalizer.  Record that this was called, check the
        object is in a sane state, and invoke a side effect.
        N)r/r)appendidr4side_effect	Exceptionr%r3es  r__del__zNonGCSimpleBase.__del__Nsh
	">>%%bh/!!#  ""	"KKq!!	"AA	BA==Bcy)z6
        A side effect called on destruction.
        Nrr2s rr9zNonGCSimpleBase.side_effect[r5rN)rrr__doc__r#r)r*r%r/	__slots__classmethodr,
contextlibcontextmanagerr0r4r=r9rrrr r sj
IIL
FII!! 
"rr ceZdZdZdZy)
SimpleBasec$t||_yr")r8id_r2s r__init__zSimpleBase.__init__cs
d8rcyr"rr2s rr4zSimpleBase.check_sanityfr5rN)rrrrIr4rrrrFrFas$rrFceZdZdZy)NonGCrN)rrrrArrrrLrLjsIrrLceZdZdZdZy)NonGCResurrectorrc:|jj|yzF
        Resurrect self by storing self in a class-wide list.
        Nr#r7r2s rr9zNonGCResurrector.side_effectr	
d#rN)rrrrAr9rrrrNrNnsI$rrNceZdZy)SimpleNrrrrrrrTrTxrrTceZdZdZy)SimpleResurrectorc:|jj|yrPrQr2s rr9zSimpleResurrector.side_effect~rRrNrrrr9rrrrXrX|s$rrXc6eZdZdZdZdZdZdZdZdZ	y)	TestBasecZtjdd|_gtjddyr")r&r'old_garbager2s rsetUpzTestBase.setUps::a=

1
rc	|jtjg|`tjy#|`tjwxYwr")assertEqualr&r'r^r(r2s rtearDownzTestBase.tearDowns=	RZZ, JJL JJLs	 9Ach|jttjt|yr")rasortedrFr)r3idss  rassert_del_callszTestBase.assert_del_callss!
 4 45vc{Crch|jttjt|yr")rardrFr*res  rassert_tp_del_callszTestBase.assert_tp_del_callss!
 7 78&+Frcv|jtdtjDt|y)Nc32K|]}t|ywr"r8.0xs  r	<genexpr>z,TestBase.assert_survivors.<locals>.<genexpr>sD!1D)rardrFr#res  rassert_survivorszTestBase.assert_survivorss'Dz/C/CDDfSkRrcv|jtdtjDt|y)Nc32K|]}t|ywr"rlrms  rrpz*TestBase.assert_garbage.<locals>.<genexpr>s:!1:rq)rardr&r'res  rassert_garbagezTestBase.assert_garbages%:rzz::F3KHrc@tjjyr")rFr#r$r2s rclear_survivorszTestBase.clear_survivorss""$rN)
rrrr_rbrgrirrrurwrrrr\r\s)DGSI%rr\cdeZdZdZdZdZejdZejdZ	y)SimpleFinalizationTestz.
    Test finalization without refcycles.
    ctj5t}t|g}t	j
|}~t
j|j||jg|j|dt
j|j||jgdddy#1swYyxYwr")rFr0rTr8weakrefrefr&r(rgrrassertIsr3srfwrs    rtest_simplez"SimpleFinalizationTest.test_simples
__
	&Aa5'CQBJJL!!#&!!"%MM"$%JJL!!#&!!"%	&	&	&B0CCctj5t}t|g}t	j
|}~t
j|j||j||j|d|jt
j|j||jgddd|jdy#1swY!xYwr")
rFr0rXr8r{r|r&r(rgrrassertIsNotrwr}r~s    rtest_simple_resurrectz,SimpleFinalizationTest.test_simple_resurrects
__
	&!#Aa5'CQBJJL!!#&!!#&RT4(  "JJL!!#&!!"%	&	


bdD!	&	&sCC55C>ctj5t}|jt	j
|t
|g}~t	j|j||jgt	j|j||jgdddy#1swYyxYwr")
rFr0rLassertFalser&
is_trackedr8r(rgrrr3rrfs   rtest_non_gcz"SimpleFinalizationTest.test_non_gcs
__

	&AR]]1-.a5'CJJL!!#&!!"%JJL!!#&!!"%
	&
	&
	&sB(CCctj5t}|jt	j
|t
|g}~t	j|j||j||jt	j|j|dz|j|dddy#1swYyxYwN)rFr0rNrr&rr8r(rgrrrwrs   rtest_non_gc_resurrectz,SimpleFinalizationTest.test_non_gc_resurrects
__
	' "AR]]1-.a5'CJJL!!#&!!#&  "JJL!!#'*!!#&	'	'	'sB;CC"N)
rrrr@rrrcpython_onlyrrrrrryrysE&" 
&&
''rryc(eZdZfdZfdZxZS)
SelfCycleBasec0t|||_yr")superrIr|r3	__class__s rrIzSelfCycleBase.__init__s
rc"t|yr")rr4rs rr4zSelfCycleBase.check_sanitys
r)rrrrIr4
__classcell__rs@rrrs  rrceZdZy)SimpleSelfCycleNrUrrrrrrVrrceZdZy)SelfCycleResurrectorNrUrrrrrrVrrceZdZdZy)SuicidalSelfCyclecd|_y)7
        Explicitly break the reference cycle.
        N)r|r2s rr9zSuicidalSelfCycle.side_effectsrNrZrrrrrsrrc"eZdZdZdZdZdZy)SelfCycleFinalizationTestzX
    Test finalization of an object having a single cyclic reference to
    itself.
    ctj5t}t|g}t	j
|}~t
j|j||jg|j|dt
j|j||jgdddy#1swYyxYwr")rFr0rr8r{r|r&r(rgrrr}r~s    rrz%SelfCycleFinalizationTest.test_simples
__
	&!Aa5'CQBJJL!!#&!!"%MM"$%JJL!!#&!!"%	&	&	&rctj5t}t|g}t	j
|}~t
j|j||j||j|d|jt
j|j||jg|j|ddddy#1swYyxYwr")rFr0rr8r{r|r&r(rgrrr}rwr~s    rrz/SelfCycleFinalizationTest.test_simple_resurrects
__
	&$&Aa5'CQBJJL!!#&!!#&MM"$%
  "JJL!!#&!!"%MM"$%!	&	&	&sCC55C>ctj5t}t|g}t	j
|}~t
j|j||jg|j|dt
j|j||jg|j|ddddy#1swYyxYwr")rFr0rr8r{r|r&r(rgrrr}r~s    rtest_simple_suicidez-SelfCycleFinalizationTest.test_simple_suicide%s__
	&!#Aa5'CQBJJL!!#&!!"%MM"$%JJL!!#&!!"%MM"$%	&	&	&sCC%%C.N)rrrr@rrrrrrrrs
&&(&rrc$eZdZdZfdZxZS)ChainedBasec.d|_||_||_y)NFsuicidedleftright)r3rs  rchainzChainedBase.chain9s
	
rct||jry|j}|jr	|j}|jryyr")rr4rrr)r3rrrs   rr4zChainedBase.check_sanity>s9
==99D}}JJE~~r)rrrrr4rrs@rrr7s
**rrceZdZy)
SimpleChainedNrUrrrrrOrVrrceZdZy)ChainedResurrectorNrUrrrrrRrVrrceZdZdZy)SuicidalChainedc.d|_d|_d|_y)rTNrr2s rr9zSuicidalChained.side_effectWs
	
rNrZrrrrrUsrrcReZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZy
)CycleChainFinalizationTestz
    Test finalization of a cyclic chain.  These tests are similar in
    spirit to the self-cycle tests above, but the collectable object
    graph isn't trivial anymore.
    c|Dcgc]	}|}}tt|D]}||j||dz
|Scc}w)N)rangelenr)r3classesrnodesis     rbuild_chainz&CycleChainFinalizationTest.build_chaingsQ")*3**s5z"	'A!HNN51:&	'+sA
c*t|}tj5|j|}|Dcgc]
}t	|}}|Dcgc]}tj|}}~tj|j||jg|j|Dcgc]	}|c}dg|ztj|j|dddycc}wcc}wcc}w#1swYyxYwr")rrFr0rr8r{r|r&r(rgrrra)r3rNrrrfwrsrs        rcheck_non_resurrecting_chainz7CycleChainFinalizationTest.check_non_resurrecting_chainmsL
__

	'$$W-E"'(Q2a5(C(+01a7;;q>1C1JJL!!#&!!"%S1rbd1D6A:>JJL!!#&
	'
	'(1
2
	'
	's5D	C:D	C?*AD	2D
1D	:D		Dct|}tj5|j|}t|}|Dcgc]
}t	|}}|Dcgc]}t|tst	| }}|Dcgc]}tj|}}~tj|j||j||j|Dcgc]	}|c}dg|z|jtj|j||jgdddycc}wcc}wcc}wcc}w#1swYyxYwr")rrFr0rr8
isinstancerXr{r|r&r(rgrrrarw)	r3rrrrrfsurvivor_idsrrs	         rcheck_resurrecting_chainz3CycleChainFinalizationTest.check_resurrecting_chain{s'L
__
	&$$W-EE
A"'(Q2a5(C(+0UaJqBS4TBqEULU+01a7;;q>1C1JJL!!#&!!,/S1rbd1D6A:>  "JJL!!#&!!"%	&	&)U12	&	&sI!E#EE#E/
E<E#EAE#&E
4AE#E##E,c6|jtgdzyN)rrr2s rtest_homogenousz*CycleChainFinalizationTest.test_homogenouss))=/A*=>rc6|jtgdzyr)rrr2s rtest_homogenous_resurrectz4CycleChainFinalizationTest.test_homogenous_resurrects%%'9&:Q&>?rc6|jtgdzyr)rrr2s rtest_homogenous_suicidalz3CycleChainFinalizationTest.test_homogenous_suicidals))?*;a*?@rc@|jttgdzyrrrrr2s rtest_heterogenous_suicidal_onez9CycleChainFinalizationTest.test_heterogenous_suicidal_ones))?M*JQ*NOrcL|jtgdztgdzzyrrr2s rtest_heterogenous_suicidal_twoz9CycleChainFinalizationTest.test_heterogenous_suicidal_twos'))
!]Oa$77	9rc@|jttgdzyr)rrrr2s rtest_heterogenous_resurrect_onez:CycleChainFinalizationTest.test_heterogenous_resurrect_ones%%'9=&IA&MNrcJ|jtttgdzyrrrrrr2s rtest_heterogenous_resurrect_twoz:CycleChainFinalizationTest.test_heterogenous_resurrect_twos %%
@1D	Frcb|jtgdztgdzztgdzzyrrr2s r!test_heterogenous_resurrect_threez<CycleChainFinalizationTest.test_heterogenous_resurrect_threes6%%
 1$
'::o=NQR=RR	TrN)rrrr@rrrrrrrrrrrrrrrr`sD'&&?@AP9OFTrrceZdZdZdZy)
LegacyBasec	|js5|jjt||j	yy#t
$r%}|jj|Yd}~yd}~wwxYwr")r/r)r7r8r4r:r%r;s  rr=zLegacyBase.__del__s^	">>%%bh/!!#"	"KKq!!	"sAA	A2
A--A2c
	|jsE|jjt||j	|jyy#t$r%}|jj|Yd}~yd}~wwxYw)zJ
        Legacy (pre-PEP 442) finalizer, mapped to a tp_del slot.
        N)r/r*r7r8r4r9r:r%r;s  r
__tp_del__zLegacyBase.__tp_del__sj	">>!!((D2!!#  ""	"KKq!!	"r>N)rrrr=rrrrrrs"
"rrceZdZy)LegacyNrUrrrrrrrceZdZdZy)LegacyResurrectorc:|jj|yrPrQr2s rr9zLegacyResurrector.side_effectrRrNrZrrrrrs$rrceZdZy)LegacySelfCycleNrUrrrrrrrrc4eZdZdZfdZdZdZdZxZS)LegacyFinalizationTestz5
    Test finalization of objects with a tp_del.
    ctjjtjt|yr")r&r'r$r(rrbrs rrbzLegacyFinalizationTest.tearDowns)	





rctj5t}t|g}t	j
|}~t
j|j||j||jg|j|dt
j|j||j|dddy#1swYyxYwr")rFr0rr8r{r|r&r(rgrirrr}r~s    rtest_legacyz"LegacyFinalizationTest.test_legacys
__
	*Aa5'CQBJJL!!#&$$S)!!"%MM"$%JJL!!#&$$S)	*	*	*sCCC(cLtj5t}t|g}t	j
|}~t
j|j||j||j||j|d|jt
j|j||j|dz|j|ddd|jdy#1swY!xYwr)
rFr0rr8r{r|r&r(rgrirrr}rwr~s    rtest_legacy_resurrectz,LegacyFinalizationTest.test_legacy_resurrects
__
	'!#Aa5'CQBJJL!!#&$$S)!!#&MM"$%  "JJL!!#&$$S1W-!!#&	' 	


bdD!!	'	'sC%DD#ctj5t}t|g}t	j
|}~t
j|jg|jg|jg|j||j|ddtjd_ddd|jg|jdy#1swY2xYw)Nr)rFr0rr8r{r|r&r(rgrirrrurr'r}r~s    rtest_legacy_self_cyclez-LegacyFinalizationTest.test_legacy_self_cycles
__
	%!Aa5'CQBJJL!!"%$$R(!!"%$RT4( $BJJqM	%	
B

bdD!	%	%sB4C::D)	rrrr@rbrrrrrs@rrrs
*"&"rr__main__)&r@rCr&unittestr{	_testcapirImportErrorrr0rr rFrLrNrTrXr\TestCaseryrrrrrrrrrrrrrrrrrmainrrr<module>rs	%$??D$$O$$$	Z	$
$%%<>'Xx'8'8>'B  	mV		=*;	
v7&(*;*;7&t**0	K		&7	k6GT8+<+<GTZ""0
	Z	
	
$
$
$
	mZ	
		>"Xx'8'8>">"BzHMMO[s"FF"FF"F.-F.