ó
šßÈ[c           @   s   d  d l  Z  d d l m Z d d l m Z d d l m Z d d	 l m	 Z	 m
 Z
 m Z m Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d Z e j e d e j ƒZ d „  Z d „  Z  d „  Z! d „  Z" d „  Z# d „  Z$ d  „  Z% d! „  Z& d" „  Z' d# „  Z( d$ „  Z) d% „  Z* d& „  Z+ d' „  Z, d( „  Z- d) „  Z. d* „  Z/ d+ „  Z0 d S(,   iÿÿÿÿNi   (   t	   cStringIOi   (   t   asciii   (   t   InconsistentTableErrori   (   t   assert_equalt   assert_almost_equalt   setup_functiont   teardown_functionc         C   s   t  |  j ƒ  | j ƒ  ƒ d  S(   N(   R   t
   splitlines(   t   arg1t   arg2(    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   assert_equal_splitlines   s    c          C   sƒ   d }  t  j d t  j ƒ } | j |  ƒ } t | j d d g ƒ t | d d d ƒ t | d d d ƒ t | d d d	 ƒ d
 S(   s    Nice, typical fixed format tablesb   
# comment (with blank line above)
|  Col1  |  Col2   |
|  1.2   | "hello" |
|  2.4   |'s worlds|
t   Readert   Col1t   Col2i   i    g333333@s   "hello"s	   's worldsN(   R   t
   get_readert
   FixedWidtht   readR   t   colnamesR   (   t   tablet   readert   dat(    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_normal   s    c          C   s_   d }  t  j d t  j d d
 ƒ } | j |  ƒ } t | j d d g ƒ t | d d d ƒ d	 S(   s8   Nice, typical fixed format table with col names providedsb   
# comment (with blank line above)
|  Col1  |  Col2   |
|  1.2   | "hello" |
|  2.4   |'s worlds|
R   t   namest   name1t   name2i   i    g333333@N(   R   R   (   R   R   R   R   R   R   R   (   R   R   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_normal_names"   s    	c          C   sz   d }  t  j d t  j d d d d ƒ } | j |  ƒ } t | j d d g ƒ t | d d	 d
 ƒ t | d	 d d ƒ d S(   s8   Nice, typical fixed format table with col names providedsz   
# comment (with blank line above)
|  Col1  |  Col2   |  Col3 |
|  1.2   | "hello" |     3 |
|  2.4   |'s worlds|     7 |
R   R   R   R   t   name3t   include_namesi   i    g333333@i   N(   R   R   R   (   R   R   (   R   R   R   R   R   R   R   (   R   R   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_normal_names_include1   s    	c          C   s\   d }  t  j d t  j d d
 ƒ } | j |  ƒ } t | j d g ƒ t | d d d ƒ d	 S(   s7   Nice, typical fixed format table with col name excludedsb   
# comment (with blank line above)
|  Col1  |  Col2   |
|  1.2   | "hello" |
|  2.4   |'s worlds|
R   t   exclude_namesR   R   i   i    s	   's worldsN(   R   (   R   R   R   R   R   R   (   R   R   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_normal_excludeB   s    	c          C   sƒ   d }  t  j d t  j ƒ } | j |  ƒ } t | j d d g ƒ t | d d d ƒ t | d d d ƒ t | d d d	 ƒ d
 S(   s9   Weird input table with data values chopped by col extent s<   
  Col1  |  Col2 |
  1.2       "hello"
  2.4   sdf's worlds
R   R   R   i   i    g333333@s   "hels   df's woN(   R   R   R   R   R   R   R   (   R   R   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_weirdQ   s    c          C   s€   d }  t  j |  d t  j d t ƒ} t t | j j ƒ d ƒ t | d d d	 ƒ t | d d d
 ƒ t | d d d ƒ d S(   s   Table with double delimiterss‘   
|| Name ||   Phone ||         TCP||
|  John  | 555-1234 |192.168.1.10X|
|  Mary  | 555-2134 |192.168.1.12X|
|   Bob  | 555-4527 | 192.168.1.9X|
R   t   guesst   Namet   Phonet   TCPi   i    t   Marys   555-1234i   s   192.168.1.9N(   R!   R"   R#   (   R   R   R   t   FalseR   t   tuplet   dtypeR   (   R   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_double`   s    c          C   s†   d }  t  j |  d t  j d t d d ƒ} t t | j j ƒ d ƒ t | d	 d
 d ƒ t | d
 d	 d ƒ t | d d d ƒ d S(   s   Table with space delimiters   
 Name  --Phone-    ----TCP-----
 John  555-1234    192.168.1.10
 Mary  555-2134    192.168.1.12
  Bob  555-4527     192.168.1.9
R   R    t	   delimitert    R!   s   --Phone-s   ----TCP-----i   i    R$   s   555-1234i   s   192.168.1.9N(   R!   s   --Phone-s   ----TCP-----(   R   R   R   R%   R   R&   R'   R   (   R   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_space_delimitero   s    	c       
   C   sŒ   d }  t  j |  d t  j d t d d d d ƒ} t t | j j ƒ d ƒ t | d
 d d ƒ t | d d
 d ƒ t | d d d ƒ d S(   s/   Table with no header row and auto-column namingsj   
|  John  | 555-1234 |192.168.1.10|
|  Mary  | 555-2134 |192.168.1.12|
|   Bob  | 555-4527 | 192.168.1.9|
R   R    t   header_startt
   data_starti    t   col1t   col2t   col3i   R$   s   555-1234i   s   192.168.1.9N(   R.   R/   R0   (	   R   R   R   R%   t   NoneR   R&   R'   R   (   R   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_no_header_autocolumn   s    c          C   s’   d }  t  j |  d t  j d t d d d d d d ƒ} t t | j j ƒ d ƒ t | d d d ƒ t | d d d ƒ t | d d d ƒ d S(   sx   Table with no header row and with col names provided.  Second
    and third rows also have hanging spaces after final |.sj   
|  John  | 555-1234 |192.168.1.10|
|  Mary  | 555-2134 |192.168.1.12|
|   Bob  | 555-4527 | 192.168.1.9|
R   R    R,   R-   i    R   R!   R"   R#   i   R$   s   555-1234i   s   192.168.1.9N(   R!   R"   R#   (   R!   R"   R#   (	   R   R   R   R%   R1   R   R&   R'   R   (   R   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_no_header_namesŽ   s    	c          C   sz   d }  t  j |  d t  j ƒ} t t | j j ƒ d ƒ t | d d d ƒ t | d d d	 ƒ t | d
 d
 d ƒ d S(   s/   Table with no header row and auto-column namingsj   
|  John  | 555-1234 |192.168.1.10|
|  Mary  | 555-2134 |192.168.1.12|
|   Bob  | 555-4527 | 192.168.1.9|
R   R.   R/   R0   i   i    R$   s   555-1234i   s   192.168.1.9N(   R.   R/   R0   (   R   R   t   FixedWidthNoHeaderR   R&   R'   R   (   R   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt'   test_read_no_header_autocolumn_NoHeaderŸ   s    c          C   s€   d }  t  j |  d t  j d d ƒ} t t | j j ƒ d ƒ t | d d d	 ƒ t | d d d
 ƒ t | d d d ƒ d S(   sx   Table with no header row and with col names provided.  Second
    and third rows also have hanging spaces after final |.sj   
|  John  | 555-1234 |192.168.1.10|
|  Mary  | 555-2134 |192.168.1.12|
|   Bob  | 555-4527 | 192.168.1.9|
R   R   R!   R"   R#   i   i    R$   s   555-1234i   s   192.168.1.9N(   R!   R"   R#   (   R!   R"   R#   (   R   R   R4   R   R&   R'   R   (   R   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt"   test_read_no_header_names_NoHeader­   s    	c          C   s¡   d }  t  j |  d t  j d d d d d d ƒ} t t | j j ƒ d ƒ t | d d d ƒ t | d d d ƒ t | d d d ƒ t | d d d ƒ d S(   sC   Table with no delimiter with column start and end values specified.s   
#    5   9     17  18      28
#    |   |       ||         |
  John   555- 1234 192.168.1.10
  Mary   555- 2134 192.168.1.12
   Bob   555- 4527  192.168.1.9
R   R   R!   R"   R#   t
   col_startsi    i	   i   t   col_endsi   i   i   i   s	   555- 1234R$   i   s
   192.168.1.s	   192.168.1N(   R!   R"   R#   (   i    i	   i   (   i   i   i   (   R!   R"   R#   (   R   R   R4   R   R&   R'   R   (   R   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_col_starts½   s    	c       	   C   s½   d }  x° i d d 6i d d	 6f D]” } t  j |  d
 t  j d d | } t t | j j ƒ d ƒ t | d d d ƒ t | d d d ƒ t | d d d ƒ t | d d d ƒ q! Wd S(   sF   Table with no delimiter with only column start or end values specifiedsC  
#1       9        19                <== Column start indexes
#|       |         |                <== Column start positions
#<------><--------><------------->  <== Inferred column positions
  John   555- 1234 192.168.1.10
  Mary   555- 2134 192.168.1.123
   Bob   555- 4527  192.168.1.9
   Bill  555-9875  192.255.255.255
i   i	   i   R7   i   i   i!   R8   R   R   R!   R"   R#   i    s	   555- 1234R$   i   s   192.168.1.123i   s   192.255.255.255N(   i   i	   i   (   i   i   i!   (   R!   R"   R#   (   R!   R"   R#   (   R   R   R4   R   R&   R'   R   (   R   t   kwargsR   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt#   test_read_detect_col_starts_or_endsÒ   s    
		s‡   | Col1 |  Col2     |  Col3     |  Col4     |
| 1.2  | "hello"   |  1        |  a        |
| 2.4  | 's worlds |         2 |         2 |
R   c          C   s9   t  ƒ  }  t j t |  d t j ƒt |  j ƒ  d ƒ d S(   s,   Write a table as a normal fixed width table.t   Writersi   | Col1 |      Col2 | Col3 | Col4 |
|  1.2 |   "hello" |    1 |    a |
|  2.4 | 's worlds |    2 |    2 |
N(   t   StringIOR   t   writeR   R   R
   t   getvalue(   t   out(    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_write_normalò   s    	c          C   s?   t  ƒ  }  t j t |  d t j d d ƒt |  j ƒ  d ƒ d S(   s,   Write a table as a normal fixed width table.R<   t   fill_valuest   as   N/Asi   | Col1 |      Col2 | Col3 | Col4 |
|  1.2 |   "hello" |    1 |  N/A |
|  2.4 | 's worlds |    2 |    2 |
N(   RC   s   N/A(   R=   R   R>   R   R   R
   R?   (   R@   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_write_fill_valuesý   s
    	c          C   s?   t  ƒ  }  t j t |  d t j d d ƒt |  j ƒ  d ƒ d S(   s5   Write a table as a fixed width table with no padding.R<   t   delimiter_padsQ   |Col1|     Col2|Col3|Col4|
| 1.2|  "hello"|   1|   a|
| 2.4|'s worlds|   2|   2|
N(   R=   R   R>   R   R   R1   R
   R?   (   R@   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_write_no_pad	  s
    	c          C   s?   t  ƒ  }  t j t |  d t j d t ƒt |  j ƒ  d ƒ d S(   s5   Write a table as a fixed width table with no bookend.R<   t   bookends]   Col1 |      Col2 | Col3 | Col4
 1.2 |   "hello" |    1 |    a
 2.4 | 's worlds |    2 |    2
N(   R=   R   R>   R   R   R%   R
   R?   (   R@   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_write_no_bookend  s    	c       	   C   sE   t  ƒ  }  t j t |  d t j d t d d ƒt |  j ƒ  d ƒ d S(   s7   Write a table as a fixed width table with no delimiter.R<   RG   R)   sT   Col1       Col2  Col3  Col4
 1.2    "hello"     1     a
 2.4  's worlds     2     2
N(	   R=   R   R>   R   R   R%   R1   R
   R?   (   R@   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_write_no_delimiter   s
    	c          C   s9   t  ƒ  }  t j t |  d t j ƒt |  j ƒ  d ƒ d S(   s,   Write a table as a normal fixed width table.R<   s8   | 1.2 |   "hello" | 1 | a |
| 2.4 | 's worlds | 2 | 2 |
N(   R=   R   R>   R   R4   R
   R?   (   R@   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_write_noheader_normal,  s    	c          C   s?   t  ƒ  }  t j t |  d t j d d ƒt |  j ƒ  d ƒ d S(   s5   Write a table as a fixed width table with no padding.R<   RE   s(   |1.2|  "hello"|1|a|
|2.4|'s worlds|2|2|
N(   R=   R   R>   R   R4   R1   R
   R?   (   R@   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_write_noheader_no_pad6  s
    	c          C   s?   t  ƒ  }  t j t |  d t j d t ƒt |  j ƒ  d ƒ d S(   s5   Write a table as a fixed width table with no bookend.R<   RG   s0   1.2 |   "hello" | 1 | a
2.4 | 's worlds | 2 | 2
N(   R=   R   R>   R   R4   R%   R
   R?   (   R@   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_write_noheader_no_bookendA  s
    	c       	   C   sE   t  ƒ  }  t j t |  d t j d t d d ƒt |  j ƒ  d ƒ d S(   s7   Write a table as a fixed width table with no delimiter.R<   RG   R)   s*   1.2    "hello"  1  a
2.4  's worlds  2  2
N(	   R=   R   R>   R   R4   R%   R1   R
   R?   (   R@   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt    test_write_noheader_no_delimiterL  s
    	c       	   C   sM   t  ƒ  }  t j t |  d t j d i d d 6d d 6ƒt |  j ƒ  d ƒ d S(	   s7   Write a table as a fixed width table with no delimiter.R<   t   formatss   %-8.3fR   s   %-15sR   s‡   |     Col1 |            Col2 | Col3 | Col4 |
| 1.200    | "hello"         |    1 |    a |
| 2.400    | 's worlds       |    2 |    2 |
N(   R=   R   R>   R   R   R
   R?   (   R@   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_write_formatsW  s
    	c          C   st   d }  t  j |  d t  j ƒ} t | j j d ƒ t | d d d ƒ t | d d d ƒ t | d d d	 ƒ d
 S(   sj   Typical fixed format table with two header lines (with some cruft
    thrown in to test column positioningsD   
  Col1    Col2
  ----  ---------
   1.2xx"hello"
  2.4   's worlds
R   R   R   i   i    g333333@s   "hello"s	   's worldsN(   R   R   (   R   R   t   FixedWidthTwoLineR   R'   R   R   (   R   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_twoline_normalc  s    c       
   C   s†   d }  t  j |  d t  j d d d d d d ƒ} t | j j d ƒ t | d d d ƒ t | d d d ƒ t | d d d ƒ d S(   s   Read restructured text tablesn   
======= ===========
  Col1    Col2
======= ===========
  1.2   "hello"
  2.4   's worlds
======= ===========
R   R,   i   t   position_linei   t   data_endiÿÿÿÿR   R   i    g333333@s   "hello"s	   's worldsN(   R   R   (   R   R   RP   R   R'   R   R   (   R   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_twoline_ReSTs  s    	c          C   s’   d }  t  j |  d t  j d d d d d d d	 d
 d d ƒ} t | j j d ƒ t | d d d ƒ t | d d d ƒ t | d d d ƒ d S(   s\   Read text table designed for humans and test having position line
    before the header linesy   
+------+----------+
| Col1 |   Col2   |
+------|----------+
|  1.2 | "hello"  |
|  2.4 | 's worlds|
+------+----------+
R   R)   t   +R,   i   RR   i    R-   i   RS   iÿÿÿÿR   R   g333333@s   "hello"s	   's worldsN(   R   R   (   R   R   RP   R   R'   R   R   (   R   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_twoline_human…  s    
c          C   sa   d }  t  j t ƒ + } t j |  d t j d d d t ƒ} Wd QXd t | j ƒ k s] t	 ‚ d S(   s¤   Test failure if too many different character are on position line.

    The position line shall consist of only one character in addition to
    the delimiter.
    sQ   
| Col1 |   Col2   |
|------|==========|
|  1.2 | "hello"  |
|  2.4 | 's worlds|
R   R)   t   |R    NsD   Position line should only contain delimiters and one other character(
   t   pytestt   raisesR   R   R   RP   R%   t   strt   valuet   AssertionError(   R   t   excinfoR   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_twoline_failš  s
    c          C   sa   d }  t  j t ƒ + } t j |  d t j d d d t ƒ} Wd QXd t | j ƒ k s] t	 ‚ d S(   sÉ   Test failure when position line uses characters prone to ambiguity

    Characters in position line must be part an allowed set because
    normal letters or numbers will lead to ambiguous tables.
    sQ   
| Col1 |   Col2   |
|aaaaaa|aaaaaaaaaa|
|  1.2 | "hello"  |
|  2.4 | 's worlds|
R   R)   RW   R    Ns(   Characters in position line must be part(
   RX   RY   R   R   R   RP   R%   RZ   R[   R\   (   R   R]   R   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_read_twoline_wrong_marker¬  s
    c          C   s9   t  ƒ  }  t j t |  d t j ƒt |  j ƒ  d ƒ d S(   s,   Write a table as a normal fixed width table.R<   sd   Col1      Col2 Col3 Col4
---- --------- ---- ----
 1.2   "hello"    1    a
 2.4 's worlds    2    2
N(   R=   R   R>   R   RP   R
   R?   (   R@   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_write_twoline_normal¾  s    	c       	   C   sE   t  ƒ  }  t j t |  d t j d d d d ƒt |  j ƒ  d ƒ d S(   s5   Write a table as a fixed width table with no padding.R<   RE   R*   t   position_chart   =s|   Col1        Col2   Col3   Col4
====   =========   ====   ====
 1.2     "hello"      1      a
 2.4   's worlds      2      2
N(   R=   R   R>   R   RP   R
   R?   (   R@   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_write_twoline_no_padÊ  s
    	c       	   C   sE   t  ƒ  }  t j t |  d t j d t d d ƒt |  j ƒ  d ƒ d S(   s5   Write a table as a fixed width table with no bookend.R<   RG   R)   RW   sl   |Col1|     Col2|Col3|Col4|
|----|---------|----|----|
| 1.2|  "hello"|   1|   a|
| 2.4|'s worlds|   2|   2|
N(   R=   R   R>   R   RP   t   TrueR
   R?   (   R@   (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   test_write_twoline_no_bookend×  s
    	(1   RX   t   extern.six.movesR    R=   t    R   t   coreR   t   commonR   R   R   R   R
   R   R   R   R   R   R(   R+   R2   R3   R5   R6   R9   R;   R   R   R   R   RA   RD   RF   RH   RI   RJ   RK   RL   RM   RO   RQ   RT   RV   R^   R_   R`   Rc   Re   (    (    (    sE   lib/python2.7/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyt   <module>   sL   "																				
											