a
    ñ»j¨F  ã                   @   s  d Z ddl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mZ ddlZejdkrvG dd	„ d	eƒZe e¡Zeƒ Zd
d„ ZG dd„ deƒZG dd„ dejƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ dejƒZG dd„ dƒZG dd„ dƒZ dS )zß
Test Suites
-----------
Provides a LazySuite, which is a suite whose test list is a generator
function, and ContextSuite,which can run fixtures (setup/teardown
functions or methods) for the context that contains its tests.é    N)ÚTest)ÚConfig)ÚResultProxyFactory)ÚisclassÚresolve_nameÚtry_runÚclic                   @   s   e Zd ZdS )ÚStringExceptionN©Ú__name__Ú
__module__Ú__qualname__© r   r   ú0E:\soccer\ml_env\Lib\site-packages\nose/suite.pyr	      s   r	   c                 C   s   d| j | jf S )Nz%s.%s)r   r   )Úclsr   r   r   Ú	_strclass   s    r   c                   @   s   e Zd ZdS )ÚMixedContextErrorNr
   r   r   r   r   r      s   r   c                       sp   e Zd Zd‡ fdd„	Zdd„ Zdd„ Zdd	„ ZeZd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZeeeddƒZ‡  ZS )Ú	LazySuiter   c                    s   t t| ƒ ¡  |  |¡ d S ©N)Úsuperr   Ú__init__Ú
_set_tests)ÚselfÚtests©Ú	__class__r   r   r       s    zLazySuite.__init__c                 C   s
   t | jƒS r   )ÚiterÚ_tests©r   r   r   r   Ú__iter__$   s    zLazySuite.__iter__c                 C   s   dt | jƒt| ƒf S )Nz<%s tests=generator (%s)>)r   r   Úidr   r   r   r   Ú__repr__'   s    ÿzLazySuite.__repr__c                 C   s
   t  | ¡S r   ©ÚobjectÚ__hash__r   r   r   r   r$   +   s    zLazySuite.__hash__c                 C   s   | j  |¡ d S r   )Ú	_precacheÚappend©r   Útestr   r   r   ÚaddTest0   s    zLazySuite.addTestc                 C   s"   | j D ]}|jr q||ƒ q|S r   )r   Ú
shouldStop)r   Úresultr(   r   r   r   Úrun3   s
    

zLazySuite.runc                 C   sh   t  dt| ƒ¡ | jrdS | jd u r(dS z(t| jƒ}|d urN| j |¡ W dS W n tyb   Y n0 dS )Nztests in %s?TF)ÚlogÚdebugr    r%   Útest_generatorÚnextr&   ÚStopIterationr'   r   r   r   Ú__bool__:   s    


zLazySuite.__bool__c                 c   sD   t  d| j¡ | jD ]
}|V  q| jd u r.d S | jD ]
}|V  q4d S )Nzprecache is %s)r-   r.   r%   r/   r'   r   r   r   Ú
_get_testsI   s    


zLazySuite._get_testsc                 C   sZ   g | _ t|tjƒ}t|tjjƒr.|s.|ƒ | _n(|rF|  |g¡ d | _n|  |¡ d | _d S r   )	r%   Ú
isinstanceÚunittestÚ	TestSuiteÚcollectionsÚabcÚCallabler/   ZaddTests)r   r   Zis_suiter   r   r   r   R   s    

zLazySuite._set_testsNzbAccess the tests in this suite. Access is through a generator, so iteration may not be repeatable.)r   )r   r   r   r   r   r!   r$   Ú__str__r)   r,   r2   r3   r   Úpropertyr   Ú__classcell__r   r   r   r   r      s   	ÿr   c                       sØ   e Zd ZdZejjZdZdZdZ	dZ
dZdZdZdZd-‡ fdd„	Zdd„ ZeZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd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e ee!j"d
d,ƒZ#‡  Z$S )/ÚContextSuitea  ContextSuite executes fixtures (setup and teardown functions or
    methods) for the context containing its tests.
    The context may be explicitly passed. If it is not, a context (or
    nested set of contexts) will be constructed by examining the tests
    in the suite.F)Zsetup_classZ	setup_allZ
setupClassZsetupAllZ
setUpClassZsetUpAll)Zteardown_classZteardown_allZteardownClassZteardownAllZtearDownClassZtearDownAll)Zsetup_moduleZsetupModuleZsetUpModuleÚsetupÚsetUp)Zteardown_moduleZteardownModuleZtearDownModuleÚteardownÚtearDown)Zsetup_packageZsetupPackageZsetUpPackage)Zteardown_packageZteardownPackageZtearDownPackager   NTc                    s`   t  d||t| ƒ¡ || _|| _|d u r.tƒ }|| _|| _d| _|| _	d | _
tt| ƒ |¡ d S )NzContext suite for %s (%s) (%s)F)r-   r.   r    ÚcontextÚfactoryr   ÚconfigÚresultProxyÚhas_runÚ	can_splitÚerror_contextr   r=   r   )r   r   rB   rC   rD   rE   rG   r   r   r   r   x   s    zContextSuite.__init__c                 C   s   dt | jƒt| jd| jƒf S )Nz<%s context=%s>r   )r   r   ÚgetattrrB   r   r   r   r   r!   †   s    þzContextSuite.__repr__c                 C   s$   | j rdt| ƒ| j f S t| ƒS d S )Nz%s:%s)rH   Úreprr   r   r   r   r    Œ   s    zContextSuite.idc                 C   s
   t  | ¡S r   r"   r   r   r   r   r$   ’   s    zContextSuite.__hash__c                 O   s   | j |i |¤ŽS r   ©r,   ©r   ÚargÚkwr   r   r   Ú__call__•   s    zContextSuite.__call__c                 C   s   t  ¡ S r   )ÚsysÚexc_infor   r   r   r   rQ   ˜   s    zContextSuite.exc_infoc                 C   s>   |   ¡ }tjdkr:t|d tƒr:t|d ƒ|d |d f}|S )Nr   r   é   é   )rQ   rP   Úplatformr4   r	   Ústr)r   Úer   r   r   Ú	_exc_info›   s
    
zContextSuite._exc_infoc                 C   sZ  t  dt| ƒ| | j¡ | jr0|  || ¡| }}n
|| }}z|  ¡  W n< tyZ   ‚ Y n* ty‚   d| _| 	| |  
¡ ¡ Y dS 0 z|| jD ] }|jr¤t  d¡  q®||ƒ qŒW d| _z|  ¡  W n< tyÖ   ‚ Y n* t� yþ   d| _| 	| |  
¡ ¡ Y n0 nTd| _z|  ¡  W n> t�y*   ‚ Y n* t�yR   d| _| 	| |  
¡ ¡ Y n0 0 dS )z,Run tests in suite inside of suite fixtures.z#suite %s (%s) run called, tests: %sr>   NZstoppingTr@   )r-   r.   r    r   rE   r?   ÚKeyboardInterruptÚ	ExceptionrH   ZaddErrorrW   r*   rF   rA   )r   r+   Úorigr(   r   r   r   r,   ¢   sH    ÿ


ùzContextSuite.runc                 C   s^   | j }|d u rdS | j||d�r$dS | j}|rZ|j  | g ¡}|D ]}| j||d�r@ dS q@dS )NF)Úctx_callbackT)rB   ÚimplementsAnyFixturerC   Úget)r   r[   rB   rC   Ú	ancestorsÚancestorr   r   r   ÚhasFixturesÃ   s    ÿzContextSuite.hasFixturesc                 C   sr   t |ƒr| j| j }n&| j| j }t|dƒr<|| j| j 7 }d}|D ]}t||ƒrDd} q\qD|d u rh|S |||ƒS )NÚ__path__FT)r   Ú
classSetupÚclassTeardownÚmoduleSetupÚmoduleTeardownÚhasattrÚpackageSetupÚpackageTeardown)r   rB   r[   ÚnamesZfixtÚmr   r   r   r\   Ó   s    

z!ContextSuite.implementsAnyFixturec                 C   sè   t  dt| ƒ| j¡ | s,t  dt| ƒ¡ d S | jrFt  dt| ƒ¡ d S | j}|d u rXd S | j}|rÊ|j | g ¡d d … }|r´| ¡ }t  d|¡ ||jv rœqxt  d|¡ |  	|¡ qx||jvrÔ|  	|¡ n
|  	|¡ d| _t  d¡ d S )Nz suite %s setUp called, tests: %szsuite %s has no testszsuite %s already set upzancestor %s may need setupzancestor %s does need setupTzcompleted suite setup)
r-   r.   r    r   Ú	was_setuprB   rC   r]   ÚpopÚsetupContext)r   rB   rC   r^   r_   r   r   r   r?   ã   s2    


zContextSuite.setUpc                 C   sv   | j j |¡ t d| |¡ | jr>|| jjv r2d S | | jj|< t|ƒrN| j}n| j	}t
|dƒrh| j| }t||ƒ d S )Nz%s setup context %sra   )rD   ÚpluginsZstartContextr-   r.   rC   rk   r   rb   rd   rf   rg   r   ©r   rB   ri   r   r   r   rm   ÿ   s    

zContextSuite.setupContextc                 C   s   | j d u rdS d| j  S )Nz
test suiteztest suite for %s©rB   r   r   r   r   ÚshortDescription  s    
zContextSuite.shortDescriptionc                 C   sð   t  d¡ | jr| jr0t  d| j| jf ¡ d S d| _| j}|d u rRt  d¡ d S | j}|râ|j | g ¡|g }|D ]j}t  d|¡ ||jvrœt  d|¡ qt||jv r´t  d|¡ qt|j| }t  d||¡ || u rt|  |¡ qtn
|  |¡ d S )	Nzcontext teardownz6No reason to teardown (was_setup? %s was_torndown? %s)TzNo context to tear downzancestor %s may need teardownzancestor %s was not setupzancestor %s already torn downz%s setup ancestor %s)r-   r.   rk   Úwas_torndownrB   rC   r]   ÚteardownContext)r   rB   rC   r^   r_   r>   r   r   r   rA     s:    

ÿÿ



zContextSuite.tearDownc                 C   sv   t  d| |¡ | jr0|| jjv r$d S | | jj|< t|ƒr@| j}n| j}t|dƒrZ| j| }t	||ƒ | j
j |¡ d S )Nz%s teardown context %sra   )r-   r.   rC   rr   r   rc   re   rf   rh   r   rD   rn   ZstopContextro   r   r   r   rs   1  s    


zContextSuite.teardownContextc                 c   s>   |   ¡ D ]0}t|ttjfƒr$|V  qt|| j| jd�V  qd S )N©rD   rE   )r3   r4   r   r5   r6   rD   rE   r'   r   r   r   Ú_get_wrapped_tests@  s    
ÿzContextSuite._get_wrapped_testszOAccess the tests in this suite. Tests are returned inside of a context wrapper.)r   NNNNT)N)%r   r   r   Ú__doc__r5   ZTestCaseZfailureExceptionrk   rr   rb   rc   rd   re   rg   rh   r   r!   r:   r    r$   rO   rQ   rW   r,   r`   r\   r?   rm   rq   rA   rs   ru   r;   r   r   r   r<   r   r   r   r   r=   c   s@     ÿ!
	
ÿr=   c                   @   sP   e Zd ZeZddefdd„Zdd„ Zdd„ Zdd	„ Z	d
d„ Z
dd„ Zdd„ ZdS )ÚContextSuiteFactoryNc                 C   sV   |d u rt ƒ }|| _|d ur"|| _|tu r4t|d�}|| _i | _i | _i | _i | _	d S )N)rD   )
r   rD   Ú
suiteClassÚ_defr   rE   ÚsuitesrB   rk   rr   )r   rD   rx   rE   r   r   r   r   Q  s    
zContextSuiteFactory.__init__c                 K   s�   t  d|¡ | dt|ddƒ¡}t  d||¡ |du r||  |¡}z|  |¡}W n, tyz   | j|  |¡dfi |¤Ž Y S 0 | j||fi |¤ŽS )a»  Return ``ContextSuite`` for tests. ``tests`` may either
        be a callable (in which case the resulting ContextSuite will
        have no parent context and be evaluated lazily) or an
        iterable. In that case the tests will wrapped in
        nose.case.Test, be examined and the context of each found and a
        suite of suites returned, organized into a stack with the
        outermost suites belonging to the outermost contexts.zCreate suite for %srB   Nztests %s context %s)	r-   r.   rl   rI   Ú	wrapTestsÚfindContextr   Ú	makeSuiteÚmixedSuites)r   r   rN   rB   r   r   r   rO   _  s    
 zContextSuiteFactory.__call__c                 c   s¨   t  d|¡ |du rdS t|dƒs,t|dƒr4|jj}t|dƒrL|j d¡}n,t|dƒrl|j d¡dd… }ntd	| ƒ‚|r¤t  d
||¡ t	d 
|¡ƒV  | ¡  qxdS )zhThis method returns the packages and modules containing the context.
        This method is a generator.zget ancestry %sNZim_classÚ__self__r   Ú.r   éÿÿÿÿz%s has no ancestors?z %s ancestors %s)r-   r.   rf   r   r   r   Úsplitr   Ú	TypeErrorr   Újoinrl   )r   rB   r^   r   r   r   Úancestryr  s    

zContextSuiteFactory.ancestryc                 C   sf   t |tjjtjfƒrd S d }|D ]@}t|dd ƒ}|d u r:q |d u rH|}q ||kr td||f ƒ‚q |S )NrB   z5Tests with different contexts in same suite! %s != %s)r4   r7   r8   r9   r5   r6   rI   r   )r   r   rB   r(   Úctxr   r   r   r|   …  s"    ÿÿÿzContextSuiteFactory.findContextc                 K   s®   | j |f|| j| | jdœ|¤Ž}|d urª| j |g ¡ |¡ | j |g ¡ |¡ t d|t	|dd ƒ¡ |  
|¡D ]8}| j |g ¡ |¡ | j|  |¡ t d||j¡ qp|S )N)rB   rD   rC   rE   zsuite %s has context %sr   zsuite %s has ancestor %s)rx   rD   rE   rz   Ú
setdefaultr&   rB   r-   r.   rI   r…   r   )r   r   rB   rN   Úsuiter_   r   r   r   r}   —  s&    ÿþþ
ÿzContextSuiteFactory.makeSuitec                 C   s  |sg S |  d¡}|s|gS |}|d d … }t|dd ƒ}|d urü|gt|  |¡ƒ }|D ]¢}|g}g }	|D ]t}
d}t|
dd ƒ}|d u r’|	 |
¡ qj||u r¦| |
¡ qj|  |¡D ]}||u r°| |
¡ d} qÐq°|sj|	 |
¡ qj|rð|  ||¡}|  |	¡}qX|g| S )Nr   rB   FT)rl   rI   Úlistr…   r&   r}   r~   )r   r   Úheadrˆ   ÚtailrB   r^   r_   ÚcommonZremainr(   Zfound_commonZtest_ctxZtest_ancestorr   r   r   r~   ¦  sB    



zContextSuiteFactory.mixedSuitesc                 C   s¢   t  d|¡ t|tjjtjfƒr.t  d¡ |S g }|D ]f}t  d|¡ t|ttjfƒrb| 	|¡ q6t|t
ƒr„| 	| j||jd�¡ q6| 	t|| j| jd�¡ q6|S )Nzwrap %szI won't wrapzwrapping %srp   rt   )r-   r.   r4   r7   r8   r9   r5   r6   r   r&   ÚContextListr}   rB   rD   rE   )r   r   Úwrappedr(   r   r   r   r{   É  s(    ÿ

ýÿzContextSuiteFactory.wrapTests)r   r   r   r=   rx   ry   r   rO   r…   r|   r}   r~   r{   r   r   r   r   rw   N  s   #rw   c                   @   s   e Zd Zddd„Zdd„ ZdS )r�   Nc                 C   s   || _ || _d S r   )r   rB   )r   r   rB   r   r   r   r   ã  s    zContextList.__init__c                 C   s
   t | jƒS r   )r   r   r   r   r   r   r   ç  s    zContextList.__iter__)N)r   r   r   r   r   r   r   r   r   r�   â  s   
r�   c                       s4   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Z‡  ZS )	ÚFinalizingSuiteWrapperc                    s   t t| ƒ ¡  || _|| _d S r   )r   r�   r   rˆ   Úfinalize)r   rˆ   r�   r   r   r   r   ì  s    zFinalizingSuiteWrapper.__init__c                 O   s   | j |i |¤ŽS r   rK   rL   r   r   r   rO   ñ  s    zFinalizingSuiteWrapper.__call__c                 C   s
   t | jƒS r   )r   rˆ   r   r   r   r   r   ô  s    zFinalizingSuiteWrapper.__iter__c              
   O   s:   z"| j |i |¤ŽW | j|i |¤Ž S | j|i |¤Ž 0 d S r   )rˆ   r�   rL   r   r   r   r,   ÷  s
    þzFinalizingSuiteWrapper.run)r   r   r   r   rO   r   r,   r<   r   r   r   r   r�   ë  s   r�   c                   @   s   e Zd Zdd„ ZdS )ÚTestDirc                  O   s   t dƒ‚d S )NzvTestDir is not usable. The class is present in nose.suite for backwards compatibility purposes but it may not be used.©ÚNotImplementedError©rM   rN   r   r   r   r   ÿ  s    ÿzTestDir.__init__N©r   r   r   r   r   r   r   r   r‘   þ  s   r‘   c                   @   s   e Zd Zdd„ ZdS )Ú
TestModulec                  O   s   t dƒ‚d S )NzyTestModule is not usable. The class is present in nose.suite for backwards compatibility purposes but it may not be used.r’   r”   r   r   r   r     s    ÿzTestModule.__init__Nr•   r   r   r   r   r–     s   r–   )!rv   ÚloggingrP   r5   Z	nose.caser   Znose.configr   Z
nose.proxyr   Z	nose.utilr   r   r   r7   rT   rY   r	   Ú	getLoggerr   r-   r#   ry   r   r   r6   r   r=   rw   r�   r�   r‘   r–   r   r   r   r   Ú<module>   s.   

D l 	