Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_finalization.cpython-34.pyo

�
f f�8�@s�dZddlZddlZddlZddlZyddlmZWnek
rjdd�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"d5d6�Z#e$d7kr�e#�ndS)8zB
Tests for object finalization semantics, as outlined in PEP 442.
�N)�with_tp_delcCsGdd�dt�}|S)Nc@seZdZdd�ZdS)zwith_tp_del.<locals>.Cc_std��dS)Nzrequires _testcapi.with_tp_del)�	TypeError)�cls�args�kwargs�r�;/opt/alt/python34/lib64/python3.4/test/test_finalization.py�__new__szwith_tp_del.<locals>.C.__new__N)�__name__�
__module__�__qualname__r	rrrr�Csr
)�object)rr
rrrr
sr)�supportc@s�eZdZdZgZgZgZgZdZfZ	e
dd��Ze
ej
dd���Zdd�Zd	d
�Zdd�Zd
S)�NonGCSimpleBasezd
    The base class for all the objects under test, equipped with various
    testing features.
    FcCsO|jj�|jj�tjj�tj�|jj�|jj�dS)N)�	survivors�clear�errors�gc�garbage�collect�	del_calls�tp_del_calls)rrrr�_cleanup%s




zNonGCSimpleBase._cleanupccsstj��a|jj�|jj�dt_z"dV|jrQ|jd�nWddt_|j�XWdQXdS)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_sanitycCsvy:|js9|jjt|��|j�|j�nWn5tk
rq}z|jj|�WYdd}~XnXdS)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@s(eZdZdd�Zdd�ZdS)�
SimpleBasecCst|�|_dS)N)rZid_)rrrr�__init__ZszSimpleBase.__init__cCsdS)Nr)rrrrr]szSimpleBase.check_sanityN)r
rrr*rrrrrr)Xsr)c@seZdZfZdS)�NonGCN)r
rrr%rrrrr+asr+c@s"eZdZfZdd�ZdS)�NonGCResurrectorcCs|jj|�dS)zF
        Resurrect self by storing self in a class-wide list.
        N)rr)rrrrr gszNonGCResurrector.side_effectN)r
rrr%r rrrrr,dsr,c@seZdZdS)�SimpleN)r
rrrrrrr-msr-c@seZdZdS)�SimpleResurrectorN)r
rrrrrrr.psr.c@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TestBasecCs-tjdd�|_gtjdd�<dS)N)rr�old_garbage)rrrr�setUpvszTestBase.setUpc
Cs/z|jtjg�Wd|`tj�XdS)N)�assertEqualrrr0r)rrrr�tearDownzszTestBase.tearDowncCs#|jttj�t|��dS)N)r2�sortedr)r)r�idsrrr�assert_del_calls�szTestBase.assert_del_callscCs#|jttj�t|��dS)N)r2r4r)r)rr5rrr�assert_tp_del_calls�szTestBase.assert_tp_del_callscCs0|jtdd�tjD��t|��dS)Ncss|]}t|�VqdS)N)r)�.0�xrrr�	<genexpr>�sz,TestBase.assert_survivors.<locals>.<genexpr>)r2r4r)r)rr5rrr�assert_survivors�szTestBase.assert_survivorscCs0|jtdd�tjD��t|��dS)Ncss|]}t|�VqdS)N)r)r8r9rrrr:�sz*TestBase.assert_garbage.<locals>.<genexpr>)r2r4rr)rr5rrr�assert_garbage�szTestBase.assert_garbagecCstjj�dS)N)r)rr)rrrr�clear_survivors�szTestBase.clear_survivorsN)
r
rrr1r3r6r7r;r<r=rrrrr/tsr/c@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�SimpleFinalizationTestz.
    Test finalization without refcycles.
    c
Cs�tj���t�}t|�g}tj|�}~tj�|j|�|j	g�|j
|�d�tj�|j|�|j	g�WdQXdS)N)r)rr-r�weakref�refrrr6r;�assertIs)r�sr5�wrrrr�test_simple�s
	




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





z,SimpleFinalizationTest.test_simple_resurrectc
Cs�tj��~t�}|jtj|��t|�g}~tj�|j|�|j	g�tj�|j|�|j	g�WdQXdS)N)
r)rr+�assertFalser�
is_trackedrrr6r;)rrBr5rrr�test_non_gc�s
	




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




z,SimpleFinalizationTest.test_non_gc_resurrectN)r
rrr$rDrFrIrKrrrrr>�s

r>cs4eZdZ�fdd�Z�fdd�Z�S)�
SelfCycleBasecst�j�||_dS)N)�superr*r@)r)�	__class__rrr*�s
zSelfCycleBase.__init__cst�j�dS)N)rMr)r)rNrrr�s
zSelfCycleBase.check_sanity)r
rrr*rrr)rNrrL�srLc@seZdZdS)�SimpleSelfCycleN)r
rrrrrrrO�srOc@seZdZdS)�SelfCycleResurrectorN)r
rrrrrrrP�srPc@seZdZdd�ZdS)�SuicidalSelfCyclecCs
d|_dS)z7
        Explicitly break the reference cycle.
        N)r@)rrrrr �szSuicidalSelfCycle.side_effectN)r
rrr rrrrrQ�srQc@s:eZdZdZdd�Zdd�Zdd�ZdS)	�SelfCycleFinalizationTestzX
    Test finalization of an object having a single cyclic reference to
    itself.
    c
Cs�tj���t�}t|�g}tj|�}~tj�|j|�|j	g�|j
|�d�tj�|j|�|j	g�WdQXdS)N)r)rrOrr?r@rrr6r;rA)rrBr5rCrrrrD�s
	




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






z/SelfCycleFinalizationTest.test_simple_resurrectc
Cs�tj���t�}t|�g}tj|�}~tj�|j|�|j	g�|j
|�d�tj�|j|�|j	g�|j
|�d�WdQXdS)N)r)rrQrr?r@rrr6r;rA)rrBr5rCrrr�test_simple_suicides
	





z-SelfCycleFinalizationTest.test_simple_suicideN)r
rrr$rDrFrSrrrrrR�srRcs.eZdZdd�Z�fdd�Z�S)�ChainedBasecCsd|_||_||_dS)NF)�suicided�left�right)rrVrrr�chain&s		zChainedBase.chaincsGt�j�|jrn*|j}|jr.n|j}|jrCndS)N)rMrrUrVrW)rrVrW)rNrrr+s
					zChainedBase.check_sanity)r
rrrXrrr)rNrrT$srTc@seZdZdS)�
SimpleChainedN)r
rrrrrrrY<srYc@seZdZdS)�ChainedResurrectorN)r
rrrrrrrZ?srZc@seZdZdd�ZdS)�SuicidalChainedcCsd|_d|_d|_dS)z7
        Explicitly break the reference cycle.
        TN)rUrVrW)rrrrr Ds		zSuicidalChained.side_effectN)r
rrr rrrrr[Bsr[c@s�eZdZdZdd�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.
    cCsMdd�|D�}x3tt|��D]}||j||d�q&W|S)NcSsg|]}|��qSrr)r8rrrr�
<listcomp>Us	z:CycleChainFinalizationTest.build_chain.<locals>.<listcomp>�)�range�lenrX)r�classes�nodes�irrr�build_chainTsz&CycleChainFinalizationTest.build_chaincCs�t|�}tj���|j|�}dd�|D�}dd�|D�}~tj�|j|�|jg�|jdd�|D�dg|�tj�|j|�WdQXdS)NcSsg|]}t|��qSr)r)r8rBrrrr]^s	zKCycleChainFinalizationTest.check_non_resurrecting_chain.<locals>.<listcomp>cSsg|]}tj|��qSr)r?r@)r8rBrrrr]_s	cSsg|]}|��qSrr)r8rCrrrr]ds	)	r`r)rrdrrr6r;r2)rra�Nrbr5�wrsrrr�check_non_resurrecting_chainZs



$
z7CycleChainFinalizationTest.check_non_resurrecting_chaincCs�t|�}tj���|j|�}t|�}dd�|D�}dd�|D�}dd�|D�}~tj�|j|�|j|�|jdd�|D�dg|�|j	�tj�|j|�|jg�WdQXdS)NcSsg|]}t|��qSr)r)r8rBrrrr]ms	zGCycleChainFinalizationTest.check_resurrecting_chain.<locals>.<listcomp>cSs+g|]!}t|t�rt|��qSr)�
isinstancer.r)r8rBrrrr]ns	cSsg|]}tj|��qSr)r?r@)r8rBrrrr]os	cSsg|]}|��qSrr)r8rCrrrr]us	)
r`r)rrdrrr6r;r2r=)rrarerbr5Zsurvivor_idsrfrrr�check_resurrecting_chainhs 



$


z3CycleChainFinalizationTest.check_resurrecting_chaincCs|jtgd�dS)N�)rgrY)rrrr�test_homogenous{sz*CycleChainFinalizationTest.test_homogenouscCs|jtgd�dS)Nrj)rirZ)rrrr�test_homogenous_resurrect~sz4CycleChainFinalizationTest.test_homogenous_resurrectcCs|jtgd�dS)Nrj)rgr[)rrrr�test_homogenous_suicidal�sz3CycleChainFinalizationTest.test_homogenous_suicidalcCs|jttgd�dS)NrJ)rgr[rY)rrrr�test_heterogenous_suicidal_one�sz9CycleChainFinalizationTest.test_heterogenous_suicidal_onecCs#|jtgdtgd�dS)NrJ)rgr[rY)rrrr�test_heterogenous_suicidal_two�sz9CycleChainFinalizationTest.test_heterogenous_suicidal_twocCs|jttgd�dS)NrJ)rirZrY)rrrr�test_heterogenous_resurrect_one�sz:CycleChainFinalizationTest.test_heterogenous_resurrect_onecCs|jtttgd�dS)NrJ)rirZrYr[)rrrr�test_heterogenous_resurrect_two�sz:CycleChainFinalizationTest.test_heterogenous_resurrect_twocCs.|jtgdtgdtgd�dS)NrJ)rirZrYr[)rrrr�!test_heterogenous_resurrect_three�sz<CycleChainFinalizationTest.test_heterogenous_resurrect_threeN)r
rrr$rdrgrirkrlrmrnrorprqrrrrrrr\Msr\c@s(eZdZdd�Zdd�ZdS)�
LegacyBasecCsly0|js/|jjt|��|j�nWn5tk
rg}z|jj|�WYdd}~XnXdS)N)rrrrrr!r)rr"rrrr#�s	zLegacyBase.__del__cCsvy:|js9|jjt|��|j�|j�nWn5tk
rq}z|jj|�WYdd}~XnXdS)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#rtrrrrrs�s
rsc@seZdZdS)�LegacyN)r
rrrrrrru�sruc@seZdZdd�ZdS)�LegacyResurrectorcCs|jj|�dS)zF
        Resurrect self by storing self in a class-wide list.
        N)rr)rrrrr �szLegacyResurrector.side_effectN)r
rrr rrrrrv�srvc@seZdZdS)�LegacySelfCycleN)r
rrrrrrrw�srwcsLeZdZdZ�fdd�Zdd�Zdd�Zdd	�Z�S)
�LegacyFinalizationTestz5
    Test finalization of objects with a tp_del.
    cs(tjj�tj�t�j�dS)N)rrrrrMr3)r)rNrrr3�s

zLegacyFinalizationTest.tearDownc
Cs�tj���t�}t|�g}tj|�}~tj�|j|�|j	|�|j
g�|j|�d�tj�|j|�|j	|�WdQXdS)N)r)rrurr?r@rrr6r7r;rA)rrBr5rCrrr�test_legacy�s
	





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






z,LegacyFinalizationTest.test_legacy_resurrectc
Cs�tj���t�}t|�g}tj|�}~tj�|jg�|j	g�|j
g�|j|�|j|�d�dtj
d_WdQX|jg�|j|�d�dS)Nr)r)rrwrr?r@rrr6r7r;r<rErrA)rrBr5rCrrr�test_legacy_self_cycle�s
	





z-LegacyFinalizationTest.test_legacy_self_cycle)r
rrr$r3ryrzr{rr)rNrrx�s
rxcCstjt�dS)N)rZrun_unittestr
rrrr�	test_mainsr|�__main__)%r$r'rZunittestr?Z	_testcapir�ImportErrorrrrr)r+r,r-r.r/ZTestCaser>rLrOrPrQrRrTrYrZr[r\rsrurvrwZcpython_onlyrxr|r
rrrr�<module>sN
B		?
	:MA