a
    ҏi                     @   sl   d dl mZ d dl mZ d dlZd dlZddlmZ ddlmZ G dd deZe	d	krhd dl
Z
e
  dS )
    )print_function)absolute_importN   )_test_extension)TestCasec                   @   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d Z
dd Zdd Zdd ZdS )	CAPITestsc              	   C   s    |  dttdd  d S )N2   c                   S   s   dS )Nr    r	   r	   r	   W/home/Claro/venv/lib/python3.9/site-packages/greenlet/tests/test_extension_interface.py<lambda>       z'CAPITests.test_switch.<locals>.<lambda>)assertEqualr   test_switchgreenletselfr	   r	   r
   r      s    zCAPITests.test_switchc                 C   s.   dd }t  |}| dtj|ddd d S )Nc                 S   s   | | S Nr	   xyr	   r	   r
   adder   s    z+CAPITests.test_switch_kwargs.<locals>.adder         r   )r   r   r   test_switch_kwargs)r   r   gr	   r	   r
   r      s    
zCAPITests.test_switch_kwargsc                 C   s,   dd }t  | }| d t| d S )Nc                  S   sB   dd } t  | }|  t  j| t  jtd d S )Nc                   S   s(   t  j  t  j  tdd S )Nz#Should never have reached this code)r   
getcurrentparentswitchAssertionErrorr	   r	   r	   r
   bar   s    z2CAPITests.test_setparent.<locals>.foo.<locals>.barzShould never reach this code)r   r   r   r   throwr   )r    childr	   r	   r
   foo   s    

z%CAPITests.test_setparent.<locals>.foo)r   r   r   r   test_setparent)r   r#   Z	foo_childr	   r	   r
   r$      s    zCAPITests.test_setparentc                 C   s   t   d S r   )r   test_getcurrentr   r	   r	   r
   r%   *   s    zCAPITests.test_getcurrentc                 C   s   |  dtdd  d S )Nc                   S   s   dS )Nr&   r	   r	   r	   r	   r
   r   .   r   z-CAPITests.test_new_greenlet.<locals>.<lambda>)r   r   test_new_greenletr   r	   r	   r
   r'   -   s    zCAPITests.test_new_greenletc                 C   s   |  tjtj d S r   )assertRaisesr   GreenletExitr   Ztest_raise_dead_greenletr   r	   r	   r
   test_raise_greenlet_dead0   s    z"CAPITests.test_raise_greenlet_deadc                 C   s   |  tjtj d S r   )r(   r   errorr   test_raise_greenlet_errorr   r	   r	   r
   r,   4   s    z#CAPITests.test_raise_greenlet_errorc                    sl   g   fdd}t  |}|  t| | t d | t d td | t	 d dd d S )Nc                      sR   zt  j  W n: ty6    t d  Y n t jyL   t	Y n0 d S )Nr   )
r   r   r   r   
ValueErrorappendsysexc_infor)   r   r	   seenr	   r
   r#   ;   s    z!CAPITests.test_throw.<locals>.foor   r   z"ValueError was not raised in foo()ztake that sucka!zmessage doesn't match)
r   r   r   
test_throwr   len
assertTrue
isinstancer-   str)r   r#   r   r	   r1   r
   r3   8   s    


zCAPITests.test_throwc                 C   sV   |  t&}tt tt |  W d    n1 s60    Y  | t|j	d d S )Nz1throw() third argument must be a traceback object)
r(   	TypeErrorr   test_throw_exactr   r   	Exceptionr   r7   	exceptionr   excr	   r	   r
   test_non_traceback_paramN   s    "z"CAPITests.test_non_traceback_paramc                 C   sX   |  t(}tt t t d  W d    n1 s80    Y  | t	|j
d d S )Nz0instance exception may not have a separate value)r(   r8   r   r9   r   r   r:   BaseExceptionr   r7   r;   r<   r	   r	   r
   test_instance_of_wrong_typeY   s    "z%CAPITests.test_instance_of_wrong_typec                 C   sT   |  t$}tt dd d  W d    n1 s40    Y  | t|jd d S )Nabcz1exceptions must be classes, or instances, not str)	r(   r8   r   r9   r   r   r   r7   r;   r<   r	   r	   r
   test_not_throwablee   s    "zCAPITests.test_not_throwableN)__name__
__module____qualname__r   r   r$   r%   r'   r*   r,   r3   r>   r@   rB   r	   r	   r	   r
   r      s   r   __main__)
__future__r   r   r/   r    r   r   r   rC   Zunittestmainr	   r	   r	   r
   <module>   s   e