ó
šßÈ[c           @` s¢  d  Z  d d l m Z m Z m Z m Z 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 y d d l Z Wn e k
 r³ n Xd d l m Z m Z d d	 l m Z d
 d d d d d d d d d d g Z e j j Z d „  Z d „  Z d e f d „  ƒ  YZ e a  e! a" e# d d d d d d g ƒ a$ e# g  ƒ a% i e# d g ƒ d= 6e# d! d" d# d g ƒ d> 6e# d! d& d' d g ƒ d? 6e# d! d) d' d g ƒ d@ 6e# d! d) d' d d+ g ƒ dA 6a& e! g  g  i  d, „ Z' d- „  Z( d. e
 j) f d/ „  ƒ  YZ) d0 e) f d1 „  ƒ  YZ* d d2 „ Z, e j- d3 d d d4 g ƒ d5 „  ƒ Z. d6 „  Z/ d7 „  Z0 d8 d d9 „ Z1 d: d d; „ Z2 d< „  Z3 d S(B   u›   
This module provides the tools used to internally run the astropy test suite
from the installed astropy.  It makes use of the `pytest` testing framework.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   six(   t   cPickle(   t   AstropyDeprecationWarningt    AstropyPendingDeprecationWarningi   (   t
   TestRunneru   raisesu!   enable_deprecations_as_exceptionsu   remote_datau    treat_deprecations_as_exceptionsu   catch_warningsu!   assert_follows_unicode_guidelinesu   quantity_allcloseu   assert_quantity_allcloseu   check_pickling_recoveryu   pickle_protocolu   generic_recursive_equality_testc         ` s6   d „  ‰  g  |  D]" } t  ‡  f d †  | Dƒ ƒ ^ q S(   Nc         S` s   |  d  k r d  St |  ƒ S(   N(   t   Nonet   str(   t   x(    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyt   to_str_or_none1   s    c         3` s   |  ] } ˆ  | ƒ Vq d  S(   N(    (   t   .0R   (   R   (    s3   lib/python2.7/site-packages/astropy/tests/helper.pys	   <genexpr>6   s    (   t   tuple(   t   optionst   y(    (   R   s3   lib/python2.7/site-packages/astropy/tests/helper.pyt   _fix_user_options0   s    	c         C` s)  d d l  m } | d k r  d Sy |  j ƒ  Wn' t k
 rW |  j ƒ  |  j j } n X|  j j } x{ t | j	 ƒ  ƒ D]g } t
 j j t
 j j | ƒ t
 j j | ƒ ƒ } t
 j j t
 j j | | ƒ ƒ } | j | ƒ | | <qw W| d d ƒ |  j ƒ  | d d ƒ |  j d t
 j j | d	 ƒ ƒ d S(
   u‰   
    This method is called after the tests have been run in coverage mode
    to cleanup and then save the coverage data and report.
    i   (   t   color_printi    Nu$   Saving coverage data in .coverage...u   greenu)   Saving HTML coverage report in htmlcov...t	   directoryu   htmlcov(   t   utils.consoleR   t   get_datat   AttributeErrort   _harvest_datat   datat   linest   _linest   listt   keyst   ost   patht   relpatht   realpatht   abspatht   joint   popt   savet   html_report(   t   covt   resultt   rootdirt   testing_pathR   R   t   keyt   new_path(    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyt   _save_coverage9   s(    
		
t   raisesc           B` s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   u†  
    A decorator to mark that a test should raise a given exception.
    Use as follows::

        @raises(ZeroDivisionError)
        def test_foo():
            x = 1/0

    This can also be used a context manager, in which case it is just
    an alias for the ``pytest.raises`` context manager (because the
    two have the same name this help avoid confusion by being
    flexible).
    c         C` s   | |  _  d  |  _ d  S(   N(   t   _excR	   t   _ctx(   t   selft   exc(    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyt   __init__q   s    	c         ` s%   t  j ˆ  ƒ ‡  ‡ f d †  ƒ } | S(   Nc          ` s   t  j ˆ j ˆ  |  | Ž d  S(   N(   t   pytestR-   R.   (   t   argst   kwargs(   t   funcR0   (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyt   run_raises_testv   s    (   t	   functoolst   wraps(   R0   R6   R7   (    (   R6   R0   s3   lib/python2.7/site-packages/astropy/tests/helper.pyt   __call__u   s    !c         C` s"   t  j |  j ƒ |  _ |  j j ƒ  S(   N(   R3   R-   R.   R/   t	   __enter__(   R0   (    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyR;   {   s    c         G` s   |  j  j | Œ  S(   N(   R/   t   __exit__(   R0   t   exc_info(    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyR<      s    (   t   __name__t
   __module__t   __doc__R2   R:   R;   R<   (    (    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyR-   a   s
   			u   compileru   scipyu   pygmentsu	   ipykernelu   IPythonu
   setuptoolsu   MarkInfo objects are deprecatedi   u   'U' mode is deprecatedu-   The strict argument and mode are deprecated\.ui   The value of convert_charrefs will become True in 3\.5\. You are encouraged to set the value explicitly\.i   i   uI   inspect\.getargspec\(\) is deprecated, use inspect\.signature\(\) insteadu]   Importing from numpy\.testing\.decorators is deprecated, import from numpy\.testing instead\.i   u`   inspect\.getargspec\(\) is deprecated, use inspect\.signature\(\) or inspect\.getfullargspec\(\)i   u.   Using or importing the ABCs from 'collections'c         C` sz   t  a |  a t j | ƒ t j | ƒ xM t j | ƒ D]< \ } } | t k rb t | j | ƒ q6 t	 | ƒ t | <q6 Wd S(   u¥  
    Turn on the feature that turns deprecations into exceptions.

    Parameters
    ----------
    include_astropy_deprecations : bool
        If set to `True`, ``AstropyDeprecationWarning`` and
        ``AstropyPendingDeprecationWarning`` are also turned into exceptions.

    modules_to_ignore_on_import : list of str
        List of additional modules that generate deprecation warnings
        on import, which are to be ignored. By default, these are already
        included: ``compiler``, ``scipy``, ``pygments``, ``ipykernel``, and
        ``setuptools``.

    warnings_to_ignore_entire_module : list of str
        List of modules with deprecation warnings to ignore completely,
        not just during import. If ``include_astropy_deprecations=True``
        is given, ``AstropyDeprecationWarning`` and
        ``AstropyPendingDeprecationWarning`` are also ignored for the modules.

    warnings_to_ignore_by_pyver : dict
        Dictionary mapping tuple of ``(major, minor)`` Python version to
        a list of deprecation warning messages to ignore. This is in
        addition of those already ignored by default
        (see ``_warnings_to_ignore_by_pyver`` values).

    N(
   t   Truet   _deprecations_as_exceptionst   _include_astropy_deprecationst   _modules_to_ignore_on_importt   updatet!   _warnings_to_ignore_entire_moduleR   t	   iteritemst   _warnings_to_ignore_by_pyvert   set(   t   include_astropy_deprecationst   modules_to_ignore_on_importt    warnings_to_ignore_entire_modulet   warnings_to_ignore_by_pyverR*   t   val(    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyt!   enable_deprecations_as_exceptionsÇ   s    !c          C` s‚  xJ t  t j t j ƒ ƒ D]0 }  t |  t j ƒ r t |  d ƒ r |  `	 q q Wt
 sW d St j ƒ  t j d t ƒ x0 t D]( } y t | ƒ Wqx t k
 rŸ qx Xqx Wt j ƒ  t g } t rÐ | t t g 7} n  x! | D] } t j d d | ƒ q× Wx8 t D]0 } x' | D] } t j d d | d | ƒqWqû WxL t D]D } t j d  | k r6x( t | D] } t j d | t ƒ qZWq6q6Wd S(	   uE  
    Turn all DeprecationWarnings (which indicate deprecated uses of
    Python itself or Numpy, but not within Astropy, where we use our
    own deprecation warning class) into exceptions so that we find
    out about them early.

    This completely resets the warning filters and any "already seen"
    warning state.
    u   __warningregistry__Nu   ignoreu   erroru   .*t   categoryt   modulei   (   R   R   t
   itervaluest   syst   modulest
   isinstancet   typest
   ModuleTypet   hasattrt   __warningregistry__RB   t   warningst   resetwarningst   simplefiltert   DeprecationWarningRD   t
   __import__t   ImportErrorRC   R   R   t   filterwarningsRF   RH   t   version_info(   RQ   t   mt
   _all_warnst   wt   vt   s(    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyt    treat_deprecations_as_exceptionsû   s6    

	!t   catch_warningsc           B` s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   u.  
    A high-powered version of warnings.catch_warnings to use for testing
    and to make sure that there is no dependence on the order in which
    the tests are run.

    This completely blitzes any memory of any warnings that have
    appeared before so that all warnings will be caught and displayed.

    ``*args`` is a set of warning classes to collect.  If no arguments are
    provided, all warnings are collected.

    Use as follows::

        with catch_warnings(MyCustomWarning) as w:
            do.something.bad()
        assert len(w) > 0
    c         G` s&   t  t |  ƒ j d t ƒ | |  _ d  S(   Nt   record(   t   superRh   R2   RA   t   classes(   R0   Rk   (    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyR2   M  s    c         C` sv   t  t |  ƒ j ƒ  } t ƒ  t |  j ƒ d k rA t j d ƒ n1 t j d ƒ x! |  j D] } t j d | ƒ qX W| S(   Ni    u   alwaysu   ignore(   Rj   Rh   R;   Rg   t   lenRk   RZ   R\   (   R0   t   warning_listt   cls(    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyR;   Q  s    c         C` s   t  ƒ  d  S(   N(   Rg   (   R0   t   typet   valuet	   traceback(    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyR<   \  s    (   R>   R?   R@   R2   R;   R<   (    (    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyRh   :  s   		t   ignore_warningsc           B` s,   e  Z d  Z d d „ Z d „  Z d „  Z RS(   u   
    This can be used either as a context manager or function decorator to
    ignore all warnings that occur within a function or block of code.

    An optional category option can be supplied to only ignore warnings of a
    certain category or categories (if a list is provided).
    c         C` sM   t  t |  ƒ j ƒ  t | t ƒ r@ t | t ƒ r@ | g |  _ n	 | |  _ d  S(   N(   Rj   Rr   R2   RU   Ro   t
   issubclasst   WarningRP   (   R0   RP   (    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyR2   i  s    c         ` s%   t  j ˆ  ƒ ‡  ‡ f d †  ƒ } | S(   Nc          ` s-   ˆ j  d ˆ j ƒ  ˆ  |  | Ž  SWd  QXd  S(   NRP   (   t	   __class__RP   (   R4   R5   (   R6   R0   (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyt   wrapperr  s    (   R8   R9   (   R0   R6   Rv   (    (   R6   R0   s3   lib/python2.7/site-packages/astropy/tests/helper.pyR:   q  s    !c         C` s\   t  t |  ƒ j ƒ  } |  j d  k	 rK x1 |  j D] } t j d | ƒ q. Wn t j d ƒ | S(   Nu   ignore(   Rj   Rr   R;   RP   R	   RZ   R\   (   R0   t   retvalRP   (    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyR;   |  s    N(   R>   R?   R@   R	   R2   R:   R;   (    (    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyRr   `  s   	c         C` sm  d d l  m } d d l m } | j d t ƒ t |  ƒ } | j |  ƒ } t |  ƒ } t	 | t ƒ so t
 ‚ | j d ƒ t	 | | j ƒ s” t
 ‚ | j d ƒ t	 | | j ƒ s¹ t
 ‚ t	 | t ƒ rØ | j d ƒ n | j d ƒ | d k	 rE|  j | ƒ |  k st
 ‚ |  j | ƒ |  k s't
 ‚ t | | ƒ |  k sEt
 ‚ n  Wd QX| j d t ƒ 
t |  ƒ } | j |  ƒ } t |  ƒ } t	 | t ƒ sšt
 ‚ | j d ƒ t	 | | j ƒ s¿t
 ‚ t	 | | j ƒ s×t
 ‚ t	 | t ƒ rö| j d ƒ n | j d ƒ | d k	 rc|  j | ƒ |  k s*t
 ‚ |  j | ƒ |  k sEt
 ‚ t | | ƒ |  k sct
 ‚ n  Wd QXd S(   uæ  
    Test that an object follows our Unicode policy.  See
    "Unicode guidelines" in the coding guidelines.

    Parameters
    ----------
    x : object
        The instance to test

    roundtrip : module, optional
        When provided, this namespace will be used to evaluate
        ``repr(x)`` and ensure that it roundtrips.  It will also
        ensure that ``__bytes__(x)`` and ``__unicode__(x)`` roundtrip.
        If not provided, no roundtrip testing will be performed.
    i   (   t   conf(   R   u   unicode_outputu   asciiN(   t    Rx   t   externR   t   set_tempt   Falset   bytest	   text_typet   reprRU   t   AssertionErrort   decodet   encodet   string_typesR	   Ru   t   evalRA   (   R   t	   roundtripRx   R   t   bytes_xt	   unicode_xt   repr_x(    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyt!   assert_follows_unicode_guidelines†  sB    $t   paramsiÿÿÿÿc         C` s   |  j  S(   u‹   
    Fixture to run all the tests for protocols 0 and 1, and -1 (most advanced).
    (Originally from astropy.table.tests.test_pickle)
    (   t   param(   t   request(    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyt   pickle_protocolÂ  s    c         C` s  |  j  } | j  } xö | D]î } | | k s@ t d j | ƒ ƒ ‚ t | | d ƒ r¦ | | | | k } d t | ƒ k rˆ t | k } n  | s¦ t d j | ƒ ƒ ‚ n  t | | d ƒ r | | j | k rÏ q| | j g } | j | ƒ t | | | | | ƒ q q Wd S(   uv   
    Check if the attributes of a and b are equal. Then,
    check if the attributes of the attributes are equal.
    u   Did not pickle {0}u   __eq__u   __iter__u    Value of {0} changed by picklingu   __dict__N(	   t   __dict__R€   t   formatRX   t   dirR|   Ru   t   extendt   generic_recursive_equality_test(   t   at   bt   class_historyt   dict_at   dict_bR*   t   eqt   new_class_history(    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyR’   Ë  s$    		
c         C` sD   t  j |  d | ƒ} t  j | ƒ } |  j g } t |  | | ƒ d S(   uy   
    Try to pickle an object. If successful, make sure
    the object's attributes survived pickling and unpickling.
    t   protocolN(   t   picklet   dumpst   loadsRu   R’   (   t   originalRš   t   ft	   unpickledR•   (    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyt   check_pickling_recoveryç  s
    	gH¯¼šò×z>c         K` s2   d d l  } | j j t |  | | | ƒ | Ž  d S(   u¾   
    Raise an assertion if two objects are not equal up to desired tolerance.

    This is a :class:`~astropy.units.Quantity`-aware version of
    :func:`numpy.testing.assert_allclose`.
    i    N(   t   numpyt   testingt   assert_allcloset   _unquantify_allclose_arguments(   t   actualt   desiredt   rtolt   atolR5   t   np(    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyt   assert_quantity_allcloseó  s    	gñhãˆµøä>c         K` s+   d d l  } | j t |  | | | ƒ | Ž  S(   u¬   
    Returns True if two arrays are element-wise equal within a tolerance.

    This is a :class:`~astropy.units.Quantity`-aware version of
    :func:`numpy.allclose`.
    i    N(   R¢   t   allcloseR¥   (   R“   R”   R¨   R©   R5   Rª   (    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyt   quantity_allclose  s    c         C` s‹  d d l  m } | j |  d t d t ƒ}  | j | d t d t ƒ} y | j |  j ƒ } Wn5 | j k
 r“ | j d j | j |  j ƒ ƒ ‚ n X| d  k r² | j d ƒ } ni | j | d t d t ƒ} y | j |  j ƒ } Wn5 | j k
 r| j d j | j |  j ƒ ƒ ‚ n X| j | d t d t ƒ} y | j | j
 ƒ } Wn  t k
 rn| j d ƒ ‚ n X|  j | j | j | j f S(	   Ni   (   t   unitst   subokt   copyu@   Units for 'desired' ({0}) and 'actual' ({1}) are not convertiblei    u=   Units for 'atol' ({0}) and 'actual' ({1}) are not convertibleu   `rtol` should be dimensionless(   Ry   R®   t   QuantityRA   R|   t   tot   unitt
   UnitsErrorR   R	   t   dimensionless_unscaledt	   ExceptionRp   (   R¦   R§   R¨   R©   t   u(    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyR¥     s,    (   i   i   (   i   i   (   i   i   (   i   i   (   i   i   (4   R@   t
   __future__R    R   R   R   R8   R   RS   RV   RZ   R3   Rz   R   t   extern.six.movesR   R›   t   pkg_resourcesR_   t   utils.exceptionsR   R   t   runnerR   t   __all__t   markt   remote_dataR   R,   t   objectR-   R|   RB   RA   RC   RI   RD   RF   RH   RO   Rg   Rh   Rr   R	   R‰   t   fixtureR   R’   R¡   R«   R­   R¥   (    (    (    s3   lib/python2.7/site-packages/astropy/tests/helper.pyt   <module>   s   "				("1	?&';$			