HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_finalization.cpython-37.opt-1.pyc
B

��g�8�@sdZddlZddlZddlZddlZyddlmZWnek
rPdd�ZYnXddlm	Z	Gdd�d�Z
Gd	d
�d
e
�ZGdd�de
�ZGd
d�de
�Z
Gdd�de�ZGdd�de
e�ZGdd�d�ZGdd�deej�ZGdd�d�ZGdd�dee�ZGdd�dee�ZGdd�dee�ZGdd �d eej�ZGd!d"�d"�ZGd#d$�d$ee�ZGd%d&�d&ee�ZGd'd(�d(ee�ZGd)d*�d*eej�ZGd+d,�d,e�ZeGd-d.�d.e��ZeGd/d0�d0e��ZeGd1d2�d2ee��Z e	j!Gd3d4�d4eej��Z"e#d5k�r
e�$�dS)6zB
Tests for object finalization semantics, as outlined in PEP 442.
�N)�with_tp_delcCsGdd�dt�}|S)Nc@seZdZdd�ZdS)zwith_tp_del.<locals>.Cc_std��dS)Nzrequires _testcapi.with_tp_del)�	TypeError)�cls�args�kwargs�r�2/usr/local/lib/python3.7/test/test_finalization.py�__new__szwith_tp_del.<locals>.C.__new__N)�__name__�
__module__�__qualname__r	rrrr�Csr
)�object)rr
rrrr
sr)�supportc@s^eZdZdZgZgZgZgZdZdZ	e
dd��Ze
ej
dd���Zdd	�Zd
d�Zdd
�ZdS)�NonGCSimpleBasezd
    The base class for all the objects under test, equipped with various
    testing features.
    FrcCs>|j��|j��tj��t��|j��|j��dS)N)�	survivors�clear�errors�gc�garbage�collect�	del_calls�tp_del_calls)rrrr�_cleanup%s



zNonGCSimpleBase._cleanupc	cs^t���L|j��|j��dt_zdV|jr<|jd�Wddt_|��XWdQRXdS)zI
        A context manager to use around all finalization tests.
        FNrT)	rZ
disable_gcrrrr�	_cleaningrr)rrrr�test.s


zNonGCSimpleBase.testcCsdS)z8
        Check the object is sane (non-broken).
        Nr)�selfrrr�check_sanity@szNonGCSimpleBase.check_sanityc
Cs^y*|js(|j�t|��|��|��Wn.tk
rX}z|j�|�Wdd}~XYnXdS)z�
        PEP 442 finalizer.  Record that this was called, check the
        object is in a sane state, and invoke a side effect.
        N)rr�append�idr�side_effect�	Exceptionr)r�errr�__del__EszNonGCSimpleBase.__del__cCsdS)z6
        A side effect called on destruction.
        Nr)rrrrr RszNonGCSimpleBase.side_effectN)r
rr�__doc__rrrrr�	__slots__�classmethodr�
contextlib�contextmanagerrrr#r rrrrrs	
rc@seZdZdd�Zdd�ZdS)�
SimpleBasecCst|�|_dS)N)rZid_)rrrr�__init__ZszSimpleBase.__init__cCsdS)Nr)rrrrr]szSimpleBase.check_sanityN)r
rrr*rrrrrr)Xsr)c@seZdZdZdS)�NonGCrN)r
rrr%rrrrr+asr+c@seZdZdZdd�ZdS)�NonGCResurrectorrcCs|j�|�dS)zF
        Resurrect self by storing self in a class-wide list.
        N)rr)rrrrr gszNonGCResurrector.side_effectN)r
rrr%r rrrrr,dsr,c@seZdZdS)�SimpleN)r
rrrrrrr-msr-c@seZdZdS)�SimpleResurrectorN)r
rrrrrrr.psr.c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TestBasecCs"tjdd�|_gtjdd�<dS)N)rr�old_garbage)rrrr�setUpvszTestBase.setUpcCs&z|�tjg�Wd|`t��XdS)N)�assertEqualrrr0r)rrrr�tearDownzszTestBase.tearDowncCs|�ttj�t|��dS)N)r2�sortedr)r)r�idsrrr�assert_del_calls�szTestBase.assert_del_callscCs|�ttj�t|��dS)N)r2r4r)r)rr5rrr�assert_tp_del_calls�szTestBase.assert_tp_del_callscCs$|�tdd�tjD��t|��dS)Ncss|]}t|�VqdS)N)r)�.0�xrrr�	<genexpr>�sz,TestBase.assert_survivors.<locals>.<genexpr>)r2r4r)r)rr5rrr�assert_survivors�szTestBase.assert_survivorscCs$|�tdd�tjD��t|��dS)Ncss|]}t|�VqdS)N)r)r8r9rrrr:�sz*TestBase.assert_garbage.<locals>.<genexpr>)r2r4rr)rr5rrr�assert_garbage�szTestBase.assert_garbagecCstj��dS)N)r)rr)rrrr�clear_survivors�szTestBase.clear_survivorsN)
r
rrr1r3r6r7r;r<r=rrrrr/tsr/c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�SimpleFinalizationTestz.
    Test finalization without refcycles.
    c	Cszt���ht�}t|�g}t�|�}~t��|�|�|�	g�|�
|�d�t��|�|�|�	g�WdQRXdS)N)r)rr-r�weakref�refrrr6r;�assertIs)r�sr5�wrrrr�test_simple�s





z"SimpleFinalizationTest.test_simplec	Cs�t���pt�}t|�g}t�|�}~t��|�|�|�	|�|�
|�d�|��t��|�|�|�	g�WdQRX|�|�d�dS)N)
r)rr.rr?r@rrr6r;�assertIsNotr=rA)rrBr5rCrrr�test_simple_resurrect�s





z,SimpleFinalizationTest.test_simple_resurrectc	Csrt���`t�}|�t�|��t|�g}~t��|�|�|�	g�t��|�|�|�	g�WdQRXdS)N)
r)rr+�assertFalser�
is_trackedrrr6r;)rrBr5rrr�test_non_gc�s




z"SimpleFinalizationTest.test_non_gcc	Cs~t���lt�}|�t�|��t|�g}~t��|�|�|�	|�|�
�t��|�|d�|�	|�WdQRXdS)N�)r)rr,rGrrHrrr6r;r=)rrBr5rrr�test_non_gc_resurrect�s



z,SimpleFinalizationTest.test_non_gc_resurrectN)r
rrr$rDrFrIrKrrrrr>�s

r>cs(eZdZ�fdd�Z�fdd�Z�ZS)�
SelfCycleBasecst���||_dS)N)�superr*r@)r)�	__class__rrr*�s
zSelfCycleBase.__init__cst���dS)N)rMr)r)rNrrr�s
zSelfCycleBase.check_sanity)r
rrr*r�
__classcell__rr)rNrrL�srLc@seZdZdS)�SimpleSelfCycleN)r
rrrrrrrP�srPc@seZdZdS)�SelfCycleResurrectorN)r
rrrrrrrQ�srQc@seZdZdd�ZdS)�SuicidalSelfCyclecCs
d|_dS)z7
        Explicitly break the reference cycle.
        N)r@)rrrrr �szSuicidalSelfCycle.side_effectN)r
rrr rrrrrR�srRc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�SelfCycleFinalizationTestzX
    Test finalization of an object having a single cyclic reference to
    itself.
    c	Cszt���ht�}t|�g}t�|�}~t��|�|�|�	g�|�
|�d�t��|�|�|�	g�WdQRXdS)N)r)rrPrr?r@rrr6r;rA)rrBr5rCrrrrD�s





z%SelfCycleFinalizationTest.test_simplec	Cs�t���~t�}t|�g}t�|�}~t��|�|�|�	|�|�
|�d�|��t��|�|�|�	g�|�
|�d�WdQRXdS)N)r)rrQrr?r@rrr6r;rAr=)rrBr5rCrrrrF�s






z/SelfCycleFinalizationTest.test_simple_resurrectc	Cs�t���vt�}t|�g}t�|�}~t��|�|�|�	g�|�
|�d�t��|�|�|�	g�|�
|�d�WdQRXdS)N)r)rrRrr?r@rrr6r;rA)rrBr5rCrrr�test_simple_suicides






z-SelfCycleFinalizationTest.test_simple_suicideN)r
rrr$rDrFrTrrrrrS�srScs$eZdZdd�Z�fdd�Z�ZS)�ChainedBasecCsd|_||_||_dS)NF)�suicided�left�right)rrWrrr�chain&szChainedBase.chaincs2t���|jrn|j}|jr n|j}|jr.ndS)N)rMrrVrWrX)rrWrX)rNrrr+s
zChainedBase.check_sanity)r
rrrYrrOrr)rNrrU$srUc@seZdZdS)�
SimpleChainedN)r
rrrrrrrZ<srZc@seZdZdS)�ChainedResurrectorN)r
rrrrrrr[?sr[c@seZdZdd�ZdS)�SuicidalChainedcCsd|_d|_d|_dS)z7
        Explicitly break the reference cycle.
        TN)rVrWrX)rrrrr DszSuicidalChained.side_effectN)r
rrr rrrrr\Bsr\c@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�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.
    cCs>dd�|D�}x*tt|��D]}||�||d�qW|S)NcSsg|]
}|��qSrr)r8rrrr�
<listcomp>Usz:CycleChainFinalizationTest.build_chain.<locals>.<listcomp>�)�range�lenrY)r�classes�nodes�irrr�build_chainTsz&CycleChainFinalizationTest.build_chainc	Cs�t|�}t���x|�|�}dd�|D�}dd�|D�}~t��|�|�|�g�|�dd�|D�dg|�t��|�|�WdQRXdS)NcSsg|]}t|��qSr)r)r8rBrrrr^^szKCycleChainFinalizationTest.check_non_resurrecting_chain.<locals>.<listcomp>cSsg|]}t�|��qSr)r?r@)r8rBrrrr^_scSsg|]
}|��qSrr)r8rCrrrr^ds)	rar)rrerrr6r;r2)rrb�Nrcr5�wrsrrr�check_non_resurrecting_chainZs



z7CycleChainFinalizationTest.check_non_resurrecting_chainc	Cs�t|�}t����|�|�}t|�}dd�|D�}dd�|D�}dd�|D�}~t��|�|�|�|�|�dd�|D�dg|�|�	�t��|�|�|�g�WdQRXdS)NcSsg|]}t|��qSr)r)r8rBrrrr^mszGCycleChainFinalizationTest.check_resurrecting_chain.<locals>.<listcomp>cSsg|]}t|t�rt|��qSr)�
isinstancer.r)r8rBrrrr^nscSsg|]}t�|��qSr)r?r@)r8rBrrrr^oscSsg|]
}|��qSrr)r8rCrrrr^us)
rar)rrerrr6r;r2r=)rrbrfrcr5Zsurvivor_idsrgrrr�check_resurrecting_chainhs 




z3CycleChainFinalizationTest.check_resurrecting_chaincCs|�tgd�dS)N�)rhrZ)rrrr�test_homogenous{sz*CycleChainFinalizationTest.test_homogenouscCs|�tgd�dS)Nrk)rjr[)rrrr�test_homogenous_resurrect~sz4CycleChainFinalizationTest.test_homogenous_resurrectcCs|�tgd�dS)Nrk)rhr\)rrrr�test_homogenous_suicidal�sz3CycleChainFinalizationTest.test_homogenous_suicidalcCs|�ttgd�dS)NrJ)rhr\rZ)rrrr�test_heterogenous_suicidal_one�sz9CycleChainFinalizationTest.test_heterogenous_suicidal_onecCs|�tgdtgd�dS)NrJ)rhr\rZ)rrrr�test_heterogenous_suicidal_two�sz9CycleChainFinalizationTest.test_heterogenous_suicidal_twocCs|�ttgd�dS)NrJ)rjr[rZ)rrrr�test_heterogenous_resurrect_one�sz:CycleChainFinalizationTest.test_heterogenous_resurrect_onecCs|�tttgd�dS)NrJ)rjr[rZr\)rrrr�test_heterogenous_resurrect_two�sz:CycleChainFinalizationTest.test_heterogenous_resurrect_twocCs(|�tgdtgdtgd�dS)NrJ)rjr[rZr\)rrrr�!test_heterogenous_resurrect_three�sz<CycleChainFinalizationTest.test_heterogenous_resurrect_threeN)r
rrr$rerhrjrlrmrnrorprqrrrsrrrrr]Msr]c@seZdZdd�Zdd�ZdS)�
LegacyBasec
CsVy"|js |j�t|��|��Wn.tk
rP}z|j�|�Wdd}~XYnXdS)N)rrrrrr!r)rr"rrrr#�szLegacyBase.__del__c
Cs^y*|js(|j�t|��|��|��Wn.tk
rX}z|j�|�Wdd}~XYnXdS)zJ
        Legacy (pre-PEP 442) finalizer, mapped to a tp_del slot.
        N)rrrrrr r!r)rr"rrr�
__tp_del__�szLegacyBase.__tp_del__N)r
rrr#rurrrrrt�s
rtc@seZdZdS)�LegacyN)r
rrrrrrrv�srvc@seZdZdd�ZdS)�LegacyResurrectorcCs|j�|�dS)zF
        Resurrect self by storing self in a class-wide list.
        N)rr)rrrrr �szLegacyResurrector.side_effectN)r
rrr rrrrrw�srwc@seZdZdS)�LegacySelfCycleN)r
rrrrrrrx�srxcs8eZdZdZ�fdd�Zdd�Zdd�Zdd	�Z�ZS)
�LegacyFinalizationTestz5
    Test finalization of objects with a tp_del.
    cs tj��t��t���dS)N)rrrrrMr3)r)rNrrr3�s
zLegacyFinalizationTest.tearDownc	Cs�t���rt�}t|�g}t�|�}~t��|�|�|�	|�|�
g�|�|�d�t��|�|�|�	|�WdQRXdS)N)r)rrvrr?r@rrr6r7r;rA)rrBr5rCrrr�test_legacy�s






z"LegacyFinalizationTest.test_legacyc	Cs�t����t�}t|�g}t�|�}~t��|�|�|�	|�|�
|�|�|�d�|��t��|�|�|�	|d�|�
|�WdQRX|�|�d�dS)NrJ)
r)rrwrr?r@rrr6r7r;rAr=)rrBr5rCrrr�test_legacy_resurrect�s 






z,LegacyFinalizationTest.test_legacy_resurrectc	Cs�t���lt�}t|�g}t�|�}~t��|�g�|�	g�|�
g�|�|�|�|�d�dtj
d_WdQRX|�g�|�|�d�dS)Nr)r)rrxrr?r@rrr6r7r;r<rErrA)rrBr5rCrrr�test_legacy_self_cycle�s







z-LegacyFinalizationTest.test_legacy_self_cycle)	r
rrr$r3rzr{r|rOrr)rNrry�s
ry�__main__)%r$r'rZunittestr?Z	_testcapir�ImportErrorrrrr)r+r,r-r.r/ZTestCaser>rLrPrQrRrSrUrZr[r\r]rtrvrwrxZcpython_onlyryr
�mainrrrr�<module>sLB		?
	:M
A