U
    e»{jD  ã                   @   s|  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d„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#Zejeejd$�Zd%d&„ Zd'd(„ Zd)d*„ Z d+d,„ Z!d-d.„ Z"d/d0„ Z#d1d2„ Z$d3d4„ Z%d5d6„ Z&d7d8„ Z'd9d:„ Z(d;d<„ Z)d=d>„ Z*d?d@„ Z+dAdB„ Z,dCdD„ Z-dEdF„ Z.dGdH„ Z/dIdJ„ Z0dKdL„ Z1dMdN„ Z2dOdP„ Z3dS )Qé    )ÚStringION)Úascii)ÚInconsistentTableErroré   )Úassert_almost_equalÚassert_equalc                 C   s   t |  ¡ | ¡ ƒ d S )N)r   Ú
splitlines)Zarg1Zarg2© r	   úe/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/io/ascii/tests/test_fixedwidth.pyÚassert_equal_splitlines   s    r   c                  C   sf   d} t jt jd�}| | ¡}t|jddgƒ t|d d dƒ t|d d dƒ t|d d d	ƒ d
S )z Nice, typical fixed format tableúb
# 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Údatr	   r	   r
   Útest_read_normal   s    
r   c                  C   sD   d} t jt jd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   r	   r	   r
   Útest_read_normal_names#   s
    
r#   c                  C   sX   d} t jt jd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"   Zinclude_namesr   r$   r   r   r   é   Nr   r   r	   r	   r
   Útest_read_normal_names_include1   s    ý
r&   c                  C   sB   d} t jt jdd�}| | ¡}t|jdgƒ t|d d dƒ dS )	z7Nice, typical fixed format table with col name excludedr   )r   )r   Zexclude_namesr   r   r   r   N)r   r   r   r   r   r   r   r	   r	   r
   Útest_read_normal_excludeD   s
    
r'   c                  C   sf   d} t jt jd�}| | ¡}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   r	   r	   r
   Útest_read_weirdR   s    
r(   c                  C   sb   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 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©ÚNameZPhoneZTCPr   r   ÚMaryú555-1234é   ú192.168.1.9N©r   r   r   r   ÚtupleÚdtyper"   ©r   r   r	   r	   r
   Útest_read_doublea   s    r4   c                  C   sd   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 )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   r)   Ú	delimiter)r+   z--Phone-z----TCP-----r   r   r,   r-   r.   r/   Nr0   r3   r	   r	   r
   Útest_read_space_delimiterp   s    r7   c                  C   sf   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 )ú/Table with no header row and auto-column namingúj
|  John  | 555-1234 |192.168.1.10|
|  Mary  | 555-2134 |192.168.1.12|
|   Bob  | 555-4527 | 192.168.1.9|
FNr   )r   r)   Úheader_startÚ
data_start©Zcol1Zcol2Zcol3r   r,   r-   r.   r/   r0   r3   r	   r	   r
   Útest_read_no_header_autocolumn   s        ÿr=   c                  C   sh   d} t j| t jd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 |.r9   FNr   r*   )r   r)   r:   r;   r"   r   r,   r-   r.   r/   r0   r3   r	   r	   r
   Útest_read_no_header_names�   s    úr?   c                  C   s`   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 )r8   r9   r   r<   r   r   r,   r-   r.   r/   N©r   r   ÚFixedWidthNoHeaderr   r1   r2   r"   r3   r	   r	   r
   Ú'test_read_no_header_autocolumn_NoHeader¥   s    rB   c                  C   sb   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 )r>   r9   r*   r!   r   r   r,   r-   r.   r/   Nr@   r3   r	   r	   r
   Ú"test_read_no_header_names_NoHeader³   s      ÿrC   c                  C   sx   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ƒ 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
r*   )r   é	   é   )é   é   é   )r   r"   Ú
col_startsÚcol_endsr   r   ú	555- 1234r,   r.   z
192.168.1.z	192.168.1Nr@   r3   r	   r	   r
   Útest_read_col_startsÄ   s    ûrL   c                  C   s’   d} ddiddifD ]x}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ƒ q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
rI   )r   rD   é   rJ   )é   rE   é!   r*   r!   r   r   rK   r,   r.   z192.168.1.123r%   z192.255.255.255Nr@   )r   Úkwargsr   r	   r	   r
   Ú#test_read_detect_col_starts_or_endsÛ   s    	ÿýürQ   z‡| Col1 |  Col2     |  Col3     |  Col4     |
| 1.2  | "hello"   |  1        |  a        |
| 2.4  | 's worlds |         2 |         2 |
r   c                  C   s*   t ƒ } tjt| tjd� 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©Úoutr	   r	   r
   Útest_write_normalü   s    þrZ   c                  C   s,   t ƒ } tjt| tjdd� t|  ¡ dƒ dS )rR   )ÚazN/A)rT   Zfill_valueszi| Col1 |      Col2 | Col3 | Col4 |
|  1.2 |   "hello" |    1 |  N/A |
|  2.4 | 's worlds |    2 |    2 |
NrU   rX   r	   r	   r
   Útest_write_fill_values
  s    þr\   c                  C   s,   t ƒ } tjt| tjdd� t|  ¡ dƒ dS )ú5Write a table as a fixed width table with no padding.N©rT   Údelimiter_padzQ|Col1|     Col2|Col3|Col4|
| 1.2|  "hello"|   1|   a|
| 2.4|'s worlds|   2|   2|
rU   rX   r	   r	   r
   Útest_write_no_pad  s    þr`   c                  C   s,   t ƒ } tjt| tjdd� t|  ¡ dƒ dS )ú5Write a table as a fixed width table with no bookend.F©rT   Úbookendz]Col1 |      Col2 | Col3 | Col4
 1.2 |   "hello" |    1 |    a
 2.4 | 's worlds |    2 |    2
NrU   rX   r	   r	   r
   Útest_write_no_bookend&  s    þrd   c                  C   s.   t ƒ } tjt| tjddd� t|  ¡ dƒ dS )ú7Write a table as a fixed width table with no delimiter.FN©rT   rc   r6   zTCol1       Col2  Col3  Col4
 1.2    "hello"     1     a
 2.4  's worlds     2     2
rU   rX   r	   r	   r
   Útest_write_no_delimiter4  s    þrg   c                  C   s*   t ƒ } tjt| tjd� t|  ¡ dƒ dS )rR   rS   z8| 1.2 |   "hello" | 1 | a |
| 2.4 | 's worlds | 2 | 2 |
N©r   r   rV   r   rA   r   rW   rX   r	   r	   r
   Útest_write_noheader_normalB  s    þri   c                  C   s,   t ƒ } tjt| tjdd� t|  ¡ dƒ dS )r]   Nr^   z(|1.2|  "hello"|1|a|
|2.4|'s worlds|2|2|
rh   rX   r	   r	   r
   Útest_write_noheader_no_padO  s    þrj   c                  C   s,   t ƒ } tjt| tjdd� t|  ¡ dƒ dS )ra   Frb   z01.2 |   "hello" | 1 | a
2.4 | 's worlds | 2 | 2
Nrh   rX   r	   r	   r
   Útest_write_noheader_no_bookend\  s    þrk   c                  C   s.   t ƒ } tjt| tjddd� t|  ¡ dƒ dS )re   FNrf   z*1.2    "hello"  1  a
2.4  's worlds  2  2
rh   rX   r	   r	   r
   Ú test_write_noheader_no_delimiteri  s        ÿþrl   c                  C   s2   t ƒ } tjt| tjdddœd� t|  ¡ dƒ dS )re   z%-8.3fz%-15s©r   r   )rT   Úformatsz‡|     Col1 |            Col2 | Col3 | Col4 |
| 1.200    | "hello"         |    1 |    a |
| 2.400    | 's worlds       |    2 |    2 |
NrU   rX   r	   r	   r
   Útest_write_formatsx  s       ÿþro   c                  C   s\   d} t j| t jd�}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   rm   r   r   r   r   r   N©r   r   ÚFixedWidthTwoLiner   r2   r"   r   r3   r	   r	   r
   Útest_read_twoline_normalˆ  s    rr   c                  C   sb   d} t j| t jd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   r:   Úposition_lineÚdata_endrm   r   r   r   r   Nrp   r3   r	   r	   r
   Útest_read_twoline_ReST˜  s    ûrv   c               	   C   sf   d} t j| 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 )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%   rs   )r   r6   r:   rt   r;   ru   rm   r   r   r   Nrp   r3   r	   r	   r
   Útest_read_twoline_human¯  s    ù	rx   c               	   C   sD   d} t  t¡�}tj| tjddd� W 5 Q R X dt|jƒks@t‚dS )z¤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.
    zQ
| Col1 |   Col2   |
|------|==========|
|  1.2 | "hello"  |
|  2.4 | 's worlds|
ú|F©r   r6   r)   zDPosition line should only contain delimiters and one other characterN©	ÚpytestÚraisesr   r   r   rq   ÚstrÚvalueÚAssertionError©r   Úexcinfor	   r	   r
   Útest_read_twoline_failÉ  s    ÿÿrƒ   c               	   C   sD   d} t  t¡�}tj| tjddd� W 5 Q R X dt|jƒks@t‚dS )zÉ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.
    zQ
| Col1 |   Col2   |
|aaaaaa|aaaaaaaaaa|
|  1.2 | "hello"  |
|  2.4 | 's worlds|
ry   Frz   z(Characters in position line must be partNr{   r�   r	   r	   r
   Útest_read_twoline_wrong_markerÝ  s    r„   c                  C   s*   t ƒ } tjt| tjd� t|  ¡ dƒ dS )rR   rS   zdCol1      Col2 Col3 Col4
---- --------- ---- ----
 1.2   "hello"    1    a
 2.4 's worlds    2    2
N©r   r   rV   r   rq   r   rW   rX   r	   r	   r
   Útest_write_twoline_normalî  s    þr†   c                  C   s.   t ƒ } tjt| tjddd� t|  ¡ dƒ dS )r]   r5   ú=)rT   r_   Zposition_charz|Col1        Col2   Col3   Col4
====   =========   ====   ====
 1.2     "hello"      1      a
 2.4   's worlds      2      2
Nr…   rX   r	   r	   r
   Útest_write_twoline_no_padý  s        ÿþrˆ   c                  C   s.   t ƒ } tjt| tjddd� t|  ¡ dƒ dS )ra   Try   rf   zl|Col1|     Col2|Col3|Col4|
|----|---------|----|----|
| 1.2|  "hello"|   1|   a|
| 2.4|'s worlds|   2|   2|
Nr…   rX   r	   r	   r
   Útest_write_twoline_no_bookend  s    þr‰   c                  C   s„   d} dddg}t j| ddd|dd	�}|j|ks2t‚t |d dd
gk¡sLt‚t |d ddgk¡sft‚t |d ddgk¡s€t‚dS )z3Test fix in #8511 where data_start is being ignoredzAAA y z
1 2 3
4 5 6
7 8 9
r[   ÚbÚcr   r%   r5   Úfixed_width_no_header)r;   ru   r6   r"   Úformaté   r.   rF   é   N)r   r   r   r€   ÚnpÚall)Útblr"   r   r	   r	   r
   Ú!test_fixedwidthnoheader_splitting  s    
úr“   c                  C   sf   ddddddddg} d	d
dddg}t j| dd|d�}tƒ }t j||dd|d� | ¡  ¡ | ksbt‚d S )Nz&| 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 |r2   ÚnameÚunitr�   ÚdescriptionZfixed_widthry   )r�   r6   Úheader_rows©r   r   r   rV   rW   r   r€   ©r’   r—   r   rY   r	   r	   r
   Útest_fixed_width_header_rows4  s    ø
rš   c               	   C   sd   ddddddddd	g	} d
ddddg}t j| d|d�}tƒ }t j||d|d� | ¡  ¡ | ks`t‚d S )Nz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     6r2   r•   r�   r–   r”   Zfixed_width_two_line©r�   r—   r˜   r™   r	   r	   r
   Ú%test_fixed_width_two_line_header_rowsF  s    ÷r�   c               	   C   s6   dg} t jtdd�� tj| ddgd� W 5 Q R X d S )Nr›   z)unexpected keyword argument 'header_rows')ÚmatchrŒ   r•   rœ   )r|   r}   Ú	TypeErrorr   r   )r’   r	   r	   r
   Ú&test_fixed_width_no_header_header_rowsY  s    r    )4Úior   Únumpyr�   r|   Z
astropy.ior   Zastropy.io.ascii.corer   Úcommonr   r   r   r   r#   r&   r'   r(   r4   r7   r=   r?   rB   rC   rL   rQ   r   r   r   r   rZ   r\   r`   rd   rg   ri   rj   rk   rl   ro   rr   rv   rx   rƒ   r„   r†   rˆ   r‰   r“   rš   r�   r    r	   r	   r	   r
   Ú<module>   sV   