ó ]ÐKc@szdZddlZddlZd„Zd„Zed„Zd„Zdefd„ƒYZ d „Z d „Z d „Z dS( se Nose test running. This module implements ``test()`` and ``bench()`` functions for NumPy modules. iÿÿÿÿNcCs¸|}g}xQd|ks(d|kr`tjj|ƒ\}}|dkrPPn|j|ƒqW|s~d|krwdSdSn|jƒ|djdƒr«|jdƒndj|ƒS( s& Given a path where a package is installed, determine its name. Parameters ---------- filepath : str Path to a file. If the determination fails, "numpy" is returned. Examples -------- >>> np.testing.nosetester.get_package_name('nonsense') 'numpy' s site-packagess dist-packagestscipytnumpyis.eggt.(s site-packagess dist-packages(tostpathtsplittappendtreversetendswithtpoptjoin(tfilepathtfullpathtpkg_nametp2((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pytget_package_name s   cCst}d}y ddl}ddlm}Wntk rEt}nX|j|kr^t}n|s}d|}t|ƒ‚n|S(s# Import nose only when needed. ii iÿÿÿÿN(traisessWNeed nose >= %d.%d.%d for tests - see http://somethingaboutorange.com/mrl/projects/nose(ii i(tTruetnoset nose.toolsRt ImportErrortFalset__versioninfo__(t fine_nosetminimum_nose_versionRRtmsg((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pyt import_nose2s    cCsb|dkrEtjdƒ}|jjddƒ}|dk sEt‚ntƒjdd|gƒdS(Nit__file__targvt(tNonetsyst _getframetf_localstgettAssertionErrorRtrun(t file_to_runtf((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pytrun_module_suiteIs  cCs9|js dSdi|d6}|ji|d6|_dS(NsSParameters ---------- label : {'fast', 'full', '', attribute identifer} Identifies the %(testtype)ss to run. This can be a string to pass to the nosetests executable with the '-A' option, or one of several special values. Special values are: 'fast' - the default - which corresponds to nosetests -A option of 'not slow'. 'full' - fast (as above) and slow %(testtype)ss as in the no -A option to nosetests - same as '' None or '' - run all %(testtype)ss attribute_identifier - string passed directly to nosetests as '-A' verbose : integer verbosity value for test outputs, 1-10 extra_argv : list List with any extra args to pass to noseteststtesttypet test_header(t__doc__(tmethR(R)((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pyt _docmethodRs  t NoseTestercBs•eZdZd d„Zd„Zd„Zddd eed„Zddd eed„Z ddd d„Z e ed ƒe e d ƒe e d ƒRS( sû Nose test runner. This class is made available as numpy.testing.Tester, and a test function is typically added to a package's __init__.py like so:: from numpy.testing import Tester test = Tester().test Calling this test function finds and runs all tests associated with the package and all its sub-packages. Attributes ---------- package_path : str Full path to the package to test. package_name : str Name of the package to test. Parameters ---------- package : module, str or None The package to test. If a string, this should be the full path to the package. If None (default), `package` is set to the module from which `NoseTester` is initialized. cCsîd}|dkrrtjdƒ}|jjddƒ}|dk sHt‚tjj|ƒ}|jjddƒ}nKt |t tƒƒr±tjj|j ƒ}t |ddƒ}n t |ƒ}||_|dkrát|ƒ}n||_dS(sâ Test class init Parameters ---------- package : string or module If string, gives full path to package If None, extract calling module path Default is None iRt__name__N(RRR R!R"R#RRtdirnamet isinstancettypeRtgetattrtstrt package_pathRt package_name(tselftpackageR5R&R4((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pyt__init__Šs     cCs”t|jdg}|rg|dkrgt|tƒs?td‚n|dkrTd}n|d|g7}n|dt|ƒg7}|r||7}n|S(sE Generate argv for nosetest command %(test_header)s s-stfulls"Selection label should be a stringtfastsnot slows-As --verbosity(RR4R0t basestringt TypeErrorR3(R6tlabeltverboset extra_argvR((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pyt _test_argv©s    cCsµtƒ}ddl}d|jGHtjj|jƒ}d|GHd|jkr‡ddl}d|jGHtjj|jƒ}d|GHnt j j ddƒ}d |GHd |j GHdS( NiÿÿÿÿsNumPy version %ssNumPy is installed in %sRsSciPy version %ssSciPy is installed in %ss RsPython version %ssnose version %d.%d.%d( RRt __version__RRR/RR5RRtversiontreplaceR(R6RRtnpdirRtspdirt pyversion((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pyt_show_system_infoºs        R:ic Csh|r(d|kr(|jdƒt}n|j|||ƒ}|rS|dg7}n|r||d|jddddg7}n|dd g7}|dd g7}|dd g7}|dd g7}|dd g7}|ddg7}tƒ}ddl}ddlm}m} |ƒ| ƒg} xB|j j j D]1} | ƒ} | j dkrMq)n| j | ƒq)W|| fS(sç Run tests for module using nose. This method does the heavy lifting for the `test` method. It takes all the same arguments, for details see `test`. See Also -------- test s--with-doctests--with-numpydoctests--cover-package=%ss--with-coverages --cover-testss--cover-inclusives --cover-erases --excludetf2py_extt f2py_f90_exttgen_extt pyrex_exttswig_exttarray_from_pyobjiÿÿÿÿN(t NumpyDoctestt KnownFailuretdoctest( tremoveRR@R5Rtnose.plugins.builtint noseclassesRNROtpluginstbuiltintnameR( R6R=R>R?tdocteststcoverageRRRNRORTtptplug((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pytprepare_test_argsÍs2     c Cs·t|dƒ}ddl}||_|r9d|jGHn d|jGH|jƒddl}d|_|j|||||ƒ\}} ddl m } | d|dt d | ƒ} | j S( sk Run tests for module using nose. Parameters ---------- label : {'fast', 'full', '', attribute identifier}, optional Identifies the tests to run. This can be a string to pass to the nosetests executable with the '-A' option, or one of several special values. Special values are: 'fast' - the default - which corresponds to the ``nosetests -A`` option of 'not slow'. 'full' - fast (as above) and slow tests as in the 'no -A' option to nosetests - this is the same as ''. None or '' - run all tests. attribute_identifier - string passed directly to nosetests as '-A'. verbose : int, optional Verbosity value for test outputs, in the range 1-10. Default is 1. extra_argv : list, optional List with any extra arguments to pass to nosetests. doctests : bool, optional If True, run doctests in module. Default is False. coverage : bool, optional If True, report coverage of NumPy code. Default is False. (This requires the `coverage module: `_). Returns ------- result : object Returns the result of running the tests as a ``nose.result.TextTestResult`` object. Notes ----- Each NumPy module exposes `test` in its namespace to run all tests for it. For example, to run all tests for numpy.lib:: >>> np.lib.test() Examples -------- >>> result = np.lib.test() Running unit tests for numpy.lib ... Ran 976 tests in 3.933s OK >>> result.errors [] >>> result.knownfail [] iiÿÿÿÿNs&Running unit tests and doctests for %ssRunning unit tests for %s(tNumpyTestProgramRtexitRT( tmintutilsR>R5RGRPRtmasterR[RSR\Rtresult( R6R=R>R?RWRXR_RPRRTR\tt((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pyttests;      cCs[d|jGH|jƒ|j|||ƒ}|ddtjg7}tƒ}|jd|ƒS(sÜ Run benchmarks for module using nose. Parameters ---------- label : {'fast', 'full', '', attribute identifier}, optional Identifies the tests to run. This can be a string to pass to the nosetests executable with the '-A' option, or one of several special values. Special values are: 'fast' - the default - which corresponds to the ``nosetests -A`` option of 'not slow'. 'full' - fast (as above) and slow tests as in the 'no -A' option to nosetests - this is the same as ''. None or '' - run all tests. attribute_identifier - string passed directly to nosetests as '-A'. verbose : int, optional Verbosity value for test outputs, in the range 1-10. Default is 1. extra_argv : list, optional List with any extra arguments to pass to nosetests. Returns ------- success : bool Returns True if running the benchmarks works, False if an error occurred. Notes ----- Benchmarks are like tests, but have names starting with "bench" instead of "test", and can be found under the "benchmarks" sub-directory of the module. Each NumPy module exposes `bench` in its namespace to run all benchmarks for it. Examples -------- >>> success = np.lib.bench() Running benchmarks for numpy.lib ... using 562341 items: unique: 0.11 unique1d: 0.11 ratio: 1.0 nUnique: 56230 == 56230 ... OK >>> success True sRunning benchmarks for %ss--matchs(?:^|[\\b_\\.%s-])[Bb]enchR(R5RGR@RtsepRR$(R6R=R>R?RR((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pytbenchRs 9   s (testtype)Rct benchmarkN( R.t __module__R*RR8R@RGRR[RcReR,(((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pyR-ms    3  PC  cCsdS(sY >>> 2+2 #random: may vary on your system N((((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pytcheck_random_directivežscCsdS(s4 >>> np.array([1,2,3]) array([1, 2, 3]) N((((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pytcheck_implicit_np¥scCsdS(sf # whitespace after the 3 >>> 1+2 3 # whitespace before the 7 >>> 3+4 7 N((((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pytcheck_whitespace_enabled¬s( R*RRRRRR'R,tobjectR-RhRiRj(((s</usr/lib/python2.7/site-packages/numpy/testing/nosetester.pyts   (  ÿ2