
    HR-eD                     T   d dl mZ d dlZd dlZd dlmZ d dlmZ ddl	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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( Z/d) Z0d* Z1d+ Z2d, Z3dS )-    )StringION)ascii)InconsistentTableError   )assert_almost_equalassert_equalc                 n    t          |                                 |                                           d S )N)r   
splitlines)arg1arg2s     Flib/python3.11/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyassert_equal_splitlinesr      s,    ""DOO$5$566666    c                  H   d} t          j        t           j                  }|                    |           }t	          |j        ddg           t          |d         d         d           t	          |d         d         d           t	          |d         d         d	           d
S )z Nice, typical fixed format tableb
# comment (with blank line above)
|  Col1  |  Col2   |
|  1.2   | "hello" |
|  2.4   |'s worlds|
ReaderCol1Col2r   r   333333@"hello"	's worldsNr   
get_reader
FixedWidthreadr   colnamesr   tablereaderdats      r   test_read_normalr"      s    E U%5666F
++e

C/000Aq	3'''QI&&&QK(((((r   c                      d} t          j        t           j        d          }|                    |           }t	          |j        ddg           t          |d         d         d           d	S )
8Nice, typical fixed format table with col names providedr   )name1name2r   namesr%   r&   r   r   r   Nr   r   s      r   test_read_normal_namesr)   #   sj    E U%5=OPPPF
++e

C1222Aq	3'''''r   c                     d} t          j        t           j        dd          }|                    |           }t	          |j        ddg           t          |d         d         d	           t	          |d         d         d
           dS )r$   zz
# comment (with blank line above)
|  Col1  |  Col2   |  Col3 |
|  1.2   | "hello" |     3 |
|  2.4   |'s worlds|     7 |
)r%   r&   name3)r%   r+   )r   r(   include_namesr%   r+   r   r   r      Nr   r   s      r   test_read_normal_names_includer.   1   s    E )(  F
 ++e

C1222Aq	3'''QAr   c                      d} t          j        t           j        d          }|                    |           }t	          |j        dg           t	          |d         d         d           dS )	z7Nice, typical fixed format table with col name excludedr   )r   )r   exclude_namesr   r   r   r   N)r   r   r   r   r   r   r   s      r   test_read_normal_excluder1   D   sf    E U%5YOOOF
++e

Cx(((QK(((((r   c                  H   d} t          j        t           j                  }|                    |           }t	          |j        ddg           t          |d         d         d           t	          |d         d         d           t	          |d         d         d	           d
S )z8Weird input table with data values chopped by col extentz<
  Col1  |  Col2 |
  1.2       "hello"
  2.4   sdf's worlds
r   r   r   r   r   r   z"helzdf's woNr   r   s      r   test_read_weirdr3   R   s    E
 U%5666F
++e

C/000Aq	3'''QF###QI&&&&&r   c                  B   d} t          j        | t           j        d          }t          t	          |j        j                  d           t          |d         d         d           t          |d         d         d           t          |d	         d	         d
           dS )zTable with double delimitersz
|| Name ||   Phone ||         TCP||
|  John  | 555-1234 |192.168.1.10X|
|  Mary  | 555-2134 |192.168.1.12X|
|   Bob  | 555-4527 | 192.168.1.9X|
F)r   guessNamePhoneTCPr   r   Mary555-1234   192.168.1.9Nr   r   r   r   tupledtyper(   r   r!   s     r   test_read_doublerB   a   s    E *U5#35
A
A
ACsy'')ABBBQF###QJ'''QM*****r   c                  D   d} t          j        | t           j        dd          }t          t	          |j        j                  d           t          |d         d         d           t          |d         d         d	           t          |d
         d
         d           dS )zTable with space delimiterz
 Name  --Phone-    ----TCP-----
 John  555-1234    192.168.1.10
 Mary  555-2134    192.168.1.12
  Bob  555-4527     192.168.1.9
F )r   r5   	delimiter)r7   z--Phone-z----TCP-----r   r   r:   r;   r<   r=   Nr>   rA   s     r   test_read_space_delimiterrF   p   s    E *U5#35C
P
P
PCsy'')MNNNQF###QJ'''QM*****r   c                  F   d} t          j        | t           j        ddd          }t          t	          |j        j                  d           t          |d         d         d           t          |d         d         d	           t          |d
         d
         d           dS )/Table with no header row and auto-column namingj
|  John  | 555-1234 |192.168.1.10|
|  Mary  | 555-2134 |192.168.1.12|
|   Bob  | 555-4527 | 192.168.1.9|
FNr   )r   r5   header_start
data_startcol1col2col3r   r:   r;   r<   r=   r>   rA   s     r   test_read_no_header_autocolumnrP      s    E
 *e&e$ST  C sy'')ABBBQF###QJ'''QM*****r   c                  H   d} t          j        | t           j        dddd          }t          t	          |j        j                  d           t          |d         d         d           t          |d         d         d	           t          |d
         d
         d           dS )xTable with no header row and with col names provided.  Second
    and third rows also have hanging spaces after final |.rI   FNr   r6   )r   r5   rJ   rK   r(   r   r:   r;   r<   r=   r>   rA   s     r   test_read_no_header_namesrS      s    E
 *&  C sy'')ABBBQF###QJ'''QM*****r   c                  @   d} t          j        | t           j                  }t          t	          |j        j                  d           t          |d         d         d           t          |d         d         d           t          |d         d         d	           d
S )rH   rI   r   rL   r   r   r:   r;   r<   r=   Nr   r   FixedWidthNoHeaderr   r?   r@   r(   rA   s     r   'test_read_no_header_autocolumn_NoHeaderrW      s    E
 *U5#;
<
<
<Csy'')ABBBQF###QJ'''QM*****r   c                  B   d} t          j        | t           j        d          }t          t	          |j        j                  d           t          |d         d         d           t          |d         d         d           t          |d         d         d	           d
S )rR   rI   r6   r'   r   r   r:   r;   r<   r=   NrU   rA   s     r   "test_read_no_header_names_NoHeaderrY      s    E
 *e.6N  C sy'')ABBBQF###QJ'''QM*****r   c                  ~   d} t          j        | t           j        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 )zCTable with no delimiter with column start and end values specified.z
#    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
r6   )r   	      )         )r   r(   
col_startscol_endsr   r   	555- 1234r:   r<   z
192.168.1.z	192.168.1NrU   rA   s     r   test_read_col_startsrc      s    E *'&  C sy'')ABBBQK(((QF###QL)))QK(((((r   c                     d} ddiddifD ]}t          j        | f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           dS )zFTable with no delimiter with only column start or end values specifiedaC  
#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
r`   )r   r[      ra   )   r\   !   r6   r'   r   r   rb   r:   r<   z192.168.1.123r-   z192.255.255.255NrU   )r   kwargsr!   s      r   #test_read_detect_col_starts_or_endsri      s    E !*-
K/HI 3 3j
+*
 
 	
 
 	U39?++-EFFFSVAY,,,SVAY'''SVAY000SVAY 122223 3r   z| Col1 |  Col2     |  Col3     |  Col4     |
| 1.2  | "hello"   |  1        |  a        |
| 2.4  | 's worlds |         2 |         2 |
r   c                      t                      } t          j        t          | t          j                   t          |                                 d           dS ),Write a table as a normal fixed width table.Writerzi| Col1 |      Col2 | Col3 | Col4 |
|  1.2 |   "hello" |    1 |    a |
|  2.4 | 's worlds |    2 |    2 |
Nr   r   writer!   r   r   getvalueouts    r   test_write_normalrs      sQ    
**C	KS!12222	    r   c                      t                      } t          j        t          | t          j        d           t          |                                 d           dS )rk   )azN/A)rm   fill_valueszi| Col1 |      Col2 | Col3 | Col4 |
|  1.2 |   "hello" |    1 |  N/A |
|  2.4 | 's worlds |    2 |    2 |
Nrn   rq   s    r   test_write_fill_valuesrw   
  sS    
**C	KS!1|LLLL	    r   c                      t                      } t          j        t          | t          j        d           t          |                                 d           dS )5Write a table as a fixed width table with no padding.Nrm   delimiter_padzQ|Col1|     Col2|Col3|Col4|
| 1.2|  "hello"|   1|   a|
| 2.4|'s worlds|   2|   2|
rn   rq   s    r   test_write_no_padr|     sS    
**C	KS!1FFFF	    r   c                      t                      } t          j        t          | t          j        d           t          |                                 d           dS )5Write a table as a fixed width table with no bookend.Frm   bookendz]Col1 |      Col2 | Col3 | Col4
 1.2 |   "hello" |    1 |    a
 2.4 | 's worlds |    2 |    2
Nrn   rq   s    r   test_write_no_bookendr   &  sS    
**C	KS!15AAAA	    r   c                      t                      } t          j        t          | t          j        dd           t          |                                 d           dS )7Write a table as a fixed width table with no delimiter.FNrm   r   rE   zTCol1       Col2  Col3  Col4
 1.2    "hello"     1     a
 2.4  's worlds     2     2
rn   rq   s    r   test_write_no_delimiterr   4  sU    
**C	KS!15DQQQQ	    r   c                      t                      } t          j        t          | t          j                   t          |                                 d           dS )rk   rl   z8| 1.2 |   "hello" | 1 | a |
| 2.4 | 's worlds | 2 | 2 |
Nr   r   ro   r!   rV   r   rp   rq   s    r   test_write_noheader_normalr   B  sQ    
**C	KS!9::::	    r   c                      t                      } t          j        t          | t          j        d           t          |                                 d           dS )ry   Nrz   z(|1.2|  "hello"|1|a|
|2.4|'s worlds|2|2|
r   rq   s    r   test_write_noheader_no_padr   O  sS    
**C	KS!9NNNN	    r   c                      t                      } t          j        t          | t          j        d           t          |                                 d           dS )r~   Fr   z01.2 |   "hello" | 1 | a
2.4 | 's worlds | 2 | 2
Nr   rq   s    r   test_write_noheader_no_bookendr   \  sS    
**C	KS!95IIII	    r   c                      t                      } t          j        t          | t          j        dd           t          |                                 d           dS )r   FNr   z*1.2    "hello"  1  a
2.4  's worlds  2  2
r   rq   s    r    test_write_noheader_no_delimiterr   i  s`    
**C	KS15D    	    r   c                      t                      } t          j        t          | t          j        ddd           t          |                                 d           dS )r   z%-8.3fz%-15sr   r   )rm   formatsz|     Col1 |            Col2 | Col3 | Col4 |
| 1.200    | "hello"         |    1 |    a |
| 2.400    | 's worlds       |    2 |    2 |
Nrn   rq   s    r   test_write_formatsr   x  sf    
**C	KS)Hg3V3V    	    r   c                  &   d} t          j        | t           j                  }t          |j        j        d           t          |d         d         d           t          |d         d         d           t          |d         d         d           d	S )
zjTypical fixed format table with two header lines (with some cruft
    thrown in to test column positioningzD
  Col1    Col2
  ----  ---------
   1.2xx"hello"
  2.4   's worlds
r   r   r   r   r   r   r   Nr   r   FixedWidthTwoLiner   r@   r(   r   rA   s     r   test_read_twoline_normalr     s    E *U5#:
;
;
;C"2333Aq	3'''QI&&&QK(((((r   c                  ,   d} t          j        | t           j        ddd          }t          |j        j        d           t          |d         d         d           t          |d         d         d	           t          |d         d         d
           dS )zRead restructured text tablezn
======= ===========
  Col1    Col2
======= ===========
  1.2   "hello"
  2.4   's worlds
======= ===========
r   r<   )r   rJ   position_linedata_endr   r   r   r   r   Nr   rA   s     r   test_read_twoline_ReSTr     s    E *&  C "2333Aq	3'''QI&&&QK(((((r   c            	      0   d} t          j        | t           j        ddddd          }t          |j        j        d           t          |d         d         d	           t          |d         d         d
           t          |d         d         d           dS )z\Read text table designed for humans and test having position line
    before the header linezy
+------+----------+
| Col1 |   Col2   |
+------|----------+
|  1.2 | "hello"  |
|  2.4 | 's worlds|
+------+----------+
+r   r   r-   r   )r   rE   rJ   r   rK   r   r   r   r   r   Nr   rA   s     r   test_read_twoline_humanr     s    E *&  C "2333Aq	3'''QI&&&QK(((((r   c                      d} t          j        t                    5 }t          j        | t          j        dd           ddd           n# 1 swxY w Y   dt          |j                  v sJ dS )zTest failure if too many different character are on position line.

    The position line shall consist of only one character in addition to
    the delimiter.
    zQ
| Col1 |   Col2   |
|------|==========|
|  1.2 | "hello"  |
|  2.4 | 's worlds|
|Fr   rE   r5   NzDPosition line should only contain delimiters and one other characterpytestraisesr   r   r   r   strvaluer   excinfos     r   test_read_twoline_failr     s    E 
-	.	. V'
5!8CuUUUUV V V V V V V V V V V V V V V 	Ow}	 	 	 	 	 	   #AAAc                      d} t          j        t                    5 }t          j        | t          j        dd           ddd           n# 1 swxY w Y   dt          |j                  v sJ dS )zTest 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.
    zQ
| Col1 |   Col2   |
|aaaaaa|aaaaaaaaaa|
|  1.2 | "hello"  |
|  2.4 | 's worlds|
r   Fr   Nz(Characters in position line must be partr   r   s     r   test_read_twoline_wrong_markerr     s    E 
-	.	. V'
5!8CuUUUUV V V V V V V V V V V V V V V5W]9K9KKKKKKKr   c                      t                      } t          j        t          | t          j                   t          |                                 d           dS )rk   rl   zdCol1      Col2 Col3 Col4
---- --------- ---- ----
 1.2   "hello"    1    a
 2.4 's worlds    2    2
Nr   r   ro   r!   r   r   rp   rq   s    r   test_write_twoline_normalr     sQ    
**C	KS!89999	    r   c                      t                      } t          j        t          | t          j        dd           t          |                                 d           dS )ry   rD   =)rm   r{   position_charz|Col1        Col2   Col3   Col4
====   =========   ====   ====
 1.2     "hello"      1      a
 2.4   's worlds      2      2
Nr   rq   s    r   test_write_twoline_no_padr     sa    
**C	KS0SV    	    r   c                      t                      } t          j        t          | t          j        dd           t          |                                 d           dS )r~   Tr   r   zl|Col1|     Col2|Col3|Col4|
|----|---------|----|----|
| 1.2|  "hello"|   1|   a|
| 2.4|'s worlds|   2|   2|
Nr   rq   s    r   test_write_twoline_no_bookendr     sV    
**C	KS!8$RUVVVV	    r   c                  ,   d} g d}t          j        | ddd|d          }|j        |k    sJ t          j        |d         dd	gk              sJ t          j        |d
         ddgk              sJ t          j        |d         ddgk              sJ dS )z3Test fix in #8511 where data_start is being ignoredzAAA y z
1 2 3
4 5 6
7 8 9
)ru   bcr   r-   rD   fixed_width_no_header)rK   r   rE   r(   formatru      r   r<   r]   r      N)r   r   r   npall)tblr(   r!   s      r   !test_fixedwidthnoheader_splittingr     s    C OOE
*&  C <5    6#c(q!f$%%%%%6#c(q!f$%%%%%6#c(q!f$%%%%%%%r   c                      g d} g d}t          j        | dd|          }t                      }t          j        ||dd|           |                                                                | k    sJ d S )N)z&| int16 | float32 |      <U3 | int64 |z&|     a |       b |        c |     d |z&|     m |         |          | m / s |z&|       |     .2f |          |       |z&|       |         | C column |       |z&|     1 |    1.00 |        c |     4 |z&|     2 |    2.00 |        d |     5 |z&|     3 |    3.00 |        e |     6 |)r@   nameunitr   descriptionfixed_widthr   )r   rE   header_rowsr   r   r   ro   rp   r
   r   r   r!   rr   s       r   test_fixed_width_header_rowsr   4  s    	 	 	C EDDK
*S#;
W
W
WC
**C	KS#;WWWW<<>>$$&&#------r   c                      g d} g d}t          j        | d|          }t                      }t          j        ||d|           |                                                                | k    sJ d S )N)	zint32 float32      <U2 int64z    m                  m / sz          .2f               z              C column      z    a       b        c     dz----- ------- -------- -----    1    1.00        c     4z    2    2.00        d     5z    3    3.00        e     6)r@   r   r   r   r   fixed_width_two_liner   r   r   r   s       r   %test_fixed_width_two_line_header_rowsr   F  s    
 
 
C EDDK
*S!7[
Q
Q
QC
**C	KS!7[QQQQ<<>>$$&&#------r   c                      dg} t          j        t          d          5  t          j        | ddg           d d d            d S # 1 swxY w Y   d S )Nr   z)unexpected keyword argument 'header_rows')matchr   r   r   )r   r   	TypeErrorr   r   )r   s    r   &test_fixed_width_no_header_header_rowsr   Y  s    )
*C	y(T	U	U	U N N
36VHMMMMN N N N N N N N N N N N N N N N N Ns   AA	A	)4ior   numpyr   r   
astropy.ior   astropy.io.ascii.corer   commonr   r   r   r"   r)   r.   r1   r3   rB   rF   rP   rS   rW   rY   rc   ri   r   r   r   r!   rs   rw   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   <module>r      s                    8 8 8 8 8 8 5 5 5 5 5 5 5 57 7 7) ) ) ( ( (  &) ) )' ' '+ + ++ + ++ + + + + +,+ + ++ + +") ) ).3 3 32	
 eju/000          
 
 

 
 

 
 
     ) ) ) ) ) ).) ) )4  (L L L"    "  & & &.. . .$. . .&N N N N Nr   