
    pj                    H   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlZd dlZe
rd dlmZ  G d	 d
          ZddZ ej        dd          dd            Z ej        dd          dd            Z ej        dd          dd            ZdS )    )annotationsN)TracebackType)Any)Callable)	Generator)TYPE_CHECKING)Selfc                  2    e Zd ZdZddZddZdd	ZddZdS )catch_threading_exceptiona  Context manager catching threading.Thread exception using
    threading.excepthook.

    Storing exc_value using a custom hook can create a reference cycle. The
    reference cycle is broken explicitly when the context manager exits.

    Storing thread using a custom hook can resurrect it if it is set to an
    object which is being finalized. Exiting the context manager clears the
    stored object.

    Usage:
        with threading_helper.catch_threading_exception() as cm:
            # code spawning a thread which raises an exception
            ...
            # check the thread exception: use cm.args
            ...
        # cm.args attribute no longer exists at this point
        # (to break a reference cycle)
    returnNonec                "    d | _         d | _        d S N)args	_old_hookselfs    g/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/_pytest/threadexception.py__init__z"catch_threading_exception.__init__)   s    59	KO    r   threading.ExceptHookArgsc                    || _         d S r   )r   )r   r   s     r   _hookzcatch_threading_exception._hook-   s    			r   r	   c                J    t           j        | _        | j        t           _        | S r   )	threading
excepthookr   r   r   s    r   	__enter__z#catch_threading_exception.__enter__0   s    "-#z	r   exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | Nonec                L    | j         J | j         t          _        d | _         | `d S r   )r   r   r   r   )r   r   r    r"   s       r   __exit__z"catch_threading_exception.__exit__5   s,     ~)))#~	IIIr   N)r   r   )r   r   r   r   )r   r	   )r   r   r    r!   r"   r#   r   r   )__name__
__module____qualname____doc__r   r   r   r%    r   r   r   r      sr         (P P P P      
	 	 	 	 	 	r   r   r   Generator[None]c               #    K   t                      5 } 	 d V  | j        r| j        j        dn| j        j        j        }d| d}|d                    t          j        | j        j        | j        j        | j        j	                            z  }t          j        t          j        |                     n# | j        r| j        j        dn| j        j        j        }d| d}|d                    t          j        | j        j        | j        j        | j        j	                            z  }t          j        t          j        |                     w w xY wd d d            d S # 1 swxY w Y   d S )Nz	<unknown>zException in thread z

 )r   r   threadnamejoin	tracebackformat_exceptionr   	exc_valueexc_tracebackwarningswarnpytest%PytestUnhandledThreadExceptionWarning)cmthread_namemsgs      r   thread_exception_runtest_hookr<   A   s     	"	$	$ Q	QEEEw Q#%7>#9KKrw~?R  ?[>>>rww.()-    fJ3OOPPP w Q#%7>#9KKrw~?R  ?[>>>rww.()-    fJ3OOPPPPQ	Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Qs)   E#B4BE#4BEE##E'*E'T)wrappertrylastc               #  2   K   t                      E d {V  d S r   r<   r*   r   r   pytest_runtest_setuprA   U   *      ,...........r   )r=   tryfirstc               #  2   K   t                      E d {V  d S r   r@   r*   r   r   pytest_runtest_callrE   Z   rB   r   c               #  2   K   t                      E d {V  d S r   r@   r*   r   r   pytest_runtest_teardownrG   _   rB   r   )r   r+   )
__future__r   r   r1   typesr   typingr   r   r   r   r5   r7   typing_extensionsr	   r   r<   hookimplrA   rE   rG   r*   r   r   <module>rM      s   " " " " " "                                                '&&&&&&* * * * * * * *ZQ Q Q Q( t,,,/ / / -,/ ---/ / / .-/ ---/ / / .-/ / /r   