U
    Ze3                     @   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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 )znose 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)Failure)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S ) r   zThe 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   sb   t |tjstd| || _|d k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Callable	TypeErrortestr   configZtbinfoZcapturedOutputresultProxypluginsZpassedunittestTestCase__init__)selfr   r   r    r   h/mounts/lovelace/software/anaconda3/envs/qiime2-amplicon-2024.2/lib/python3.8/site-packages/nose/case.pyr      s    zTest.__init__c                 O   s   | j ||S N)run)r   argkwargr   r   r   __call__-   s    zTest.__call__c                 C   s"   | j | }|d k	r|S t| jS r   )r   ZtestNamestrr   )r   namer   r   r   __str__0   s    zTest.__str__c                 C   s
   d| j  S )NzTest(%r))r   r   r   r   r   __repr__6   s    zTest.__repr__c                 C   s.   z
|j }W n tk
r   Y nX || j dS )z>Called after test is complete (after result.stopTest)
        N)	afterTestAttributeErrorr   )r   resultr!   r   r   r   r!   9   s
    
zTest.afterTestc                 C   s.   z
|j }W n tk
r   Y nX || j dS )z<Called before test is run (before result.startTest)
        N)
beforeTestr"   r   )r   r#   r$   r   r   r   r$   C   s
    
zTest.beforeTestc                 C   s   t  \}}}|||fS )z Extract exception info.
        )sysexc_info)r   excZexvtbr   r   r   r&   M   s    zTest.exc_infoc                 C   s
   | j  S )z0Get a short(er) description of the test
        )r   idr   r   r   r   r)   S   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+   X   s    
zTest.addressc                 C   sh   z
| j jW S  tk
r   Y nX z
| j jW S  tk
r>   Y nX zt| j jW S  tk
rb   Y nX d S r   )r   contextr"   	__class__r   
__module__r   r   r   r   _contextc   s    

zTest._contextz-Get the context object of this test (if any).c              	   C   sv   | j r|  || }zRz| | | | W n4 tk
rB    Y n    t }|| | Y nX W 5 | | X dS )a  Modified run for the test wrapper.

        From here we don't call result.startTest or stopTest or
        addSuccess.  The wrapper calls addError/addFailure only if its
        own setup or teardown fails, or running the wrapped test fails
        (eg, if the wrapped "test" is not callable).

        Two additional methods are called, beforeTest and
        afterTest. These give plugins a chance to modify the wrapped
        test before it is called and do cleanup after it is
        called. They are called unconditionally.
        N)r   r!   r$   runTestKeyboardInterruptr%   r&   ZaddError)r   r#   errr   r   r   r   t   s    
zTest.runc                 C   s,   | j }| jj| }|dk	r |}|| dS )zRun 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prepareTestCase)r   r#   r   Z	plug_testr   r   r   r1      s
    zTest.runTestc                 C   s   | j | }|d k	r|S | j}z|j |_W n: tk
rh   z|j |_W n tk
rb   Y nX Y nX z| j }W n tk
r   Y nX z|t	| jkrW d S W n tk
r   Y nX |S r   )
r   ZdescribeTestr   Z_testMethodDocstripr"   Z_TestCase__testMethodDocshortDescription	Exceptionr   )r   descr   r   r   r   r5      s,    
zTest.shortDescription)NN)__name__r/   __qualname____doc____test__r   r   r   r    r!   r$   r&   r)   r+   r0   propertyr-   r   r1   r5   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 )
TestBasezBCommon functionality for FunctionTestCase and MethodTestCase.
    Fc                 C   s   t | S r   )r   r   r   r   r   r)      s    zTestBase.idc                 C   s   | j | j  d S r   )r   r   r   r   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   r>   _descriptorsgetattrr   r4   split)r   funcr   docr   r   r   r5      s    zTestBase.shortDescriptionN)r8   r/   r9   r:   r;   r)   r1   r5   r   r   r   r   r=      s
   r=   c                   @   sj   e Zd ZdZdZdde df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 )FunctionTestCasezTestCase wrapper for test functions.

    Don't use this class directly; it is used internally in nose to
    create test cases for test functions.
    FNc                 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 is to support generator functions.
        N)r   	setUpFunctearDownFuncr   
descriptorr=   r   )r   r   setUptearDownr   rH   r   r   r   r      s    zFunctionTestCase.__init__c                 C   s"   | j dk	rt| j S t| jS dS r*   N)rH   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 )z=Run any setup function attached to the test function
        )setuprI   rF   N)rF   r   r   r   namesr   r   r   rI     s    
zFunctionTestCase.setUpc                 C   s$   | j r|    nd}t| j| dS )z@Run any teardown function attached to the test function
        )teardownrJ   rG   N)rG   r   r   rM   r   r   r   rJ     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)r@   r,   rP   r8   r/   r   rC   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 )af  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)rH   r   r   r   r   r   r   r@   &  s    zFunctionTestCase._descriptors)r8   r/   r9   r:   r;   tupler   r+   r0   r<   r-   rI   rJ   r   r    r@   r   r   r   r   rE      s   

		rE   c                   @   sh   e Zd ZdZdZde df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 )MethodTestCasezTest case wrapper for test methods.

    Don't use this class directly; it is used internally in nose to
    create test cases for test methods.
    FNc                 C   sj   || _ || _|| _|| _t|r(td|jj| _|  | _	| jdk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   rH   r   
ValueError__self__r.   clsinstr8   rA   r=   r   )r   rU   r   r   rH   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 )NrP   z%s.%s.%srQ   )r@   r,   rP   r8   rX   r/   rR   r   r   r   r   `  s    
zMethodTestCase.__str__c                 C   s"   | j dk	rt| j S t| jS dS rK   )rH   r   rU   r   r   r   r   r+   n  s    

zMethodTestCase.addressc                 C   s   | j S r   )rX   r   r   r   r   r0   x  s    zMethodTestCase._contextz Get context (class) of this testc                 C   s   t | jd d S )N)rL   rI   r   rY   r   r   r   r   rI   }  s    zMethodTestCase.setUpc                 C   s   t | jd d S )N)rO   rJ   r[   r   r   r   r   rJ     s    zMethodTestCase.tearDownc                 C   s"   | j r| j | jfS | j| jfS dS )ag  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)rH   r   rU   r   r   r   r   r@     s    zMethodTestCase._descriptors)r8   r/   r9   r:   r;   rS   r   r   r    r+   r0   r<   r-   rI   rJ   r@   r   r   r   r   rT   4  s   $
rT   )r:   loggingr%   r   inspectr   Znose.configr   Znose.failurer   Z	nose.utilr   r   r   r
   	getLoggerr8   log__all__r   r   r=   rE   rT   r   r   r   r   <module>   s   
 *b