a
    p=ic8                     @   s  d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
mZ d dlmZ d dlmZ ddlmZ ddlmZmZ G d	d
 d
ejZG dd dejZG dd dejZe ZG dd dejZG dd dZG dd deZ e Z!G dd deZ"G dd dej#j$Z%dS )    N)doctests)
ErrorClassErrorClassPlugin)Plugin)src   )get_package_name)KnownFailureExceptionKnownFailureTestc                   @   s   e Zd Zdd Zdd ZdS )NumpyDocTestFinderc                 C   s   |du rdS t |r"|j|ju S t |r8|j|jkS t |rN|j|jkS t |rh|j|j	j
jkS t |dur|t |u S t|dr|j|jkS t|trdS tddS )zY
        Return true if the given object is defined in the given
        module.
        NT
__module__z"object must be a class or function)inspect
isfunction__dict____globals__	isbuiltin__name__r   isclassismethod__self__	__class__	getmodulehasattr
isinstanceproperty
ValueError)selfmoduleobject r   s/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/numpy/testing/_private/noseclasses.py_from_module   s"    





zNumpyDocTestFinder._from_modulec              
   C   sD  t j| ||||||| ddlm}m}	m}
m}m} |
|r| j	r|j
 D ]H\}}| d| }||st|	|rN| ||rN| ||||||| qN|	|r@| j	r@|j
 D ]\}}t|trt||}t|trt||j}||s|	|s||st|tr| ||r| d| }| ||||||| qdS )zm
        Find tests for the given object and any contained objects, and
        add them to `tests`.
        r   )	isroutiner   ismoduler   r   .N)doctestDocTestFinder_findr   r"   r   r#   r   r   Z_recurser   itemsr!   r   staticmethodgetattrclassmethod__func__r   )r   testsobjnamer   Zsource_linesglobsseenr"   r   r#   r   r   ZvalnamevalZvalname1r   r   r    r'   :   s<    




zNumpyDocTestFinder._findN)r   r   __qualname__r!   r'   r   r   r   r    r      s   r   c                   @   s   e Zd Zdd ZdS )NumpyOutputCheckerc                 C   sz   t j| |||}|svd|v r"dS |dd}|dd}dD ]$}|d| d}|d| d}q>t j| |||}|S )Nz#randomTz'>z'<)      z'<i%d'int)r%   OutputCheckercheck_outputreplace)r   Zwantgotoptionflagsretszr   r   r    r9   l   s    
zNumpyOutputChecker.check_outputN)r   r   r3   r9   r   r   r   r    r4   k   s   r4   c                   @   s   e Zd ZdddZdS )NumpyDocTestCaser   N_c                 C   s(   || _ || _tjj| |||||d d S )N)r<   setUptearDownchecker)Z_result_varZ	_nose_objr%   DocTestCase__init__)r   testr<   rA   rB   rC   r.   
result_varr   r   r    rE      s    
zNumpyDocTestCase.__init__)r   NNNNr@   )r   r   r3   rE   r   r   r   r    r?      s     r?   c                   @   sj   e Zd ZdZdZejejB ZddgZ	e
ZeZeZejfddZdd Zd	d
 Zdd Zdd Zdd ZdS )NumpyDoctestZnumpydoctesti  zgenerate_numpy_api.pyzsetup.pyc                 C   s   t | || d| _d | _d S )NT)r   optionsZdoctest_testsdoctest_result_varr   parserenvr   r   r    rI      s    zNumpyDoctest.optionsc                 C   sB   t | || |  | _t | _| jr>dd |jjD |j_d S )Nc                 S   s   g | ]}|j d kr|qS )r%   )r/   .0pr   r   r    
<listcomp>   s   
z*NumpyDoctest.configure.<locals>.<listcomp>)	r   	configuretest_finder_classfinderr%   ZDocTestParserrL   enabledpluginsr   rI   configr   r   r    rR      s
    

zNumpyDoctest.configurec                 C   sX   t tj|j}tddtd|_d|v rT|d}|d }t	||ji |g|j|< dS )a`   Configure `test` object to set test context

        We set the numpy / scipy standard doctest namespace

        Parameters
        ----------
        test : test object
            with ``globs`` dictionary defining namespace

        Returns
        -------
        None

        Notes
        -----
        `test` object modified in place
        __main__)__builtins____file__r   npZscipyr$   N)
r   ospathdirnamefilenamerZ   numpyr0   split
__import__)r   rF   pkg_namerP   p2r   r   r    set_test_context   s    

zNumpyDoctest.set_test_contextc                 c   s   |  |jstjd| d S z| j|}W n tyB   Y d S 0 |sLd S |  t	|j
}|D ]>}|jsnqb|jsz||_| | | j|| j|  | jdV  qbd S )NzDoctest doesn't want module %s)r<   rC   rG   )matchesr   npdlogdebugrT   findAttributeErrorsortr   r[   Zexamplesra   rg   doctest_case_classdoctest_optflagsout_check_classrJ   )r   r   r-   Zmodule_filerF   r   r   r    loadTestsFromModule   s,    

z NumpyDoctest.loadTestsFromModulec                 C   s   t jf i t d S N)rb   Zset_printoptionsprint_stater   r   r   r    afterContext  s    zNumpyDoctest.afterContextc                 C   s(   t j|}|| jv rdS tj| |S )NF)r^   r_   basenamedoctest_ignoreri   DoctestwantFile)r   filebnr   r   r    rz     s    
zNumpyDoctest.wantFileN)r   r   r3   r/   scorer%   ZNORMALIZE_WHITESPACEELLIPSISrp   rx   r?   ro   r4   rq   r   rS   r^   environrI   rR   rg   rr   rv   rz   r   r   r   r    rH      s   	*rH   c                   @   s6   e Zd ZdZdZdZdZdddZdd	 Zd
d Z	dS )	Unpluggerzi Nose plugin to remove named plugin late in loading

    By default it removes the "doctest" plugin.
    Z	unpluggerTi  r%   c                 C   s
   || _ d S rs   )	to_unplug)r   r   r   r   r    rE     s    zUnplugger.__init__c                 C   s   d S rs   r   rK   r   r   r    rI     s    zUnplugger.optionsc                    s    fdd|j j D |j _ d S )Nc                    s   g | ]}|j  jkr|qS r   )r/   r   rN   ru   r   r    rQ     s   z'Unplugger.configure.<locals>.<listcomp>)rV   rW   r   ru   r    rR     s    zUnplugger.configureN)r%   )
r   r   r3   __doc__r/   rU   r}   rE   rI   rR   r   r   r   r    r     s   
r   c                   @   s8   e Zd ZdZdZeedddZej	fddZ
dd	 Zd
S )KnownFailurePlugina1  Plugin that installs a KNOWNFAIL error class for the
    KnownFailureClass exception.  When KnownFailure is raised,
    the exception will be logged in the knownfail attribute of the
    result, 'K' or 'KNOWNFAIL' (verbose) will be output, and the
    exception will not be counted as an error or failure.TZ	KNOWNFAILF)labelZ	isfailurec                 C   s$   d}|j ddd||ddd d S )NZNOSE_WITHOUT_KNOWNFAILz--no-knownfail
store_truenoKnownFailFz3Disable special handling of KnownFailure exceptions)actiondestdefaulthelp)
add_optionget)r   rL   rM   Zenv_optr   r   r    rI   -  s
    zKnownFailurePlugin.optionsc                 C   s*   | j s
d S || _t|dd}|r&d| _d S )Nr   F)Zcan_configureconfr*   rU   )r   rI   r   disabler   r   r    rR   4  s    zKnownFailurePlugin.configureN)r   r   r3   r   rU   r   r	   Z	knownfailr^   r   rI   rR   r   r   r   r    r   "  s   r   c                   @   s   e Zd ZdZdd ZdS )FPUModeCheckPluginzx
    Plugin that checks the FPU mode before and after each test,
    raising failures if the test changed the mode.
    c                    s   ddl m   fdd}|S )Nr   )get_fpu_modec                    sZ     } |    }||krVztd||W n" tyT   | t  Y n0 d S )Nz6FPU mode changed from {0:#x} to {1:#x} during the test)rF   AssertionErrorformatZ
addFailuresysexc_info)resultZold_modeZnew_moder   rF   r   r    runH  s    
z/FPUModeCheckPlugin.prepareTestCase.<locals>.run)Znumpy.core._multiarray_testsr   )r   rF   r   r   r   r    prepareTestCaseE  s    z"FPUModeCheckPlugin.prepareTestCaseN)r   r   r3   r   r   r   r   r   r    r   ?  s   r   c                   @   s   e Zd Zdd ZdS )NumpyTestProgramc                 C   sh   | j du r(tjj| jj| jj| jd| _ | jj| j }|durF|| _ | j 	| j
| _| j | _| jS )a  Run Tests. Returns true on success, false on failure, and
        sets self.success to the same value.

        Because nose currently discards the test result object, but we need
        to return it to the user, override TestProgram.runTests to retain
        the result
        N)stream	verbosityrX   )Z
testRunnernosecoreZTextTestRunnerrX   r   r   rV   ZprepareTestRunnerr   rF   r   ZwasSuccessfulsuccess)r   Zplug_runnerr   r   r    runTests[  s    
zNumpyTestProgram.runTestsN)r   r   r3   r   r   r   r   r    r   Z  s   r   )&r^   r   r%   r   rb   r   Znose.pluginsr   ri   Znose.plugins.errorclassr   r   Znose.plugins.baser   Z	nose.utilr   Z
nosetesterr   utilsr	   r
   r&   r   r8   r4   rD   r?   Zget_printoptionsrt   ry   rH   r   r   ZKnownFailurer   r   ZTestProgramr   r   r   r   r    <module>   s*   	Ox