U C^ 9@s0ddlmZmZmZddlZddlZddlZddlZddlZddl Z ddl m Z ddl mZmZddlmZddlmZddlmZdd lmZmZGd d d ejZGd d d ejZGddde jZeZ Gddde j!Z"Gddde#Z$GdddeZ%e%Z&GdddeZ'Gddde j(j)Z*dS))divisionabsolute_importprint_functionN)doctests) ErrorClassErrorClassPlugin)Plugin)src)get_package_name)KnownFailureExceptionKnownFailureTestc@seZdZddZddZdS)NumpyDocTestFindercCs|dkr dSt|r"|j|jkSt|r8|j|jkSt|rN|j|jkSt|rh|j|j j jkSt |dk r|t |kSt |dr|j|jkSt |trdStddS)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__risclassismethod__self__ __class__ getmodulehasattr isinstanceproperty ValueError)selfmoduleobjectr"E/tmp/pip-install-6_kvzl1k/numpy/numpy/testing/_private/noseclasses.py _from_module s"          zNumpyDocTestFinder._from_modulec Cs@tj||||||||ddlm}m} m} m} m} | |r|j r|j D]F\} }d|| f}||sr| |rN| ||rN||||||||qN| |r<|j r<|j D]\} }t |trt|| }t |trt|| j}| |s | |s | |s t |tr| ||rd|| f} |||| ||||qdS)zm Find tests for the given object and any contained objects, and add them to `tests`. r) isroutinerismodulerrz%s.%sN)doctest DocTestFinder_findrr%rr&rrZ_recurseritemsr$r staticmethodgetattr classmethod__func__r)rtestsobjnamer Z source_linesglobsseenr%rr&rrZvalnamevalZvalname1r"r"r#r)<sD        zNumpyDocTestFinder._findN)rr __qualname__r$r)r"r"r"r#rsrc@seZdZddZdS)NumpyOutputCheckercCsztj||||}|svd|kr"dS|dd}|dd}dD]$}|d|d}|d|d}q>tj||||}|S)Nz#randomTz'>z'<)z'setUptearDownchecker)Z _result_varZ _nose_objr' DocTestCase__init__)rtestr>rCrDrEr0 result_varr"r"r#rGs zNumpyDocTestCase.__init__)rNNNNrB)rrr5rGr"r"r"r#rAs rAc@sjeZdZdZdZejejBZddgZ e Z e Z eZejfddZddZd d Zd d Zd dZddZdS) NumpyDoctestZ numpydoctestizgenerate_numpy_api.pyzsetup.pycCst|||d|_d|_dS)NT)roptionsZ doctest_testsdoctest_result_varrparserenvr"r"r#rKszNumpyDoctest.optionscCsBt|||||_t|_|jr>dd|jjD|j_dS)NcSsg|]}|jdkr|qS)r')r1.0pr"r"r# s z*NumpyDoctest.configure..) r configuretest_finder_classfinderr'Z DocTestParserrNenabledpluginsrrKconfigr"r"r#rTs   zNumpyDoctest.configurecCsXttj|j}tddtd|_d|krT|d}|d}t ||ji|g|j|<dS)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__rnpZscipy.N) r ospathdirnamefilenamer\numpyr2split __import__)rrHpkg_namerRp2r"r"r#set_test_contexts  zNumpyDoctest.set_test_contextccs||jstjd|dSz|j|}Wntk rDYdSX|sNdS|t |j }|D]>}|j spqd|j s|||_ | ||j||j||jdVqddS)NzDoctest doesn't want module %s)r>rErI)matchesrnpdlogdebugrVfindAttributeErrorsortr r]Zexamplesrdrjdoctest_case_classdoctest_optflagsout_check_classrL)rr r/Z module_filerHr"r"r#loadTestsFromModules,   z NumpyDoctest.loadTestsFromModulecCstjftdSN)reZset_printoptions print_staterr"r"r# afterContextszNumpyDoctest.afterContextcCs(tj|}||jkrdStj||S)NF)rarbbasenamedoctest_ignorerlDoctestwantFile)rfileZbnr"r"r#r}s  zNumpyDoctest.wantFileN)rrr5r1scorer'ZNORMALIZE_WHITESPACEELLIPSISrsr{rArrr6rtrrUraenvironrKrTrjruryr}r"r"r"r#rJs   *rJc@s6eZdZdZdZdZdZd ddZdd Zd d Z d S) Unpluggerzi Nose plugin to remove named plugin late in loading By default it removes the "doctest" plugin. Z unpluggerTir'cCs ||_dSrv) to_unplug)rrr"r"r#rGszUnplugger.__init__cCsdSrvr"rMr"r"r#rKszUnplugger.optionscsfdd|jjD|j_dS)Ncsg|]}|jjkr|qSr")r1rrPrxr"r#rS s z'Unplugger.configure..)rXrYr"rxr#rTszUnplugger.configureN)r') rrr5__doc__r1rWrrGrKrTr"r"r"r#rs rc@s8eZdZdZdZeedddZej fddZ dd Z d S) KnownFailurePlugina1Plugin 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 isfailurecCs$d}|jddd||ddddS)NZNOSE_WITHOUT_KNOWNFAILz--no-knownfail store_true noKnownFailFz3Disable special handling of KnownFailure exceptions)actiondestdefaulthelp) add_optionget)rrNrOZenv_optr"r"r#rK/s  zKnownFailurePlugin.optionscCs*|js dS||_t|dd}|r&d|_dS)NrF)Z can_configureconfr,rW)rrKrdisabler"r"r#rT6s  zKnownFailurePlugin.configureN) rrr5rrWrr Z knownfailrarrKrTr"r"r"r#r$src@seZdZdZddZdS)FPUModeCheckPluginzx Plugin that checks the FPU mode before and after each test, raising failures if the test changed the mode. csddlmfdd}|S)Nr) get_fpu_modecs\}|}||krXztd||Wn$tk rV|tYnXdS)Nz6FPU mode changed from {0:#x} to {1:#x} during the test)rHAssertionErrorformatZ addFailuresysexc_info)resultZold_modeZnew_moderrHr"r#runJs z/FPUModeCheckPlugin.prepareTestCase..run)Znumpy.core._multiarray_testsr)rrHrr"rr#prepareTestCaseGs  z"FPUModeCheckPlugin.prepareTestCaseN)rrr5rrr"r"r"r#rAsrc@seZdZddZdS)NumpyTestProgramcCsh|jdkr(tjj|jj|jj|jd|_|jj|j}|dk rF||_|j |j |_ |j |_ |j S)aRun 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 verbosityrZ)Z testRunnernosecoreZTextTestRunnerrZrrrXZprepareTestRunnerrrHrZ wasSuccessfulsuccess)rZ plug_runnerr"r"r#runTests]s   zNumpyTestProgram.runTestsN)rrr5rr"r"r"r#r\sr)+ __future__rrrrarr'rrerZ nose.pluginsrrlZnose.plugins.errorclassrrZnose.plugins.baserZ nose.utilr Z nosetesterr utilsr r r(rr:r6rFrAZget_printoptionsrwr|rJr!rrZ KnownFailurerrZ TestProgramrr"r"r"r#s,     O x