o
    ڭh                     @   s<   d dl Z d dlmZ ddlmZ dd ZG dd deZdS )	    N)greenlet   )TestCasec                  G   s   t  jj|  S )N)r   
getcurrentparentswitch)args r	   ^/var/www/html/stock_analysis/be/venv/lib/python3.10/site-packages/greenlet/tests/test_throw.pyr      s   r   c                   @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )
ThrowTestsc                 C   s>   dd }t |}| }| |d |t}| |d d S )Nc                   S   s6   zt d W n ty   t d Y d S w t d d S Nokfail)r   RuntimeErrorr	   r	   r	   r
   f   s   z ThrowTests.test_class.<locals>.fr   r   r   assertEqualthrowr   selfr   gresr	   r	   r
   
test_class   s   
zThrowTests.test_classc                 C   sv   dd }t |}| }| |d |td}| |d t |}| }| |d |td}| |d d S )Nc                  S   sR   zt d W n ty"   t d } t| dkr t d Y d S Y nw t d d S )Nr   r   ciaor   )r   r   sysexc_infostr)valr	   r	   r
   r      s   zThrowTests.test_val.<locals>.fr   r   r   r   r	   r	   r
   test_val   s   
zThrowTests.test_valc                 C   sh   dd }t |}| }| |d | }| t|t j | |j | }| t|t j d S )Nc                   S   s   t d t d d S r   r   r	   r	   r	   r
   r   2   s   zThrowTests.test_kill.<locals>.fr   )r   r   r   r   
assertTrue
isinstanceGreenletExitdeadr   r	   r	   r
   	test_kill1   s   zThrowTests.test_killc                    sD  t    fdd} fdd}t |}t ||d}| t |t W d    n1 s/w   Y  | |j | |j t |}t ||d}| }| |d |t}| |d | |j | |j t |}t ||d}| }| |d | }| |d |t}| |d | |j | |j d S )	Nc                      s&   z  d W dS  ty   Y dS w )Nf1 ready to catchcaughtznormal exit)r   
IndexErrorr	   mainr	   r
   f1A   s   z9ThrowTests.test_throw_goes_to_original_parent.<locals>.f1c                      s     d d S )Nfrom f2r   r	   r(   r	   r
   f2H   s   z9ThrowTests.test_throw_goes_to_original_parent.<locals>.f2)r   r%   r&   r+   )	r   r   assertRaisesr'   r   r    r#   r   r   )r   r*   r,   g1g2r   r	   r(   r
   "test_throw_goes_to_original_parent>   s8   

z-ThrowTests.test_throw_goes_to_original_parentc                 C   sT   |  t}t tt |  W d    n1 sw   Y  | t|jd d S )Nz1throw() third argument must be a traceback object)	r-   	TypeErrorr   r   r   	Exceptionr   r   	exceptionr   excr	   r	   r
   test_non_traceback_paramf   s   z#ThrowTests.test_non_traceback_paramc                 C   sT   |  t}t t t  W d    n1 sw   Y  | t|j	d d S )Nz0instance exception may not have a separate value)
r-   r1   r   r   r   r2   BaseExceptionr   r   r3   r4   r	   r	   r
   test_instance_of_wrong_typep   s   z&ThrowTests.test_instance_of_wrong_typec                 C   sN   |  t}t d W d    n1 sw   Y  | t|jd d S )Nabcz1exceptions must be classes, or instances, not str)r-   r1   r   r   r   r   r   r3   r4   r	   r	   r
   test_not_throwablez   s   zThrowTests.test_not_throwableN)
__name__
__module____qualname__r   r   r$   r0   r6   r8   r:   r	   r	   r	   r
   r      s    (

r   )r   r    r   r   r   r	   r	   r	   r
   <module>   s
    