o
    gk                     @   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   X/var/www/html/ecg_monitoring/venv/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
   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   	leakcheckr   GREENLET_USE_GCr   r   r   r   r   <module>   s    
