
    [Fi                     R   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m	Z	 d dl
Z
d dlZ G d d	      Zd
ed   fdZ ej                  dd      d
ed   fd       Z ej                  dd      d
ed   fd       Z ej                  dd      d
ed   fd       Zy)    N)TracebackType)Any)Callable)	Generator)Optional)Typec                   X    e Zd ZdZddZddZddZdeee	      dee	   d	ee
   ddfd
Zy)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)
    returnNc                      d | _         d | _        y N)args	_old_hookselfs    i/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/_pytest/threadexception.py__init__z"catch_threading_exception.__init__$   s    :>	PT    c                     || _         y r   )r   )r   r   s     r   _hookzcatch_threading_exception._hook(   s	    	r   c                 Z    t         j                  | _        | j                  t         _        | S r   )	threading
excepthookr   r   r   s    r   	__enter__z#catch_threading_exception.__enter__+   s     "--#zz	r   exc_typeexc_valexc_tbc                 \    | j                   J | j                   t        _        d | _         | `y r   )r   r   r   r   )r   r   r   r   s       r   __exit__z"catch_threading_exception.__exit__0   s,     ~~)))#~~	Ir   )r   N)r   zthreading.ExceptHookArgsr   N)r   r
   )__name__
__module____qualname____doc__r   r   r   r   r   BaseExceptionr   r    r   r   r
   r
      sV    (U
	4./	 -(	 '		
 
	r   r
   r   )NNNc               #     K   t               5 } 	 d  | j                  r| j                  j                  dn| j                  j                  j                  }d| d}|dj	                  t        j                  | j                  j                  | j                  j                  | j                  j                              z  }t        j                  t        j                  |             	 d d d        y # | j                  r| j                  j                  dn| j                  j                  j                  }d| d}|dj	                  t        j                  | j                  j                  | j                  j                  | j                  j                              z  }t        j                  t        j                  |             w w xY w# 1 sw Y   y xY ww)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_hookr6   <   s|    	"	$ Q	Qww#%77>>#9Krww~~?R?R  -[M>rww..(())--  fJJ3OP!Q Q ww#%77>>#9Krww~~?R?R  -[M>rww..(())--  fJJ3OP 	Q Qs4   GGC4CG+	G4CGGGGT)wrappertrylastc               #   4   K   t               E d {    y 7 wr   r6   r%   r   r   pytest_runtest_setupr;   P        ,...   )r7   tryfirstc               #   4   K   t               E d {    y 7 wr   r:   r%   r   r   pytest_runtest_callr@   U   r<   r=   c               #   4   K   t               E d {    y 7 wr   r:   r%   r   r   pytest_runtest_teardownrB   Z   r<   r=   )r   r+   typesr   typingr   r   r   r   r   r/   r1   r
   r6   hookimplr;   r@   rB   r%   r   r   <module>rF      s             * *ZQy1A'B Q( t,/i(89 / -/ -/Y'78 / ./ -/+;!< / ./r   