U
    Z¬Üeß  ã                   @   sN   d Z ddlZddlmZ e e¡Zdd„ ZG dd„ deƒZ	G dd	„ d	eƒZ
dS )
a—  
Result Proxy
------------

The result proxy wraps the result instance given to each test. It
performs two functions: enabling extended error/failure reporting
and calling plugins.

As each result event is fired, plugins are called with the same event;
however, plugins are called with the nose.case.Test instance that
wraps the actual test. So when a test fails and calls
result.addFailure(self, err), the result proxy calls
addFailure(self.test, err) for each plugin. This allows plugins to
have a single stable interface for all test types, and also to
manipulate the test object itself by setting the `test` attribute of
the nose.case.Test that they receive.
é    N)ÚConfigc                    s8   ‡ ‡fdd„}‡ ‡fdd„}‡ ‡fdd„}t ||||ƒS )znCreate a property that proxies attribute ``proxied_attr`` through
    the local attribute ``local_attr``.
    c                    s   t t | ˆ ƒˆƒS ©N)Úgetattr©Úself©Ú
local_attrÚproxied_attr© úi/mounts/lovelace/software/anaconda3/envs/qiime2-amplicon-2024.2/lib/python3.8/site-packages/nose/proxy.pyÚfget   s    zproxied_attribute.<locals>.fgetc                    s   t t| ˆ ƒˆ|ƒ d S r   )Úsetattrr   )r   Úvaluer   r
   r   Úfset   s    zproxied_attribute.<locals>.fsetc                    s   t t| ˆ ƒˆƒ d S r   )Údelattrr   r   r   r
   r   Úfdel!   s    zproxied_attribute.<locals>.fdel)Úproperty)r   r	   Údocr   r   r   r
   r   r   Úproxied_attribute   s    r   c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )ÚResultProxyFactoryzrFactory for result proxies. Generates a ResultProxy bound to each test
    and the result passed to the test.
    Nc                 C   s$   |d krt ƒ }|| _d| _d | _d S )NF)r   ÚconfigÚ_ResultProxyFactory__preparedÚ_ResultProxyFactory__result)r   r   r
   r
   r   Ú__init__*   s
    zResultProxyFactory.__init__c                 C   sL   | j s,d| _ | jj |¡}|dk	r,| | _}| jdk	r<| j}t||| jdS )a  Return a ResultProxy for the current test.

        On first call, plugins are given a chance to replace the
        result used for the remaining tests. If a plugin returns a
        value from prepareTestResult, that object will be used as the
        result for all tests.
        TN)r   )r   r   ÚpluginsZprepareTestResultr   ÚResultProxy)r   ÚresultÚtestZplug_resultr
   r
   r   Ú__call__1   s    

zResultProxyFactory.__call__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r
   r
   r
   r   r   &   s   
r   c                   @   sª   e Zd ZdZd&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d„ Zdd„ Zdd„ ZedddƒZedd d!ƒZedd"d#ƒZedd$d%ƒZdS )'r   ag  Proxy to TestResults (or other results handler).

    One ResultProxy is created for each nose.case.Test. The result
    proxy calls plugins with the nose.case.Test instance (instead of
    the wrapped test case) as each result call is made. Finally, the
    real result method is called, also with the nose.case.Test
    instance as the test parameter.

    Nc                 C   s,   |d krt ƒ }|| _|j| _|| _|| _d S r   )r   r   r   r   r   )r   r   r   r   r
   r
   r   r   M   s    zResultProxy.__init__c                 C   s
   t | jƒS r   )Úreprr   r   r
   r
   r   Ú__repr__U   s    zResultProxy.__repr__c                 C   sN   t |d tƒsJt |d tƒrJt|d jtfi ƒ|d ƒ}|d ||d f}|S )Né   r   é   )Ú
isinstanceÚ	ExceptionÚtyper   )r   Úerrr   r
   r
   r   Ú_prepareErrX   s    zResultProxy._prepareErrc                 C   sT   t | jdd ƒ}|| jksP||ksP|t |dd ƒksPtd| jt| jƒ|t|ƒf ƒ‚d S )Nr   Z
_nose_casez4ResultProxy for %r (%s) was called with test %r (%s))r   r   ÚAssertionErrorÚid)r   r   Úcaser
   r
   r   ÚassertMyTestb   s    
ÿþÿýzResultProxy.assertMyTestc                 C   s6   |   |¡ | j | j¡ t| jdƒr2| j | j¡ d S )NÚ	afterTest)r/   r   r0   r   Úhasattrr   ©r   r   r
   r
   r   r0   m   s    
zResultProxy.afterTestc                 C   s6   |   |¡ | j | j¡ t| jdƒr2| j | j¡ d S )NÚ
beforeTest)r/   r   r3   r   r1   r   r2   r
   r
   r   r3   s   s    
zResultProxy.beforeTestc                 C   s€   |   |¡ | j}| | j|¡}|r&d S | | j|¡}|d k	r@|}| | j|¡ | j | j|  |¡¡ | j ¡ s|| j	j
r|d| _d S )NT)r/   r   ÚhandleErrorr   ZformatErrorÚaddErrorr   r+   ZwasSuccessfulr   ÚstopOnErrorÚ
shouldStop©r   r   r*   r   Zplugin_handledÚ	formattedr
   r
   r   r5   y   s    
zResultProxy.addErrorc                 C   s~   |   |¡ | j}| | j|¡}|r&d S d| j_| | j|¡}|d k	rH|}| | j|¡ | j | j|  |¡¡ | j	j
rzd| _d S )NFT)r/   r   ZhandleFailurer   ZpassedZformatFailureÚ
addFailurer   r+   r   r6   r7   r8   r
   r
   r   r:   ˆ   s    
zResultProxy.addFailurec                 C   sV   ddl m} |  |¡ | j}t|tƒs.t|ƒ}| | j||d f¡ | j 	| j|¡ d S )Nr   )ÚSkipTest)
Znose.plugins.skipr;   r/   r   r'   r(   r5   r   r   ÚaddSkip)r   r   Úreasonr;   r   r
   r
   r   r<   —   s    

zResultProxy.addSkipc                 C   s*   |   |¡ | j | j¡ | j | j¡ d S r   )r/   r   Ú
addSuccessr   r   r2   r
   r
   r   r>   ¢   s    
zResultProxy.addSuccessc                 C   s*   |   |¡ | j | j¡ | j | j¡ d S r   )r/   r   Ú	startTestr   r   r2   r
   r
   r   r?   §   s    
zResultProxy.startTestc                 C   s   | j  ¡  d S r   )r   Ústopr   r
   r
   r   r@   ¬   s    zResultProxy.stopc                 C   s*   |   |¡ | j | j¡ | j | j¡ d S r   )r/   r   ÚstopTestr   r   r2   r
   r
   r   rA   ¯   s    
zResultProxy.stopTestr   r7   zShould the test run stop?ÚerrorszTests that raised an exceptionÚfailureszTests that failedÚtestsRunzNumber of tests run)N)r   r    r!   r"   r   r$   r+   r/   r0   r3   r5   r:   r<   r>   r?   r@   rA   r   r7   rB   rC   rD   r
   r
   r
   r   r   C   s4   	

ÿÿÿÿr   )r"   ÚloggingZnose.configr   Ú	getLoggerr   Úlogr   Úobjectr   r   r
   r
   r
   r   Ú<module>   s   
