a
    DfG                     @   s   d dl Z d dlZd dlZd dlZd dlmZ ejeje	d  Z
ejd eje
d dddddd d	ZG d
d de jZG dd deZdS )    N)ComparisonTestCasez..2   (         
   )CRITICALERRORWARNINGINFODEBUGVERBOSEc                       sJ   e Zd ZdZ fddZdd Zdd Zdd	d
Zdd Zdd Z	  Z
S )MockLoggingHandlerz
    Mock logging handler to check for expected logs used by
    LoggingComparisonTestCase.

    Messages are available from an instance's ``messages`` dict, in
    order, indexed by a lowercase log level string (e.g., 'debug',
    'info', etc.).c                    s:   g g g g g g d| _ ddddd| _t j|i | d S )Nr   r   r
   r	   r   r   zparam.param.warning()zparam.param.message()zparam.param.verbose()zparam.param.debug())r
   r   r   r   )messagesparam_methodssuper__init__)selfargskwargs	__class__ b/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/holoviews/tests/utils.pyr      s    zMockLoggingHandler.__init__c                 C   s:   |    z"| j|j |  W |   n
|   0 dS )z5Store a message to the instance's messages dictionaryN)acquirer   	levelnameappend
getMessagerelease)r   recordr   r   r   emit$   s    zMockLoggingHandler.emitc                 C   s(   |    g g g g g g d| _|   d S )Nr   )r   r   r   )r   r   r   r   reset,   s
    zMockLoggingHandler.reset   c                 C   s   dd | j | | d D S )z4Returns the last n lines captured at the given levelc                 S   s   g | ]}t |qS r   )str).0elr   r   r   
<listcomp>4       z+MockLoggingHandler.tail.<locals>.<listcomp>N)r   )r   levelnr   r   r   tail2   s    zMockLoggingHandler.tailc                 C   s   d}| j |dd}t|dkr:tdj| j| t|d|d |spt|j| j| t|d t|dn| j| d d	S )
zq
        Assert that the last line captured at the given level ends with
        a particular substring.
        z6

{method}: {last_line}
does not end with:
{substring}r#   r*   r   $Missing {method} output: {substring}method	substringr/   	last_liner0   N)	r+   lenAssertionErrorformatr   reprendswithr   popr   r)   r0   msgr2   r   r   r   assertEndsWith6   s    

z!MockLoggingHandler.assertEndsWithc                 C   s   d}| j |dd}t|dkr:tdj| j| t|d||d vrnt|j| j| t|d t|dn| j| d d	S )
zp
        Assert that the last line captured at the given level contains a
        particular substring.
        z5

{method}: {last_line}
does not contain:
{substring}r#   r,   r   r-   r.   r1   r3   N)r+   r4   r5   r6   r   r7   r   r9   r:   r   r   r   assertContainsH   s    

z!MockLoggingHandler.assertContains)r#   )__name__
__module____qualname____doc__r   r!   r"   r+   r<   r=   __classcell__r   r   r   r   r      s   

r   c                       s,   e Zd ZdZ fddZ fddZ  ZS )LoggingComparisonTestCasez
    ComparisonTestCase with support for capturing param logging output.

    Subclasses must call super setUp to make the
    tests independent. Testing can then be done via the
    self.log_handler.tail and self.log_handler.assertEndsWith methods.
    c                    s>   t    tj }|j| _g |_tdd| _|| j d S )Nr   )r)   )	r   setUpparamparameterized
get_loggerhandlersr   log_handler
addHandler)r   logr   r   r   rD   c   s    

zLoggingComparisonTestCase.setUpc                    s^   t    tj }| j|_| jj}| j  |	 D ]"\}}|D ]}|
t| | qBq6d S )N)r   tearDownrE   rF   rG   rH   rI   r   r"   itemsrK   LEVELS)r   rK   r   r)   Zmsgsr;   r   r   r   rL   k   s    


z"LoggingComparisonTestCase.tearDown)r>   r?   r@   rA   rD   rL   rB   r   r   r   r   rC   Z   s   rC   )loggingossysrE   Zholoviews.element.comparisonr   pathabspathsplit__file__cwdinsertjoinrN   Handlerr   rC   r   r   r   r   <module>   s   I