σ
ίΘ[c           @` sδ  d  Z  d d l m Z m Z m Z m Z d d l Z d d l m Z d d l 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 Z d d l Z d d l Z d d l m Z d d l m Z d d l Z d d	 l m Z m Z d
 d l m Z m Z d
 d l m Z d d l m  Z  d d l! m" Z" y d d l# j$ Z% Wn e& k
 rtd Z% n Xd g Z( d Z) xE d d d g D]4 Z* e e*  d k re( j+ d j, e) e*   qqWe- e	 d e.  rλe j/   n  d   Z0 d   Z1 d   Z2 d   Z3 e d2 d3 d4 d5 d6 g  Z4 d d# l5 m6 Z6 e d$ e6 f g  Z7 d%   Z8 d&   Z9 d' e j: f d(     YZ; e j< d) d* e j= Z> d+ e j? f d,     YZ@ d- e@ f d.     YZA d/ e@ f d0     YZB d1   ZC d S(7   us   
These plugins modify the behavior of py.test and are meant to be imported
into conftest.py in the root directory.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   six(   t   builtins(   t   find_loader(   t   OrderedDict(   t   set_temp_configt   set_temp_cachei   (   t    treat_deprecations_as_exceptionst   ignore_warnings(   t!   enable_deprecations_as_exceptions(   t   writeable_directory(   t   resolve_nameu   astropy.tests.pytest_repeatu   astropy.extern.pluginsu   pytest_doctestplusu   pytest_openfilesu   pytest_remotedatau   {}.{}.pluginu   _pytest_runningc         C` sn   |  j  d d d d t d d |  j  d d d d t d d |  j d	 d d
 d  |  j d d d
 d  d  S(   Nu   --astropy-config-dirt   nargsu   ?t   typet   helpu  specify directory for storing and retrieving the Astropy configuration during tests (default is to use a temporary directory created by the test runner); be aware that using an Astropy config file other than the default can cause some tests to fail unexpectedlyu   --astropy-cache-diru   specify directory for storing and retrieving the Astropy cache during tests (default is to use a temporary directory created by the test runner)u   astropy_config_dirt   defaultu   astropy_cache_dir(   t	   addoptionR   t   addinit   None(   t   parser(    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyt   pytest_addoption8   s    		c         C` s   t    d  S(   N(   R
   (   t   config(    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyt   pytest_configureV   s    c         C` s’   |  j  j d  } |  j  j d  } |  j  j d  p9 | } |  j  j d  pQ | } | ry t |  |  _ |  j j   n  | r t |  |  _ |  j j   n  d  S(   Nu   astropy_config_diru   astropy_cache_dir(   R   t   getinit	   getoptionR   t	   __enter__R	   (   t   itemt
   config_dirt	   cache_dir(    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyt   pytest_runtest_setupY   s    c         C` sB   t  |  d  r |  j j   n  t  |  d  r> |  j j   n  d  S(   Nu   set_temp_cacheu   set_temp_config(   t   hasattrR	   t   __exit__R   (   R   t   nextitem(    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyt   pytest_runtest_teardownl   s    u   Numpyu   numpyu   Scipyu   scipyu
   Matplotlibu
   matplotlibu   h5pyu   Pandasu   pandas(   t   __version__u   Astropyc         C` sK  y t  j j p d } Wn t k
 r/ d } n Xt j ra g  |  j D] } | j d  ^ qC } n	 |  j } t t	  d k r½ xQ t	 j
   D]- \ } } | d k r d j | |  } q q Wn d j t	 d  } t |  d  rKt |  j  } | j t j  s| t j 7} n  g  | D]+ } | j |  r<| t |  n | ^ q}	 n | }	 | d j d	 j |	   7} | d
 j t j j   j   d   7} d d l m }
 |
   } t | t  rΠ| j | d  } n  | d j |  7} | d j t  j  7} | d j t  j  7} | d j t  j   t j   t  j    7} t  j  d# k  rt| d j t! t" j# t  j$ d    7} n  | d 7} | d j t  j%  7} | d j t  j&  7} x€ t j' t(  D] \ } } y# t) t*   t+ |  } Wd  QXWn$ t, k
 r| d j |  7} qΊXy | j- } Wn t k
 r6d } n X| d j | |  7} qΊWy d d l m. } Wn t, k
 rxn X| d j |  7} d d g } g  } xc | D][ } t/ |  j0 | d   } | r₯t | t j2  rπd  j | | f  } n  | j3 |  q₯q₯W| r)| d! j d" j |   7} n  t j rG| j4 | d  } n  | S($   Nu   asciiu   utf-8i   u   Astropyu%   
Running tests with {0} version {1}.
u)   
Running tests with Astropy version {0}.
u   rootdiru   Running tests in {0}.

u    u   Date: {0}

i   i    (   t   platformu   replaceu   Platform: {0}

u   Executable: {0}

u   Full Python Version: 
{0}

u1   encodings: sys: {0}, locale: {1}, filesystem: {2}i   u   , unicode bits: {0}i   u   
u   byteorder: {0}
u-   float info: dig: {0.dig}, mant_dig: {0.dig}

u   {0}: not available
u"   unknown (no __version__ attribute)u	   {0}: {1}
(   t   astropy_helpers_versionu   astropy_helpers: {0}
u   remote_datau   pep8u   : u   Using Astropy options: {0}.
u   , (   i   i   i    (5   t   syst   stdoutt   encodingt   AttributeErrorR   t   PY2t   argst   decodet   lent   TESTED_VERSIONSt   itemst   formatR!   t   strt   rootdirt   endswitht   ost   sept
   startswitht   joint   datetimet   nowt	   isoformatR&   t
   isinstancet   bytest
   executablet   versiont   getdefaultencodingt   localet   getpreferredencodingt   getfilesystemencodingt   version_infot   intt   matht   logt
   maxunicodet	   byteordert
   float_infot	   iteritemst   PYTEST_HEADER_MODULESR   t   DeprecationWarningR   t   ImportErrorR%   R'   t   getattrt   optionR   t   string_typest   appendt   encode(   R   t   stdoutencodingt   xR-   t   pkgR@   t   sR4   t   argt   dirsR&   t   platt   module_displayt   module_namet   moduleR'   t   special_optst   optst   opt   op_value(    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyt   pytest_report_header   s    
	(	8&					"
	
	c         C` s*   t  j r t |  |  St j |  |  Sd  S(   N(   R   R,   t   Pairt   pytestt   Module(   t   patht   parent(    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyt   pytest_pycollect_makemoduleΰ   s    	Rd   c           B` s   e  Z d  Z d   Z RS(   u   
    This class treats a given test .py file as a pair of .py files
    where one has __future__ unicode_literals and the other does not.
    c         C` s1  y |  j  j d t  } Wn t k
 rb d d  l } | j j   } |  j | j d d    nB |  j  j	 k
 r£ t
 j   d } |  j d j | j    n Xt j t j |  j   d   } | j   } Wd  QXd | k rt | j | |  j  |   t | j | |  j  |   g St j |  j  |   g Sd  S(	   Nt   ensuresyspathi    t   styleu   shorti   uκ   import file mismatch:
imported module {!r} has this __file__ attribute:
  {}
which is not the same as the test file we want to collect:
  {}
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modulesu   rbt   TEST_UNICODE_LITERALS(   t   fspatht   pyimportt   Truet   SyntaxErrort   pyt   codet   ExceptionInfot   CollectErrort   getreprt   ImportMismatchErrorR(   t   exc_infoR2   R-   t   iot   openR   t	   text_typet   readt   UnicodeLiteralsModulet   __name__t   NoUnicodeLiteralsModuleRe   Rf   (   t   selft   modRq   t   excinfot   et   fdt   content(    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyt   collectρ   s"    !(   R}   t
   __module__t   __doc__R   (    (    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyRd   λ   s   s+   from __future__ import ((\(.*?\))|([^\n]+))t   flagst   ModifiedModulec           B` s   e  Z d    Z d   Z RS(   c         C` s/   | |  _  | |  _ t t |   j | |  d  S(   N(   t   mod_nameR   t   superR   t   __init__(   R   R   R   Rg   Rh   (    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyR     s    		c         C` sC  t  j t d |  j  } t j |  j  } t j |  j	  | _
 t |  d  r¬ t | t j |  j	  d |  j t j Bt  } |  j |  } t | t j |  j	  d  } n' t | t j |  j	  d |  j t  } t j   } z< t j t j j t j |  j	    t j | | j  Wd  t j |  X|  j j j |  | S(   Ns   
u   _transform_astu   exec(   t   ret   subt   _RE_FUTURE_IMPORTSR   t   typest
   ModuleTypeR   R   Rz   Rm   t   __file__R!   t   compileR   t   astt   PyCF_ONLY_ASTRo   t   _transform_astR6   t   getcwdt   chdirRg   t   dirnamet   exec_t   __dict__R   t   pluginmanagert   consider_module(   R   R   t   new_modt   treeRr   t   pwd(    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyt   _importtestmodule  s(    %(   R}   R   R   R‘   (    (    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyR     s   	R|   c           B` s2   e  Z e j j e j j Be j j Be j j BZ RS(    (	   R}   R   t
   __future__R    t   compiler_flagR   R   R   R   (    (    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyR|   C  s   R~   c           B` s1   e  Z e j j e j j Be j j BZ d    Z RS(   c         C` s)   d t  j f d     Y} |   j |  S(   Nt   NonAsciiLiteralc           B` s   e  Z d    Z RS(   c         S` s   | j  } t | t  r y | j d  Wq t k
 r y | j d  } Wn t k
 r_ q Xt j t j d |  |  Sq Xn  | S(   Nu   asciiu   utf-8RX   (   RX   R=   R>   R.   t   UnicodeDecodeErrorR   t   copy_locationt   Str(   R   t   nodeRX   (    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyt	   visit_Str^  s    	#(   R}   R   R©   (    (    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyR€   ]  s   (   R   t   NodeTransformert   visit(   R   R   R€   (    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyR   S  s    
(	   R}   R   R’   R    R£   R   R   R   R   (    (    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyR~   L  s   c         C` s]   y t    Wn t k
 r d SX|  j j d  s6 d S|  j   |  j d d t d t d S(   u;   Output a warning to IPython users in case any tests failed.Nu   failedu  Some tests are known to fail when run from the IPython prompt; especially, but not limited to tests involving logging and warning handling.  Unless you are certain as to the cause of the failure, please check that the failure occurs outside IPython as well.  See http://docs.astropy.org/en/stable/known_issues.html#failing-logging-tests-when-running-the-tests-in-ipython for more information.t   yellowt   bold(   t   get_ipythont	   NameErrort   statst   gett   ensure_newlinet
   write_lineRo   (   t   terminalreporter(    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyt   pytest_terminal_summaryn  s    
(   u   Numpyu   numpy(   u   Scipyu   scipy(   u
   Matplotlibu
   matplotlib(   u   h5pyu   h5py(   u   Pandasu   pandas(D   R   R’   R    R   R   R   t   externR   t   extern.six.movesR   R   R:   Rx   RB   RG   R6   R   R(   R   t   pkgutilR   t   collectionsR   Re   t   config.pathsR   R	   t   helperR
   R   R   t   utils.argparseR   t   utils.introspectionR   t   importlib.machineryt	   machineryt   importlib_machineryRO   R   t   pytest_pluginst   _PLUGINS_PREFIXt   pluginRS   R2   RP   t   Falset   skipR   R   R    R$   RM   t    R%   R0   Rc   Ri   t   FileRd   R   t   DOTALLR   Rf   R   R|   R~   R΅   (    (    (    s;   lib/python2.7/site-packages/astropy/tests/pytest_plugins.pyt   <module>   sh   "
	 					a	**	"