U
    ËZj  ã                   @   sx   d dl Z d dlZd dlZG dd„ deƒZG dd„ deƒZG dd„ dejƒZG dd	„ d	eƒZ	d
d„ Z
G dd„ dejƒZdS )é    Nc                   @   s   e Zd ZdS )Ú	SomeErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú^/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/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   s   t  | ¡| _| jS r	   )ÚgreenletÚsettraceÚoldtracer
   ©r   r   r   r   Ú	__enter__   s    zGreenletTracer.__enter__c                 G   s   t  | j¡ d S r	   )r   r   r   r   r   r   r   Ú__exit__   s    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S )ÚTestGreenletTracingz*
    Tests of ``greenlet.settrace()``
    c              	   C   sŒ   t  ¡ }dd„ }dd„ }tƒ �0}t   |¡}| ¡  t   |¡}|  t|j¡ W 5 Q R X |  |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#   s    z8TestGreenletTracing.test_greenlet_tracing.<locals>.dummyc                   S   s
   t ƒ ‚d S r	   )r   r   r   r   r   Údummyexc%   s    z;TestGreenletTracing.test_greenlet_tracing.<locals>.dummyexcÚswitchÚthrow)r   Ú
getcurrentr   r   ÚassertRaisesr   ÚassertEqual)r   Úmainr   r   r
   Úg1Úg2r   r   r   Útest_greenlet_tracing!   s    





üz)TestGreenletTracing.test_greenlet_tracingc              	      st   t  ¡ ‰ ‡ fdd„}t   |¡}| ¡  tdd��$}|  t|j¡ |  t  ¡ d ¡ W 5 Q R X |  |dˆ |ffg¡ d S )Nc                      s   ˆ   ¡  d S r	   )r   r   ©r!   r   r   r   7   s    zBTestGreenletTracing.test_exception_disables_tracing.<locals>.dummyT)r   r   )r   r   r   r   r   r   r    Úgettrace)r   r   Úgr
   r   r%   r   Útest_exception_disables_tracing5   s    

ÿz3TestGreenletTracing.test_exception_disables_tracingN)r   r   r   Ú__doc__r$   r(   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   G   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   J   s    zPythonTracer.__call__c                 C   s   t  | ¡| _| jS r	   )ÚsysÚ
setprofiler   r
   r   r   r   r   r   N   s    zPythonTracer.__enter__c                 G   s   t  | j¡ d S r	   )r0   r1   r   r   r   r   r   r   R   s    zPythonTracer.__exit__r   r   r   r   r   r*   D   s
   r*   c                   C   s   dS ©Né*   r   r   r   r   r   Útpt_callbackU   s    r4   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   s2   t ƒ �}tƒ  W 5 Q R X |  |dddddg¡ d S )N©Úreturnr   ©Úcallr4   ©r7   r4   ©r9   r   ©Úc_callr   )r*   r4   r    )r   r
   r   r   r   Útest_trace_events_trivialb   s    	ûz+TestPythonTracing.test_trace_events_trivialc              	   C   s   t ƒ �}| ¡  W 5 Q R X |S r	   )r*   r   ©r   Zgletr
   r   r   r   Ú_trace_switchu   s    zTestPythonTracing._trace_switchc                 C   s,   |   |¡}|  |ddddddddd	g	¡ d S )
Nr6   )r=   r@   )r9   Úrunr8   r:   ©r7   rA   )Zc_returnr@   r;   r<   )r@   r    r?   r   r   r   Ú$_check_trace_events_func_already_setz   s    
÷z6TestPythonTracing._check_trace_events_func_already_setc                 C   s   dd„ }|   t |¡¡ d S )Nc                   S   s   t ƒ S r	   ©r4   r   r   r   r   rA   ‰   s    zOTestPythonTracing.test_trace_events_into_greenlet_func_already_set.<locals>.run)rC   r   ©r   rA   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   s   t ƒ S r	   rD   r   r   r   r   rA   �   s    zUTestPythonTracing.test_trace_events_into_greenlet_subclass_already_set.<locals>.X.runN©r   r   r   rA   r   r   r   r   ÚX�   s   rH   )r   rC   ©r   rH   r   r   r   Ú4test_trace_events_into_greenlet_subclass_already_setŽ   s    zFTestPythonTracing.test_trace_events_into_greenlet_subclass_already_setc                 C   s8   |  ¡  tƒ  | ¡  |  |jddddddddg¡ d S )Nr6   r8   r:   rB   r;   r<   )r   r4   r   r    r
   )r   r'   Útracerr   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                      s   ˆ   ¡  tƒ S r	   ©r   r4   r   ©rK   r   r   rA   ¦   s    zQTestPythonTracing.test_trace_events_from_greenlet_func_sets_profiler.<locals>.run)r*   rL   r   rE   r   rN   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                    s   ˆ   ¡  tƒ S r	   rM   r   rN   r   r   rA   °   s    zWTestPythonTracing.test_trace_events_from_greenlet_subclass_sets_profiler.<locals>.X.runNrG   r   rN   r   r   rH   ¯   s   rH   )r*   r   rL   rI   r   rN   r   Ú6test_trace_events_from_greenlet_subclass_sets_profiler­   s    zHTestPythonTracing.test_trace_events_from_greenlet_subclass_sets_profilerc                    s|   t ƒ ‰d ‰ d ‰‡‡fdd„}‡ ‡fdd„}t |¡‰ t |¡‰ˆ  ¡ }|  |d¡ tƒ  |  ˆjdddd	d
ddddg	¡ d S )Nc                      s    ˆ  ¡  tƒ  ˆ  ¡  tƒ  dS r2   )r   r4   r   r   ©r#   rK   r   r   Úg1_run½   s
    zPTestPythonTracing.test_trace_events_multiple_greenlets_switching.<locals>.g1_runc                      s    t ƒ  ˆ ¡  t ƒ  ˆ  ¡  d S r	   )r4   r   r   r   ©r"   rK   r   r   Úg2_runÄ   s    zPTestPythonTracing.test_trace_events_multiple_greenlets_switching.<locals>.g2_runr3   r6   r8   r:   ©r=   rR   )r9   rT   r;   r<   ©r*   r   r   r    r4   r
   ©r   rR   rT   Úxr   ©r"   r#   rK   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dddd	ddd
dg¡ d S )Nc                      s.   t  ¡ j ¡  ˆ ¡  tƒ  ˆ  ¡  tƒ  dS r2   )r   r   Úparentr   r   r4   r   rQ   r   r   rR   ä   s    zYTestPythonTracing.test_trace_events_multiple_greenlets_switching_siblings.<locals>.g1_runc                      s.   t  ¡ j ¡  tƒ  ˆ ¡  tƒ  ˆ  ¡  d S r	   )r   r   r[   r   r4   r   r   rS   r   r   rT   ì   s
    zYTestPythonTracing.test_trace_events_multiple_greenlets_switching_siblings.<locals>.g2_runr3   r6   r8   r:   rU   r;   r<   rV   rW   r   rY   r   Ú7test_trace_events_multiple_greenlets_switching_siblingsÜ   s,    

øzITestPythonTracing.test_trace_events_multiple_greenlets_switching_siblings)r   r   r   r)   ZmaxDiffr>   r@   rC   rF   rJ   rL   rO   rP   rZ   r\   r   r   r   r   r5   X   s   	
%r5   )r0   Zunittestr   Ú	Exceptionr   Úobjectr   ZTestCaser   r*   r4   r5   r   r   r   r   Ú<module>   s   (