o 6a8@sddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z ddl m Z ddlmZddlmZddlmZmZGd d d ejZGd d d ejZGd ddejZeZGdddejZGdddZGddde Z e Z!Gddde Z"Gdddej#j$Z%dS)N)doctests) ErrorClassErrorClassPlugin)Plugin)src)get_package_name)KnownFailureExceptionKnownFailureTestc@seZdZddZddZdS)NumpyDocTestFindercCs|durdSt|r|j|juSt|r|j|jkSt|r'|j|jkSt|r4|j|j j jkSt |durB|t |uSt |drM|j|jkSt |trTdStd)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 isclassismethod__self__ __class__ getmodulehasattr isinstanceproperty ValueError)selfmoduleobjectrD/usr/lib/python3/dist-packages/numpy/testing/_private/noseclasses.py _from_modules"          zNumpyDocTestFinder._from_modulec CsBtj||||||||ddlm}m} m} m} m} | |rL|j rL|j D]$\} }|d| }||s:| |rK| ||rK||||||||q'| |r|j r|j D]F\} }t |trft|| }t |trqt|| j}| |s| |s| |st |tr| ||r|d| } |||| ||||qXdSdSdS)zm Find tests for the given object and any contained objects, and add them to `tests`. r) isroutinerismodulerr.N)doctest DocTestFinder_findr r"rr#rr_recurseritemsr!r staticmethodgetattr classmethod__func__r)rtestsobjnamer source_linesglobsseenr"rr#rrvalnamevalvalname1rrr r':sD      zNumpyDocTestFinder._findN)rr __qualname__r!r'rrrr r s r c@eZdZddZdS)NumpyOutputCheckercCsztj||||}|s;d|vrdS|dd}|dd}dD]}|d|d}|d|d}qtj||||}|S)Nz#randomTz'>z'<)z'ls    zNumpyOutputChecker.check_outputN)rr r7r>rrrr r9k r9c@seZdZ  dddZdS)NumpyDocTestCaserN_cCs(||_||_tjj||||||ddS)N)rBsetUptearDownchecker) _result_var _nose_objr% DocTestCase__init__)rtestrBrHrIrJr/ result_varrrr rNs  zNumpyDocTestCase.__init__)rNNNNrG)rr r7rNrrrr rFsrFc@sjeZdZdZdZejejBZddgZ e Z e Z eZejfddZddZd d Zd d Zd dZddZdS) NumpyDoctest numpydoctestizgenerate_numpy_api.pyzsetup.pycCst|||d|_d|_dS)NT)roptions doctest_testsdoctest_result_varrparserenvrrr rSs zNumpyDoctest.optionscCsFt|||||_t|_|jr!dd|jjD|j_dSdS)NcSsg|] }|jdkr|qSr%)r0.0prrr s z*NumpyDoctest.configure..) r configuretest_finder_classfinderr% DocTestParserrWenabledpluginsrrSconfigrrr r^s   zNumpyDoctest.configurecCs\ttj|j}tddtd|_d|vr,|d}|d}t ||ji|g|j|<dSdS)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__rnpscipyr$N) rospathdirnamefilenamergnumpyr2split __import__)rrOpkg_namer\p2rrr set_test_contexts  zNumpyDoctest.set_test_contextccs||jstjd|dSz|j|}Wn ty"YdSw|s'dS|t |j }|D]}|j s8q2|j s>||_ | ||j||j||jdVq2dS)NzDoctest doesn't want module %s)rBrJrP)matchesrnpdlogdebugr`findAttributeErrorsortrrhexamplesrorudoctest_case_classdoctest_optflagsout_check_classrU)rrr. module_filerOrrr loadTestsFromModules2     z NumpyDoctest.loadTestsFromModulecCstjditdS)Nr)rpset_printoptions print_staterrrr afterContextszNumpyDoctest.afterContextcCs(tj|}||jvr dStj||S)NF)rlrmbasenamedoctest_ignorerwDoctestwantFile)rfilebnrrr rs  zNumpyDoctest.wantFileN)rr r7r0scorer%NORMALIZE_WHITESPACEELLIPSISrrrFr~r9rr r_rlenvironrSr^rurrrrrrr rQs    * rQc@s6eZdZdZdZdZdZd ddZdd Zd d Z d S) Unpluggerzi Nose plugin to remove named plugin late in loading By default it removes the "doctest" plugin. unpluggerTir%cCs ||_dSN) to_unplug)rrrrr rNs zUnplugger.__init__cCsdSrrrVrrr rSszUnplugger.optionscsfdd|jjD|j_dS)Ncsg|] }|jjkr|qSr)r0rrZrrr r]s z'Unplugger.configure..)rcrdrrr r^szUnplugger.configureNrY) rr r7__doc__r0rbrrNrSr^rrrr r s  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.T KNOWNFAILF)label isfailurecCs$d}|jddd||ddddS)NNOSE_WITHOUT_KNOWNFAILz--no-knownfail store_true noKnownFailFz3Disable special handling of KnownFailure exceptions)actiondestdefaulthelp) add_optionget)rrWrXenv_optrrr rS-s   zKnownFailurePlugin.optionscCs.|jsdS||_t|dd}|rd|_dSdS)NrF) can_configureconfr+rb)rrSrdisablerrr r^4s  zKnownFailurePlugin.configureN) rr r7rrbrr knownfailrlrrSr^rrrr r"s rc@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_modecsX}|}||kr*ztd||ty)|tYdSwdS)Nz6FPU mode changed from {0:#x} to {1:#x} during the test)rOAssertionErrorformat addFailuresysexc_info)resultold_modenew_moderrOrr runHs  z/FPUModeCheckPlugin.prepareTestCase..run)numpy.core._multiarray_testsr)rrOrrrr prepareTestCaseEs  z"FPUModeCheckPlugin.prepareTestCaseN)rr r7rrrrrr r?s rc@r8)NumpyTestProgramcCsh|jdurtjj|jj|jj|jd|_|jj|j}|dur#||_|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 verbosityre) testRunnernosecoreTextTestRunnerrerrrcprepareTestRunnerrrOr wasSuccessfulsuccess)r plug_runnerrrr runTests[s   zNumpyTestProgram.runTestsN)rr r7rrrrr rZrEr)&rlrr%r rpr nose.pluginsrrwnose.plugins.errorclassrrnose.plugins.baser nose.utilr nosetesterrutilsr r r&r r=r9rMrFget_printoptionsrrrQrr KnownFailurerr TestProgramrrrrr s,     O x