
    YHh(                    n   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mZ d dlmZ  G d d	e      Ze	 	 	 d	 	 	 	 	 	 	 dd       Ze	 	 	 d	 	 	 	 	 	 	 dd       Zd
eej(                  df	 	 	 	 	 	 	 	 	 	 	 ddZedd       Z G d dej.                        Z e       Z	 	 	 d	 	 	 	 	 	 	 	 	 ddZy)    )annotationsN)Iterator)contextmanager)format_exception)AnyNoReturn)ROOT_LOGGERc                      e Zd ZdZy)LogAssertionErrorz6An assertion error raised in relation to log messages.N)__name__
__module____qualname____doc__     M/var/www/html/planif/env/lib/python3.12/site-packages/reactpy/testing/logs.pyr   r      s    @r   r    c           	   #  6  K   t        j                  |       }t        j                  |      }t               5 }	 d t        |      D ]  }|j	                  |j                               s#|7|j                  2|j                  d   Bt        |j                  d   |      s\|r>|j                  k|j	                  dj                  t        |j                               s n t        d| ||       	 ddd       y# t        $ r  w xY w# 1 sw Y   yxY ww)zAssert that ReactPy produced a log matching the described message or error.

    Args:
        match_message: Must match a logged message.
        error_type: Checks the type of logged exceptions.
        match_error: Must match an error message.
    Nr   r   z.Could not find a log record matching the given)recompilecapture_reactpy_logslistfindall
getMessageexc_info
issubclassjoinr   _raise_log_message_error	Exception)match_message
error_typematch_errormessage_patternerror_patternlog_recordsrecords          r   assert_reactpy_did_logr'      s     jj/OJJ{+M		 %;$	J {+  $++F,=,=,?@ #*"OO7 & 2 > *6??1+=z J
 ("OO7 - 5 5 "(8&//(J K! 14 )D!	A% %  		% %sV   5DDC?-D+D:D
D$D30D$D6	D?D

DDDc              #     K   	 t        | ||      5  d ddd       t        d| ||       y# 1 sw Y   xY w# t        $ r Y yw xY ww)z3Assert the inverse of :func:`assert_reactpy_logged`Nz(Did find a log record matching the given)r'   r   r   )r    r!   r"   s      r   assert_reactpy_did_not_logr)   I   sW     
#M:{K 	J	
 	!6		
	 	 s5   A9 -9 A69 	AAAATc                L   g }t        j                  |      }t        |       D ]~  \  }}|j                  |k\  s|j                  s#|j                  d   }	|	5t        |	|      sB|j                  t        |	            s]|r| |t        |      z
  = |j                  |	        |S )a  Return a list of logged exception matching the given criteria

    Args:
        log_level: The level of log to check
        exclude_exc_types: Any exception types to ignore
        del_log_records: Whether to delete the log records for yielded exceptions
       )
r   r   	enumeratelevelnor   
isinstancesearchstrlenappend)
r%   patterntypes	log_leveldel_log_recordsfoundcompiled_patternindexr&   errors
             r   list_logged_exceptionsr;   ^   s     "$Ezz'*";/ 
$v>>Y&6??OOA&E!ue,$++CJ7"#ECJ$67U#
$ Lr   c               #  ~  K   t         j                  } t        j                  t        j                         	 t
        t         j                  v rot        t
        j                        }	 t
        j                   t        t
        j                        }g t
        j                  || 	 t        j                  |        yt        j                  t
               	 t
        j                   t        j                  t
               t
        j                  j                          	 t        j                  |        y# t        t
        j                        }g t
        j                  || w xY w# t        j                  t
               t
        j                  j                          w xY w# t        j                  |        w xY ww)z\Capture logs from ReactPy

    Any logs produced in this context are cleared afterwards
    N)r	   levelsetLevelloggingDEBUG_LOG_RECORD_CAPTORhandlersr1   records
addHandlerremoveHandlerclear)original_levelstart_index	end_indexs      r   r   r   |   s=     !&&N'-!5!550889KG(000 2 : :;	DF"**;yA 	^, 	12	/$,,,%%&89&&,,.^,   2 : :;	DF"**;yA %%&89&&,,.^,sX   4F=/F# 'D6 9,F# &F=<F# E' (7F#  F=6.E$$F# '9F  F# #F::F=c                  (     e Zd Zd fdZddZ xZS )_LogRecordCaptorc                0    g | _         t        | 	          y )N)rC   super__init__)self	__class__s    r   rN   z_LogRecordCaptor.__init__   s    02r   c                :    | j                   j                  |       y)NT)rC   r2   )rO   r&   s     r   handlez_LogRecordCaptor.handle   s    F#r   )returnNone)r&   zlogging.LogRecordrS   bool)r   r   r   rN   rR   __classcell__)rP   s   @r   rK   rK      s    r   rK   c                    g }|r|j                  d|       |r|j                  d|        |r|j                  d|       t        | dz   dj                  |      z         )Nzlog message pattern zexception type zerror message pattern  z and )r2   r   r   )prefixr    r!   r"   
conditionss        r   r   r      sq     J00ABCOJ<892;/BC
FSL7<<
+CC
DDr   )r   Nr   )r    r0   r!   type[Exception] | Noner"   r0   rS   zIterator[None])r%   zlist[logging.LogRecord]r3   r0   r4   z!type[Any] | tuple[type[Any], ...]r5   intr6   rU   rS   zlist[BaseException])rS   z!Iterator[list[logging.LogRecord]])
rY   r0   r    r0   r!   r[   r"   r0   rS   r   )
__future__r   r?   r   collections.abcr   
contextlibr   	tracebackr   typingr   r   reactpy.loggingr	   AssertionErrorr   r'   r)   r   ERRORr;   r   NullHandlerrK   rA   r   r   r   r   <module>rf      sr   "  	 $ % &   'A A )-44&4 4 	4 4n )-

&
 
 	
 
, /8]] ( - 	
  < - -6w**  &' 
 )-	EEE 'E 	E
 Er   