ó
šßÈ[c           @   sÌ   d  d l  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	 m
 Z
 d d l m Z d d l m Z d d l m Z d d	 l m Z d
 d l m Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   divisiont   with_statementNi   (   t   six(   t   fits(   t   Tablei   (   t	   printdiff(   t   catch_warningsi   (   t   FitsTestCaset   TestConveniencec           B   sb   e  Z e j j d  ƒ d „  ƒ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z RS(	   s   six.PY2c         C   s˜   t  j d t ƒ t ƒ  7 } t j |  j d ƒ ƒ } t | ƒ d k sL t ‚ Wd  QXt ƒ  7 } t j	 |  j d ƒ ƒ } t | ƒ d k sŽ t ‚ Wd  QXd  S(   Nt   alwayss
   test0.fitsi    (
   t   warningst   simplefiltert   ResourceWarningR   R   t   getdatat   datat   lent   AssertionErrort	   getheader(   t   selft   wR   t   header(    (    sE   lib/python2.7/site-packages/astropy/io/fits/tests/test_convenience.pyt   test_resource_warning   s    c         C   sg   t  |  j d ƒ d ƒ } t j | ƒ } | j s7 t ‚ | j d ƒ t j | ƒ } | j sc t ‚ d S(   s¾   
        Tests that file-like objects are not closed after being passed
        to convenience functions.

        Regression test for https://github.com/astropy/astropy/issues/5063
        s
   test0.fitst   rbi    N(   t   openR   R   R   t   closedR   t   seekR   (   R   t   fR   R   (    (    sE   lib/python2.7/site-packages/astropy/io/fits/tests/test_convenience.pyt   test_fileobj_not_closed"   s    c         C   s+  t  d d d g d d d g d d d	 g g d
 d d d g d d d d g ƒ} d | d _ d | d _ t ƒ  P } t j | ƒ } t | ƒ d k s› t ‚ t | d j ƒ j	 d ƒ s½ t ‚ Wd  QX| j
 j d ƒ | j
 j d ƒ k  sí t ‚ t | t j ƒ st ‚ |  j d ƒ } | j | d t ƒd  S(   Ni   i   i   t   at   bt   cgffffff@g      @gÍÌÌÌÌÌ@t   namest   dtypet   it   U1R   s   m/ss
   not-a-uniti    s'   'not-a-unit' did not parse as fits unitt   TUNIT1t   TTYPE2s   test_table_to_hdu.fitst	   overwrite(   R   t   unitR   R   t   table_to_hduR   R   t   strt   messaget
   startswithR   t   indext
   isinstancet   BinTableHDUt   tempt   writetot   True(   R   t   tableR   t   hdut   filename(    (    sE   lib/python2.7/site-packages/astropy/io/fits/tests/test_convenience.pyt   test_table_to_hdu2   s    -!(*c         C   sÊ   t  d d d g d d d g d d d	 g g d
 d d d g d d d d g ƒ} d d d d g | j d <t j | ƒ } | j j d ƒ d d d d g k s  t ‚ t j t	 ƒ  | j j
 d ƒ Wd QXd S(   sT   
        Regression test for https://github.com/astropy/astropy/issues/6079
        i   i   i   R   R   R   gffffff@g      @gÍÌÌÌÌÌ@R   R    R!   R"   R   t   Thist   ist   commentt   commentsN(   R   t   metaR   R'   R   t   getR   t   pytestt   raisest
   ValueErrorR+   (   R   R1   R2   (    (    sE   lib/python2.7/site-packages/astropy/io/fits/tests/test_convenience.pyt,   test_table_to_hdu_convert_comment_conventionF   s    -!*c         C   s    t  j d d d t  j f d t  j f g ƒ} t j ƒ  } d | d <|  j d ƒ } t j | d	 | d
 | d t ƒt j	 | d d ƒ} | d d k sœ t
 ‚ d S(   sT   
        Regression test for https://github.com/astropy/astropy/issues/5988
        i   R    t   xt   yg      E@s   LTU&Et   ANSWERs   tabhdr42.fitsR   R   R%   t   exti   i*   N(   i   (   g      E@s   LTU&E(   t   npt   zerost   floatt   intR   t   HeaderR.   R/   R0   R   R   (   R   R   t   h_inR3   t   h_out(    (    sE   lib/python2.7/site-packages/astropy/io/fits/tests/test_convenience.pyt   test_table_writeto_headerS   s    -
c         C   sµ   |  j  d ƒ } t j t j d	 ƒ ƒ t j t j d
 ƒ ƒ g } t j | ƒ j | ƒ t j | t j d ƒ d t j	 d g ƒ d d ƒt j
 | d d ƒ} | d d k s± t ‚ d S(   s€   
        Test that _makehdu correctly includes the header. For example in the
        fits.update convenience function.
        s   twoextension.fitsi
   R   t   WHATid   RB   i   N(   i
   i
   (   i
   i
   (   i
   i
   (   RK   id   (   R.   R   t
   PrimaryHDURC   RD   t   ImageHDUt   HDUListR/   t   updateRG   R   R   (   R   R3   t   hdusRI   (    (    sE   lib/python2.7/site-packages/astropy/io/fits/tests/test_convenience.pyt"   test_image_extension_update_header_   s    	c         C   s£  t  |  j d ƒ |  j d ƒ ƒ d	 k s- t ‚ t  |  j d ƒ |  j d ƒ d d ƒd	 k s` t ‚ t  |  j d ƒ |  j d ƒ d d ƒd	 k s“ t ‚ t j t ƒ  t  d d d d ƒWd	 QXt j |  j d
 ƒ d d ƒÃ } t j |  j d ƒ d d ƒœ } t  | d | d ƒ d	 k s!t ‚ t j t	 ƒ   t  | d | d d d ƒWd	 QXt  | | ƒ d	 k smt ‚ t j t
 ƒ  t  | | d ƒ Wd	 QXWd	 QXWd	 QXd	 S(   sS   
        Test that FITSDiff can run the different inputs without crashing.
        s   arange.fitss
   blank.fitsRB   i    s   o4sp040b0_raw.fitst   extnamet   scis   fakefile.fitsNs   stddata.fitst   modet   readonlys   checksum.fits(   R   R   t   NoneR   R;   R<   t   IOErrorR   R   R=   t   NotImplementedError(   R   t   in1t   in2(    (    sE   lib/python2.7/site-packages/astropy/io/fits/tests/test_convenience.pyt   test_printdiffr   s"    $!!#!c         C   s   |  j  d ƒ } |  j d ƒ } t j | | ƒ t j | ƒ t j j |  j d ƒ ƒ s\ t	 ‚ t j | d |  j d ƒ ƒt j j |  j d ƒ ƒ s™ t	 ‚ d S(   sT   
        Regression test for https://github.com/astropy/astropy/issues/6937
        s   tb.fitss   tb_1.txtt   datafiles   test_tb.txtN(
   R   R.   t   shutilt   copyfileR   t	   tabledumpt   ost   patht   isfileR   (   R   R3   t   temp_filename(    (    sE   lib/python2.7/site-packages/astropy/io/fits/tests/test_convenience.pyt   test_tabledump“   s    !(   t   __name__t
   __module__R;   t   markt   skipifR   R   R4   R>   RJ   RQ   R[   Rd   (    (    (    sE   lib/python2.7/site-packages/astropy/io/fits/tests/test_convenience.pyR      s   						!(   t
   __future__R    R   R`   R]   R
   R;   t   numpyRC   t   externR   t   ioR   R1   R   t    R   t   tests.helperR   R   R   (    (    (    sE   lib/python2.7/site-packages/astropy/io/fits/tests/test_convenience.pyt   <module>   s   