ó
ßČ[c           @   ss   d  Z  d d l Z d d l Z y d d l j Z Wn e k
 rJ d Z n Xd   Z d   Z	 d   Z
 d   Z d S(   sY   
This plugin provides support for testing whether file-like objects are properly
closed.
i˙˙˙˙Nc         C   s9   |  j  d d d d d |  j d d d d	 d
 d d  S(   Ns   --open-filest   actiont
   store_truet   helps"   fail if any test leaves files opent   open_files_ignoresě   when used with the --open-files option, allows specifying names of files that may be ignored when left open between tests--files in this list are matched may be specified by their base name (ignoring their full path) or by absolute patht   typet   argst   default(    (   t	   addoptiont   addini(   t   parser(    (    sM   lib/python2.7/site-packages/astropy/extern/plugins/pytest_openfiles/plugin.pyt   pytest_addoption   s
    	c          C   s   d d  l  }  g  } |  j   } t d  k	 r? t t j    } n t d   t j   D  } g  | j   D]! } | j	 j
 |  sh | j	 ^ qh } t |  S(   Ni˙˙˙˙c         s   s   |  ] } | d  Vq d S(   i    N(    (   t   .0t   info(    (    sM   lib/python2.7/site-packages/astropy/extern/plugins/pytest_openfiles/plugin.pys	   <genexpr>.   s    (   t   psutilt   Processt   importlib_machineryt   Nonet   tuplet   all_suffixest   impt   get_suffixest
   open_filest   patht   endswitht   set(   R   t   filest   pt   suffixest   x(    (    sM   lib/python2.7/site-packages/astropy/extern/plugins/pytest_openfiles/plugin.pyt   _get_open_file_list&   s    4c         C   s%   |  j  j d  r! t   |  _ n  d  S(   NR   (   t   configt   getvalueR   R   (   t   item(    (    sM   lib/python2.7/site-packages/astropy/extern/plugins/pytest_openfiles/plugin.pyt   pytest_runtest_setup5   s    c         C   s  |  j  j d  s# t |  d  r' d  S|  j } |  ` t   } |  j d k rt t |  d t |  k sp t  d  St   } |  j  j	 d  } x | D] } t
 } x[ | D]S } t j j |  sć t j j |  | k rü t } Pqü qŠ | | k rŠ t } PqŠ qŠ W| rq n  | | k r | j |  q q Wt |  rd g }	 x$ | D] }
 |	 j d j |
   qHWt d j |	    n  d  S(   NR   t   test_open_file_detectioni   R   s   File(s) not closed:s     {0}s   
(   R   R   t   hasattrR   R   t   namet   lent   AssertionErrorR   t   getinit   Falset   osR   t   isabst   basenamet   Truet   addt   appendt   formatt   join(   R    t   nextitemt   start_open_filesR   t
   not_closedR   t   filenamet   ignoret   ignoredt   msgR$   (    (    sM   lib/python2.7/site-packages/astropy/extern/plugins/pytest_openfiles/plugin.pyt   pytest_runtest_teardown<   s<    		"		(   t   __doc__R   R)   t   importlib.machineryt	   machineryR   t   ImportErrorR   R
   R   R!   R8   (    (    (    sM   lib/python2.7/site-packages/astropy/extern/plugins/pytest_openfiles/plugin.pyt   <module>   s   
			