a
    ñ»jL  ã                   @   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 )
a0  
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.
When a test fails and calls result.addFailure(self, err),
the result proxy calls addFailure(self.test, err) for each plugin.é    N)ÚConfigc                    s8   ‡ ‡fdd„}‡ ‡fdd„}‡ ‡fdd„}t ||||ƒS )Nc                    s   t t | ˆ ƒˆƒS ©N)Úgetattr©Úself©Ú
local_attrÚproxied_attr© ú0E:\soccer\ml_env\Lib\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 )ÚResultProxyFactoryz;Generates a ResultProxy bound to each test, and the result.Nc                 C   s$   |d u 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ur,| | _}| jdu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__%   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   zð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.Nc                 C   s,   |d u rt ƒ }|| _|j| _|| _|| _d S r   )r   r   r   r   r   )r   r   r   r   r
   r
   r   r   :   s    zResultProxy.__init__c                 C   s
   t | jƒS r   )Úreprr   r   r
   r
   r   Ú__repr__B   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   Ú_prepareErrE   s    zResultProxy._prepareErrc                 C   sT   t | jdd ƒ}|| ju sP||u sP|t |dd ƒu sPJ d| jt| jƒ|t|ƒf ƒ‚d S )Nr   Z
_nose_casez4ResultProxy for %r (%s) was called with test %r (%s))r   r   Úid)r   r   Úcaser
   r
   r   ÚassertMyTestO   s    
ÿþÿýzResultProxy.assertMyTestc                 C   s6   |   |¡ | j | j¡ t| jdƒr2| j | j¡ d S )NÚ	afterTest)r.   r   r/   r   Úhasattrr   ©r   r   r
   r
   r   r/   Y   s    
zResultProxy.afterTestc                 C   s6   |   |¡ | j | j¡ t| jdƒr2| j | j¡ d S )NÚ
beforeTest)r.   r   r2   r   r0   r   r1   r
   r
   r   r2   _   s    
zResultProxy.beforeTestc                 C   s€   |   |¡ | j}| | j|¡}|r&d S | | j|¡}|d u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   r4   e   s    
zResultProxy.addErrorc                 C   s~   |   |¡ | j}| | j|¡}|r&d S d| j_| | j|¡}|d urH|}| | j|¡ | j | j|  |¡¡ | j	j
rzd| _d S )NFT)r.   r   ZhandleFailurer   ZpassedZformatFailureÚ
addFailurer   r+   r   r5   r6   r7   r
   r
   r   r9   s   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(   r4   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   r1   r
   r
   r   r=   ‹   s    
zResultProxy.addSuccessc                 C   s*   |   |¡ | j | j¡ | j | j¡ d S r   )r.   r   Ú	startTestr   r   r1   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   r1   r
   r
   r   r@   ˜   s    
zResultProxy.stopTestr   r6   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.   r/   r2   r4   r9   r;   r=   r>   r?   r@   r   r6   rA   rB   rC   r
   r
   r
   r   r   5   s4   


	ÿÿÿÿr   )r"   ÚloggingZnose.configr   Ú	getLoggerr   Úlogr   Úobjectr   r   r
   r
   r
   r   Ú<module>   s   
