U
    nvgk                     @   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:t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 k	rBd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   :/tmp/pip-unpacked-wheel-49pzfzc0/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   s   d S Nr   r   r   r   r   r   '   s    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   s   d S r    r   r   r   r   r   __del__C   s    zCGCTests.test_finalizer_crash.<locals>.object_with_finalizer.__del__N)r   r   r   r#   r   r   r   r   object_with_finalizerB   s   r$   c                      sL     t  _z0z  W n t jk
r8   td Y nX W 5 t  `X d S )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_GCAssertionErrorr   r   r   r   r   <module>   s   
