o
    £€jcL  ã                   @   s>   d dl Z d dlZd dlZd dlZd dlZG dd„ dejƒZdS )é    Nc                   @   s6   e Zd Zdd„ Zejrdd„ Zdd„ Zdd„ Zd	S d	S )
ÚGCTestsc                 C   sB   t  t tj¡ ¡ ¡}t ¡  |  |ƒ d u ¡ |  tj	tj	¡ d S ©N)
ÚweakrefÚrefÚgreenletÚ
getcurrentÚswitchÚgcÚcollectÚ
assertTrueÚassertFalseÚgarbage)ÚselfÚo© r   úA/usr/local/lib/python3.10/dist-packages/greenlet/tests/test_gc.pyÚtest_dead_circular_ref
   s   zGCTests.test_dead_circular_refc                 C   sT   G dd„ dt j ƒ}|ƒ }||_t |¡}t ¡  |  |ƒ d u ¡ |  tjtj¡ d S )Nc                   @   s   e Zd ZdS )z9GCTests.test_circular_greenlet.<locals>.circular_greenletN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   Úcircular_greenlet   s    r   )	r   r   r   r   r	   r
   r   r   r   )r   r   r   r   r   r   Útest_circular_greenlet   s   
zGCTests.test_circular_greenletc                 C   sN   G dd„ dt j ƒ}|ƒ }t |¡}t ¡  |  |ƒ d u ¡ |  tjtj¡ d S )Nc                   @   s   e Zd Zdd„ Zdd„ ZdS )z4GCTests.test_inactive_ref.<locals>.inactive_greenletc                 S   s   t j j| | jd d S )N)Úrun)r   Ú__init__r   ©r   r   r   r   r      s   z=GCTests.test_inactive_ref.<locals>.inactive_greenlet.__init__c                 S   ó   d S r   r   r   r   r   r   r   "   ó   z8GCTests.test_inactive_ref.<locals>.inactive_greenlet.runN)r   r   r   r   r   r   r   r   r   Úinactive_greenlet   s    r   )r   r   r   r	   r
   r   r   r   )r   r   r   r   r   r   Útest_inactive_ref   s   
zGCTests.test_inactive_refc                    sd   G dd„ dt ƒ‰ g }t ¡ ‰‡ ‡fdd„}t |¡}||_| |¡ | ¡  ~~t ¡  t ¡  d S )Nc                   @   s   e Zd Zdd„ ZdS )z;GCTests.test_finalizer_crash.<locals>.object_with_finalizerc                 S   r   r   r   r   r   r   r   Ú__del__<   r   zCGCTests.test_finalizer_crash.<locals>.object_with_finalizer.__del__N)r   r   r   r   r   r   r   r   Úobject_with_finalizer;   s    r    c                      s.   ˆ ƒ t  ¡ _zˆ ¡  W t  ¡ `d S t  ¡ `w r   )r   r   Úobjectr   r   ©r    Úparentr   r   Úgreenlet_body@   s   
z3GCTests.test_finalizer_crash.<locals>.greenlet_body)r!   r   r   ÚarrayÚappendr   r	   r
   )r   r%   r$   Úgr   r"   r   Útest_finalizer_crash*   s   

zGCTests.test_finalizer_crashN)	r   r   r   r   r   ÚGREENLET_USE_GCr   r   r(   r   r   r   r   r   	   s    
ær   )r	   ÚsysÚunittestr   r   ÚTestCaser   r   r   r   r   Ú<module>   s    