σ
£αSc           @` s   d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l m	 Z	 d d l
 m Z d   Z d   Z d d  Z d	 e f d
     YZ d S(   se   
Nose test running.

This module implements ``test()`` and ``bench()`` functions for NumPy modules.

i    (   t   divisiont   absolute_importt   print_functionN(   t
   basestring(   t   ModuleDeprecationWarningc         C` sΈ   |  } g  } xQ d |  k s( d |  k r` t  j j |   \ }  } | d k rP Pn  | j |  q W| s~ d | k rw d Sd Sn  | j   | d j d  r« | j d  n  d j |  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-packagest   scipyt   numpyi    s   .eggt   .(   s   site-packagess   dist-packages(   t   ost   patht   splitt   appendt   reverset   endswitht   popt   join(   t   filepatht   fullpatht   pkg_namet   p2(    (    sR   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/testing/nosetester.pyt   get_package_name   s    
c          C` sq   t  }  d } y d d l } Wn t k
 r5 t }  n X| j | k  rN t }  n  |  sm d | } t |   n  | S(   s#    Import nose only when needed.
    i    i
   NsW   Need nose >= %d.%d.%d for tests - see http://somethingaboutorange.com/mrl/projects/nose(   i    i
   i    (   t   Truet   noset   ImportErrort   Falset   __versioninfo__(   t	   fine_noset   minimum_nose_versionR   t   msg(    (    sR   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/testing/nosetester.pyt   import_nose8   s    
	c         C` se   |  d  k rH t j d  } | j j d d   }  |  d  k rH t  qH n  t   j d d |  g  d  S(   Ni   t   __file__t   argvt    (   t   Nonet   syst	   _getframet   f_localst   gett   AssertionErrorR   t   run(   t   file_to_runt   f(    (    sR   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/testing/nosetester.pyt   run_module_suiteN   s    t
   NoseTesterc           B` s   e  Z d  Z d d d d d g Z d d d  Z d   Z d	   Z d
   Z d d d e	 e	 d  Z
 d d d e	 e	 d d  Z d d d d  Z 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, optional
        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.
    raise_warnings : str or sequence of warnings, optional
        This specifies which warnings to configure as 'raise' instead
        of 'warn' during the test execution.  Valid strings are:

          - "develop" : equals ``(DeprecationWarning, RuntimeWarning)``
          - "release" : equals ``()``, don't raise on any warnings.

        See Notes for more details.

    Notes
    -----
    The default for `raise_warnings` is
    ``(DeprecationWarning, RuntimeWarning)`` for the master branch of NumPy,
    and ``()`` for maintenance branches and released versions.  The purpose
    of this switching behavior is to catch as many warnings as possible
    during development, but not give problems for packaging of released
    versions.

    t   f2py_extt   f2py_f90_extt   gen_extt	   pyrex_extt   swig_extt   releasec         C` sϊ   d  } | d  k ru t j d  } | j j d d   } | d  k rK t  n  t j j |  } | j j d d   } nK t	 | t
 t   r΄ t j j | j  } t | d d   } n t |  } | |  _ | d  k rδ t |  } n  | |  _ | |  _ d  S(   Ni   R   t   __name__(   R!   R"   R#   R$   R%   R&   R   R	   t   dirnamet
   isinstancet   typeR   t   getattrt   strt   package_pathR   t   package_namet   raise_warnings(   t   selft   packageR:   R9   R)   R8   (    (    sR   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/testing/nosetester.pyt   __init__   s"    			c         C` s€   t  |  j d g } | rj | d k rj t | t  sB t d   n  | d k rW d } n  | d | g 7} n  | d t |  g 7} | d g 7} | r  | | 7} n  | S(	   s   Generate argv for nosetest command

        Parameters
        ----------
        label : {'fast', 'full', '', attribute identifier}, optional
            see ``test`` docstring
        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
        -------
        argv : list
            command line arguments that will be passed to nose
        s   -st   fulls"   Selection label should be a stringt   fasts   not slows   -As   --verbositys   --exe(   R   R8   R4   R   t	   TypeErrorR7   (   R;   t   labelt   verboset
   extra_argvR   (    (    sR   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/testing/nosetester.pyt
   _test_argv¦   s    	c         C` sΣ   t    } d d  l } t d | j  t j j | j  } t d |  d |  j k r d d  l	 } t d | j  t j j | j  } t d |  n  t
 j j d d  } t d	 |  t d
 | j  d  S(   Ni    s   NumPy version %ss   NumPy is installed in %sR   s   SciPy version %ss   SciPy is installed in %ss   
R    s   Python version %ss   nose version %d.%d.%d(   R   R   t   printt   __version__R   R	   R3   R   R9   R   R"   t   versiont   replaceR   (   R;   R   R   t   npdirR   t   spdirt	   pyversion(    (    sR   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/testing/nosetester.pyt   _show_system_infoΛ   s    	c         C` s   d d l  m } |   S(   s»    Return instantiated plugin for doctests

        Allows subclassing of this class to override doctester

        A return value of None means use the nose builtin doctest plugin
        i   (   t   NumpyDoctest(   t   noseclassesRM   (   R;   RM   (    (    sR   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/testing/nosetester.pyt   _get_custom_doctesterέ   s    R?   i   c         C` so  t    |  j | | |  } x! |  j D] } | d | g 7} q& W| rf | d |  j d d d g 7} n  d d l } d d	 l m }	 m }
 |	   g } | g  | j j	 j D] } |   ^ q§ 7} d
 | k } | t
 k rδ | rδ t } n  |  j   } | d k r| re| re| d
 g 7} qenI | r2| j d
  n  | |
 d  | g 7} | re| d | j g 7} n  | | f S(   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	   --excludes   --cover-package=%ss   --with-coverages   --cover-testss   --cover-erasei    Ni   (   t   KnownFailuret	   Unpluggers   --with-doctestt   doctests   --with-(   R   RD   t   excludesR9   t   nose.plugins.builtinRN   RP   RQ   t   pluginst   builtinR   R   RO   R!   t   removet   name(   R;   RA   RB   RC   t   doctestst   coverageR   t   enameR   RP   RQ   RU   t   pt   doctest_argvt   plug(    (    sR   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/testing/nosetester.pyt   prepare_test_argsη   s0    )	c         C` sΚ  t  | d  } d d l m } | | _ | rB t d |  j  n t d |  j  |  j   d d l } d | _	 | d k r |  j
 } n  t d t t f d	 d  }	 | |	 j   k rΔ |	 | } n  t j   ρ t j   t j d
 d t x! | D] }
 t j d d |
 qυ Wt j d d d t j d d d t j d d d t j d d t t j d d t d d l m } |  j | | | | |  \ } } | d | d t d |  } Wd QX| j S(   sη  
        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:
             <http://nedbatchelder.com/code/modules/coverage.html>`_).
        raise_warnings : str or sequence of warnings, optional
            This specifies which warnings to configure as 'raise' instead
            of 'warn' during the test execution.  Valid strings are:

              - "develop" : equals ``(DeprecationWarning, RuntimeWarning)``
              - "release" : equals ``()``, don't raise on any warnings.

        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() #doctest: +SKIP

        Examples
        --------
        >>> result = np.lib.test() #doctest: +SKIP
        Running unit tests for numpy.lib
        ...
        Ran 976 tests in 3.933s

        OK

        >>> result.errors #doctest: +SKIP
        []
        >>> result.knownfail #doctest: +SKIP
        []
        i   i   (   t   utilss&   Running unit tests and doctests for %ss   Running unit tests for %si    Nt   developR1   t   alwayst   categoryt   errort   ignoret   messages   Not importing directorys   numpy.dtype size changeds   numpy.ufunc size changed(   t   NumpyTestProgramR   t   exitRU   (    (   t   minR    R`   RB   RE   R9   RL   RR   R!   t   masterR:   t   dictt   DeprecationWarningt   RuntimeWarningt   keyst   warningst   catch_warningst   resetwarningst   filterwarningsR   t   FutureWarningRN   Rg   R_   R   t   result(   R;   RA   RB   RC   RY   RZ   R:   R`   RR   t
   _warn_optst   warningtypeRg   R   RU   t   t(    (    sR   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/testing/nosetester.pyt   test  s<    @	
		
!c         C` s   t  d |  j  |  j   |  j | | |  } | d d t j g 7} t   } d d l m } | d  g } | j	 d | d |  S(	   sθ  
        Run benchmarks for module using nose.

        Parameters
        ----------
        label : {'fast', 'full', '', attribute identifier}, optional
            Identifies the benchmarks 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 benchmarks 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 benchmark 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() #doctest: +SKIP
        Running benchmarks for numpy.lib
        ...
        using 562341 items:
        unique:
        0.11
        unique1d:
        0.11
        ratio: 1.0
        nUnique: 56230 == 56230
        ...
        OK

        >>> success #doctest: +SKIP
        True

        s   Running benchmarks for %ss   --matchs   (?:^|[\\b_\\.%s-])[Bb]enchi   (   RQ   RR   R   t
   addplugins(
   RE   R9   RL   RD   R   t   sepR   RN   RQ   R'   (   R;   RA   RB   RC   R   R   RQ   t   add_plugins(    (    sR   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/testing/nosetester.pyt   bench  s    8
	N(   R2   t
   __module__t   __doc__RS   R!   R=   RD   RL   RO   R   R_   Rx   R|   (    (    (    sR   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/testing/nosetester.pyR+   X   s    ,		%		
	-	o(   R~   t
   __future__R    R   R   R   R"   Ro   t   numpy.compatR   R   R   R   R   R!   R*   t   objectR+   (    (    (    sR   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/testing/nosetester.pyt   <module>   s   	(	
