o
    E6d                     @   s   d dl mZ d dlZd dlZddlmZ G dd deZG dd deZ	G d	d
 d
eZ
G dd deZdd ZG dd deZdS )    )print_functionN   )TestCasec                   @   s   e Zd ZdS )	SomeErrorN)__name__
__module____qualname__ r	   r	   rC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\greenlet/tests/test_tracing.pyr      s    r   c                   @   s2   e Zd ZdZdddZdd Zdd Zd	d
 ZdS )GreenletTracerNFc                 C   s   g | _ || _d S N)actionserror_on_trace)selfr   r	   r	   r
   __init__   s   
zGreenletTracer.__init__c                 G   s   | j | | jrtd S r   )r   appendr   r   r   argsr	   r	   r
   __call__   s   zGreenletTracer.__call__c                 C      t | | _| jS r   )greenletsettraceoldtracer   r   r	   r	   r
   	__enter__      zGreenletTracer.__enter__c                 G      t | j d S r   )r   r   r   r   r	   r	   r
   __exit__      zGreenletTracer.__exit__)Fr   r   r   r   r   r   r   r   r	   r	   r	   r
   r   
   s    
r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	TestGreenletTracingz*
    Tests of ``greenlet.settrace()``
    c              	   C   s   t  }dd }dd }t }t  |}|  t  |}| t|j W d    n1 s/w   Y  | |d||ffd||ffd||ffd||ffg d S )Nc                   S   s   d S r   r	   r	   r	   r	   r
   dummy%      z:TestGreenletTracing.test_a_greenlet_tracing.<locals>.dummyc                   S   s   t  r   )r   r	   r	   r	   r
   dummyexc'      z=TestGreenletTracing.test_a_greenlet_tracing.<locals>.dummyexcswitchthrow)r   
getcurrentr   r%   assertRaisesr   assertEqual)r   mainr!   r#   r   g1g2r	   r	   r
   test_a_greenlet_tracing#   s   






z+TestGreenletTracing.test_a_greenlet_tracingc                    s   t    fdd}t  |}|  tdd}| t|j | t  d  W d    n1 s2w   Y  | |d |ffg d S )Nc                      s       d S r   )r%   r	   r*   r	   r
   r!   9   s   zDTestGreenletTracing.test_b_exception_disables_tracing.<locals>.dummyT)r   r%   )r   r'   r%   r   r(   r   r)   gettrace)r   r!   gr   r	   r.   r
   !test_b_exception_disables_tracing7   s   


z5TestGreenletTracing.test_b_exception_disables_tracingc                 C   s:   t  }| t| W d    d S 1 sw   Y  d S r   )r   r   r   )r   tracerr	   r	   r
   test_set_same_tracer_twiceE   s   "z.TestGreenletTracing.test_set_same_tracer_twiceN)r   r   r   __doc__r-   r1   r3   r	   r	   r	   r
   r       s
    r    c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 ZdS )
PythonTracerNc                 C   s
   g | _ d S r   )r   r   r	   r	   r
   r   R   s   
zPythonTracer.__init__c                 C   s   | j ||jjf d S r   )r   r   f_codeco_name)r   frameeventargr	   r	   r
   r   U   s   zPythonTracer.__call__c                 C   r   r   )sys
setprofiler   r   r   r	   r	   r
   r   Y   r   zPythonTracer.__enter__c                 G   r   r   )r;   r<   r   r   r	   r	   r
   r   ]   r   zPythonTracer.__exit__r   r	   r	   r	   r
   r5   O   s    r5   c                   C   s   dS N*   r	   r	   r	   r	   r
   tpt_callback`   r"   r?   c                   @   sd   e Zd Zd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S )TestPythonTracingz
    Tests of the interaction of ``sys.settrace()``
    with greenlet facilities.

    NOTE: Most of this is probably CPython specific.
    Nc                 C   s@   t  }t  W d    n1 sw   Y  | |g d d S )N)returnr   callr?   rB   r?   rD   r   c_callr   )r5   r?   r)   )r   r   r	   r	   r
   test_trace_events_trivialm   s   
z+TestPythonTracing.test_trace_events_trivialc                 C   s4   t  }|  W d    |S 1 sw   Y  |S r   )r5   r%   r   Zgletr   r	   r	   r
   _trace_switch   s   

zTestPythonTracing._trace_switchc                 C   s   |  |}| |g d d S )N)	rA   )rH   rK   )rD   runrC   rE   rB   rL   )Zc_returnrK   rF   rG   )rK   r)   rJ   r	   r	   r
   $_check_trace_events_func_already_set   s   
z6TestPythonTracing._check_trace_events_func_already_setc                 C   s   dd }|  t| d S )Nc                   S      t  S r   r?   r	   r	   r	   r
   rL      r$   zOTestPythonTracing.test_trace_events_into_greenlet_func_already_set.<locals>.run)rN   r   r   rL   r	   r	   r
   0test_trace_events_into_greenlet_func_already_set   s   zBTestPythonTracing.test_trace_events_into_greenlet_func_already_setc                 C   s"   G dd dt j }| |  d S )Nc                   @   s   e Zd Zdd ZdS )zQTestPythonTracing.test_trace_events_into_greenlet_subclass_already_set.<locals>.Xc                 S   rO   r   rP   r   r	   r	   r
   rL      r$   zUTestPythonTracing.test_trace_events_into_greenlet_subclass_already_set.<locals>.X.runNr   r   r   rL   r	   r	   r	   r
   X   s    rT   )r   rN   r   rT   r	   r	   r
   4test_trace_events_into_greenlet_subclass_already_set   s   zFTestPythonTracing.test_trace_events_into_greenlet_subclass_already_setc                 C   s,   |   t  |  | |jg d d S )N)rA   rC   rE   rM   rC   rE   rF   rG   )r%   r?   r   r)   r   )r   r0   r2   r	   r	   r
   /_check_trace_events_from_greenlet_sets_profiler   s   zATestPythonTracing._check_trace_events_from_greenlet_sets_profilerc                    s(   t    fdd}| t|  d S )Nc                             t S r   r   r?   r	   r2   r	   r
   rL         zQTestPythonTracing.test_trace_events_from_greenlet_func_sets_profiler.<locals>.run)r5   rW   r   rQ   r	   rZ   r
   2test_trace_events_from_greenlet_func_sets_profiler   s
   zDTestPythonTracing.test_trace_events_from_greenlet_func_sets_profilerc                    s.   t   G  fdddtj}| |   d S )Nc                       s   e Zd Z fddZdS )zSTestPythonTracing.test_trace_events_from_greenlet_subclass_sets_profiler.<locals>.Xc                    rX   r   rY   r   rZ   r	   r
   rL      r[   zWTestPythonTracing.test_trace_events_from_greenlet_subclass_sets_profiler.<locals>.X.runNrS   r	   rZ   r	   r
   rT      s    rT   )r5   r   rW   rU   r	   rZ   r
   6test_trace_events_from_greenlet_subclass_sets_profiler   s   zHTestPythonTracing.test_trace_events_from_greenlet_subclass_sets_profilerc                    sn   t  d  d fdd} fdd}t| t|  }| |d t  | jg d d S )Nc                      s       t     t  dS r=   )r   r?   r%   r	   r,   r2   r	   r
   g1_run   s
   zPTestPythonTracing.test_trace_events_multiple_greenlets_switching.<locals>.g1_runc                      s    t     t      d S r   )r?   r   r%   r	   r+   r2   r	   r
   g2_run   s   zPTestPythonTracing.test_trace_events_multiple_greenlets_switching.<locals>.g2_runr>   )	rA   rC   rE   rH   r_   )rD   ra   rC   rE   rF   rG   r5   r   r%   r)   r?   r   r   r_   ra   xr	   r+   r,   r2   r
   .test_trace_events_multiple_greenlets_switching   s   

z@TestPythonTracing.test_trace_events_multiple_greenlets_switchingc                    s~   t  d  d fdd} fdd}t| t|       }| |d t  | jg d d S )Nc                      s.   t  j    t     t  dS r=   )r   r'   parentr%   r   r?   r	   r^   r	   r
   r_      s   zYTestPythonTracing.test_trace_events_multiple_greenlets_switching_siblings.<locals>.g1_runc                      s.   t  j  t    t     d S r   )r   r'   rh   r%   r?   r   r	   r`   r	   r
   ra      s
   zYTestPythonTracing.test_trace_events_multiple_greenlets_switching_siblings.<locals>.g2_runr>   )rA   rC   rE   rb   rC   rE   rF   rG   rc   rd   r	   rf   r
   7test_trace_events_multiple_greenlets_switching_siblings   s   

zITestPythonTracing.test_trace_events_multiple_greenlets_switching_siblings)r   r   r   r4   ZmaxDiffrI   rK   rN   rR   rV   rW   r\   r]   rg   ri   r	   r	   r	   r
   r@   c   s    	
%r@   )
__future__r   r;   r    r   	Exceptionr   objectr   r    r5   r?   r@   r	   r	   r	   r
   <module>   s    1