a
    ñ»j>/  ã                   @   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	m
Z
mZ ddlZe e¡ZdgZG dd„ dejƒZG dd	„ d	ejƒZG d
d„ deƒZG dd„ deƒZdS )zÝnose unittest.TestCase subclasses. It is not necessary to subclass these
classes when writing tests; they are used internally by nose.loader.TestLoader
to create test cases from test functions and methods in test classes.é    N)Ú
isfunction)ÚConfig)Úresolve_nameÚtest_addressÚtry_runÚTestc                   @   s”   e Zd 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eedddƒZdd„ Zdd„ Zdd„ Zdd „ ZdS )"r   zßThe universal test case wrapper.
    When a plugin sees a test, it will always see an instance of this
    class. To access the actual test case that will be run, access the
    test property of the nose.case.Test instance.FNc                 C   sd   t |tjjƒstd| ƒ‚|| _|d u r.tƒ }|| _d | _d | _	|| _
|j| _d | _tj | ¡ d S )NzTnose.case.Test called with argument %r that is not callable. A callable is required.)Ú
isinstanceÚcollectionsÚabcÚCallableÚ	TypeErrorÚtestr   ÚconfigZtbinfoZcapturedOutputÚresultProxyÚpluginsZpassedÚunittestÚTestCaseÚ__init__)Úselfr   r   r   © r   ú/E:\soccer\ml_env\Lib\site-packages\nose/case.pyr      s     þÿzTest.__init__c                 O   s   | j |i |¤ŽS ©N)Úrun)r   ÚargÚkwargr   r   r   Ú__call__)   s    zTest.__call__c                 C   s"   | j  | ¡}|d ur|S t| jƒS r   )r   ZtestNameÚstrr   )r   Únamer   r   r   Ú__str__,   s    zTest.__str__c                 C   s
   d| j  S )NzTest(%r))r   ©r   r   r   r   Ú__repr__2   s    zTest.__repr__c                 C   s,   z
|j }W n ty   Y n0 || jƒ dS )z5Called after test is complete (after result.stopTest)N)Ú	afterTestÚAttributeErrorr   )r   Úresultr!   r   r   r   r!   5   s
    
zTest.afterTestc                 C   s,   z
|j }W n ty   Y n0 || jƒ dS )z3Called before test is run (before result.startTest)N)Ú
beforeTestr"   r   )r   r#   r$   r   r   r   r$   >   s
    
zTest.beforeTestc                 C   s   t  ¡ \}}}|||fS r   )ÚsysÚexc_info)r   ÚexcZexvÚtbr   r   r   r&   G   s    zTest.exc_infoc                 C   s
   | j  ¡ S r   )r   Úidr   r   r   r   r)   K   s    zTest.idc                 C   s$   t | jdƒr| j ¡ S t| jƒS dS )ú¿Return a round-trip name for this test, a name that can be
        fed back as input to loadTestByName and (assuming the same
        plugin configuration) result in the loading of this test.ÚaddressN)Úhasattrr   r+   r   r   r   r   r   r+   N   s    
zTest.addressc                 C   sb   z
| j jW S  ty   Y n0 z
| j jW S  ty:   Y n0 zt| j jƒW S  ty\   Y n0 d S r   )r   Úcontextr"   Ú	__class__r   Ú
__module__r   r   r   r   Ú_contextW   s    

zTest._contextz-Get the context object of this test (if any).c              	   C   s„   | j r|   || ¡}z`z|  |¡ |  |¡ W n8 ty@   ‚ Y n& tyd   t ¡ }| | |¡ Y n0 W |  |¡ n|  |¡ 0 dS )zµModified run for the test wrapper.
        The wrapper calls addError/addFailure if own setup or teardown fails.
        Two additional methods are called: beforeTest and afterTest.N)	r   r$   ÚrunTestÚKeyboardInterruptÚ	Exceptionr%   r&   ZaddErrorr!   )r   r#   Úerrr   r   r   r   i   s    
zTest.runc                  O   s   d S r   r   )ÚargsÚkwargsr   r   r   ÚaddDuration{   s    zTest.addDurationc                 C   s4   | j }| jj | ¡}|dur |}| j|_||ƒ dS )z±Run the test. Plugins may alter the test by returning a
        value from prepareTestCase. The value must be callable and
        must accept one argument, the result instance.N)r   r   r   ZprepareTestCaser7   )r   r#   r   Z	plug_testr   r   r   r1   ~   s    zTest.runTestc                 C   s¸   | j  | ¡}|d ur|S | j}z|j ¡ |_W n6 tyd   z|j ¡ |_W n ty^   Y n0 Y n0 z| j ¡ }W n ty†   Y n0 z|t	| jƒkržW d S W n ty²   Y n0 |S r   )
r   ZdescribeTestr   Z_testMethodDocÚstripr"   Z_TestCase__testMethodDocÚshortDescriptionr3   r   )r   Údescr   r   r   r   r9   ‰   s,    ÿ
zTest.shortDescription)NN)Ú__name__r/   Ú__qualname__Ú__doc__Ú__test__r   r   r   r    r!   r$   r&   r)   r+   r0   Úpropertyr-   r   r7   r1   r9   r   r   r   r   r      s&   
			ÿc                   @   s,   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	S )
ÚTestBasez=Common functionality for FunctionTestCase and MethodTestCase.Fc                 C   s   t | ƒS r   )r   r   r   r   r   r)   ¦   s    zTestBase.idc              
   C   sT   z| j | jŽ  W n> tyN } z&dt|ƒv r8|  d¡ n‚ W Y d }~n
d }~0 0 d S )Nzrequired positional argumentz'pynose doesn't support pytest fixtures.)r   r   r3   r   ZskipTest)r   Úer   r   r   r1   ©   s    zTestBase.runTestc                 C   sN   t | jdƒr| jjS |  ¡ \}}t|dd ƒ}|s8t| ƒ}| ¡  d¡d  ¡ S )NÚdescriptionr=   Ú
r   )r,   r   rB   Ú_descriptorsÚgetattrr   r8   Úsplit)r   Úfuncr   Údocr   r   r   r9   ²   s    zTestBase.shortDescriptionN)r;   r/   r<   r=   r>   r)   r1   r9   r   r   r   r   r@   ¢   s
   	r@   c                   @   s`   e Zd ZdZdZddd„Zdd„ Zd	d
„ ZeedddƒZ	dd„ Z
dd„ Zdd„ ZeZdd„ ZdS )ÚFunctionTestCasez’TestCase wrapper for test functions.
    Don't use this class directly; it is used internally in nose to
    create test cases for test functions.FNr   c                 C   s,   || _ || _|| _|| _|| _t | ¡ dS )aú  Initialize the MethodTestCase.
        Required argument:
        * test -- the test function to call.
        Optional arguments:
        * setUp -- function to run at setup.
        * tearDown -- function to run at teardown.
        * arg -- arguments to pass to the test function. This is to support
          generator functions that yield arguments.
        * descriptor -- the function, other than the test, that should be used
          to construct the test name. This supports generator functions.N)r   Ú	setUpFuncÚtearDownFuncr   Ú
descriptorr@   r   )r   r   ÚsetUpÚtearDownr   rL   r   r   r   r   Â   s    zFunctionTestCase.__init__c                 C   s"   | j durt| j ƒS t| jƒS dS ©r*   N)rL   r   r   r   r   r   r   r+   Ö   s    

zFunctionTestCase.addressc                 C   s   t | jjƒS r   )r   r   r/   r   r   r   r   r0   ß   s    zFunctionTestCase._contextz!Get context (module) of this testc                 C   s$   | j r|   ¡  nd}t| j|ƒ dS )z4Run any setup function attached to the test function)ÚsetuprM   rJ   N)rJ   r   r   ©r   Únamesr   r   r   rM   å   s    
zFunctionTestCase.setUpc                 C   s$   | j r|   ¡  nd}t| j|ƒ dS )z7Run any teardown function attached to the test function)ÚteardownrN   rK   N)rK   r   r   rQ   r   r   r   rN   í   s    
zFunctionTestCase.tearDownc                 C   sF   |   ¡ \}}t|dƒr|j}n|j}d|j|f }|rBd||f }|S )NÚcompat_func_namez%s.%sú%s%s)rD   r,   rT   r;   r/   ©r   rG   r   r   r   r   r   r   õ   s    
zFunctionTestCase.__str__c                 C   s"   | j r| j | jfS | j| jfS dS )a]  Get the descriptors of the test function: the function and
        arguments that will be used to construct the test name. In
        most cases, this is the function itself and no arguments. For
        tests generated by generator functions, the original
        (generator) function and args passed to the generated function
        are returned.N)rL   r   r   r   r   r   r   rD     s    zFunctionTestCase._descriptors)NNr   N)r;   r/   r<   r=   r>   r   r+   r0   r?   r-   rM   rN   r   r    rD   r   r   r   r   rI   ¼   s    ÿ
	ÿ
rI   c                   @   s`   e Zd ZdZdZddd„Zdd„ ZeZd	d
„ Zdd„ Z	e
e	dddƒZdd„ Zdd„ Zdd„ ZdS )ÚMethodTestCasez�Test case wrapper for test methods.
    Don't use this class directly; it is used internally in nose to
    create test cases for test methods.FNr   c                 C   sj   || _ || _|| _|| _t|ƒr(tdƒ‚|jj| _|  ¡ | _	| jdu r\| j j
}t| j	|ƒ| _t | ¡ dS )a£  Initialize the MethodTestCase.
        Required argument:
        * method -- the method to call, may be bound or unbound. In either
          case, a new instance of the method's class will be instantiated to
          make the call.  Note: In Python 3.x, if using an unbound method, you
          must wrap it using pyversion.unbound_method.
        Optional arguments:
        * test -- the test function to call. If this is passed, it will be
          called instead of getting a new bound method of the same name as the
          desired method from the test instance. This is to support generator
          methods that yield inline functions.
        * arg -- arguments to pass to the test function. This is to support
          generator methods that yield arguments.
        * descriptor -- the function, other than the test, that should be used
          to construct the test name. This is to support generator methods.z_Unbound methods must be wrapped using pyversion.unbound_method before passing to MethodTestCaseN)Úmethodr   r   rL   r   Ú
ValueErrorÚ__self__r.   ÚclsÚinstr;   rE   r@   r   )r   rX   r   r   rL   Úmethod_namer   r   r   r     s    ÿ


zMethodTestCase.__init__c                 C   sN   |   ¡ \}}t|dƒr|j}n|j}d| jj| jj|f }|rJd||f }|S )NrT   z%s.%s.%srU   )rD   r,   rT   r;   r[   r/   rV   r   r   r   r   4  s    
zMethodTestCase.__str__c                 C   s"   | j durt| j ƒS t| jƒS dS rO   )rL   r   rX   r   r   r   r   r+   @  s    

zMethodTestCase.addressc                 C   s   | j S r   )r[   r   r   r   r   r0   I  s    zMethodTestCase._contextz Get context (class) of this testc                 C   s   t | jdƒ d S )N)rP   rM   ©r   r\   r   r   r   r   rM   O  s    zMethodTestCase.setUpc                 C   s   t | jdƒ d S )N)rS   rN   r^   r   r   r   r   rN   R  s    zMethodTestCase.tearDownc                 C   s"   | j r| j | jfS | j| jfS dS )a]  Get the descriptors of the test method: the method and
        arguments that will be used to construct the test name. In
        most cases, this is the method itself and no arguments. For
        tests generated by generator methods, the original
        (generator) method and args passed to the generated method
        or function are returned.N)rL   r   rX   r   r   r   r   rD   U  s    zMethodTestCase._descriptors)Nr   N)r;   r/   r<   r=   r>   r   r   r    r+   r0   r?   r-   rM   rN   rD   r   r   r   r   rW     s   
 
	ÿrW   )r=   Úloggingr%   r   Úinspectr   Znose.configr   Z	nose.utilr   r   r   r	   Ú	getLoggerr;   ÚlogÚ__all__r   r   r@   rI   rW   r   r   r   r   Ú<module>   s   
 R