o
    …©Zhk  ã                   @   sN   d dl Z d dlZd dlZddlmZ ddlmZ ejsJ ‚G dd„ deƒZdS )é    Né   )ÚTestCase)Úfails_leakcheckc                   @   s0   e Zd Zdd„ Zdd„ Zdd„ Zedd„ ƒZd	S )
ÚGCTestsc                 C   sb   t  t tj¡ ¡ ¡}t ¡  |ƒ d ur!dd l}td| 	|ƒ ¡ƒ |  
|ƒ ¡ |  tjtj¡ d S )Nr   zO IS NOT NONE.)ÚweakrefÚrefÚgreenletÚ
getcurrentÚswitchÚgcÚcollectÚsysÚprintÚgetrefcountÚassertIsNoneÚassertFalseÚgarbage)ÚselfÚor   © r   úM/var/www/html/lang_env/lib/python3.10/site-packages/greenlet/tests/test_gc.pyÚtest_dead_circular_ref   s   
zGCTests.test_dead_circular_refc                 C   sP   G dd„ dt j ƒ}|ƒ }||_t |¡}t ¡  |  |ƒ ¡ |  tjtj¡ d S )Nc                   @   s   e Zd ZdZdS )z9GCTests.test_circular_greenlet.<locals>.circular_greenletN)Ú__name__Ú
__module__Ú__qualname__r   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   sJ   G dd„ dt j ƒ}|ƒ }t |¡}t ¡  |  |ƒ ¡ |  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 ©Nr   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__C   r"   zCGCTests.test_finalizer_crash.<locals>.object_with_finalizer.__del__N)r   r   r   r%   r   r   r   r   Úobject_with_finalizerB   s    r&   c                      s^   ˆ ƒ t  ¡ _z#zˆ ¡  W n t jy   tdƒ Y nw W t  ¡ `d S W t  ¡ `d S t  ¡ `w )NzGot greenlet exit!)r   r	   Úobjectr
   ZGreenletExitr   r   ©r&   Úparentr   r   Úgreenlet_bodyG   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   r$   r   r.   r   r   r   r   r      s    	
r   )	r   r   r   Ú r   Z	leakcheckr   ZGREENLET_USE_GCr   r   r   r   r   Ú<module>   s    
