
    HR-e~<                        d 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m	Z	 ddl
mZmZmZmZmZ ddlmZmZmZ ddlmZmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZm Z m!Z! ddl"m#Z# ddl$m%Z% ej&        d             Z'ej&        d             Z(d Z)d Z*d Z+d Z,d Z-d Z.d Z/d Z0d Z1d Z2d Z3d Z4d Z5ej6        7                    dddg          d             Z8d  Z9d! Z:d" Z;d# Z<d$ Z=d% Z>d& Z?d' Z@ G d( d)          ZAdS )*z,
Test the conversion to/from astropy.table.
    N)reload_configset_temp_config)conf
from_table
is_votabletreevalidate)E25W39	VOWarning)parsewriteto)ColumnTable)simple_table)Unit)get_pkg_data_filenameget_pkg_data_fileobjget_pkg_data_path)AstropyDeprecationWarning)_NOT_OVERWRITING_MSG_MATCHc                 |    t          d          }|                     d|           |                     d|           dS )z
    Pytest fixture to run a test case with tilde-prefixed paths.

    In the tilde-path case, environment variables are temporarily
    modified so that '~' resolves to the data directory.
    dataHOMEUSERPROFILEN)r   setenv)monkeypatchpaths     Clib/python3.11/site-packages/astropy/io/votable/tests/table_test.pyhome_is_datar       sC     V$$Dvt$$$}d+++++    c                     |                      dt          |                     |                      dt          |                     dS )z
    Pytest fixture to run a test case with tilde-prefixed paths.

    In the tilde-path case, environment variables are temporarily
    modified so that '~' resolves to the temp directory.
    r   r   N)r   str)r   tmp_paths     r   home_is_tmpdirr%   +   sB     vs8}}---}c(mm44444r!   c                    t          j        d          5  t          t          d                    }d d d            n# 1 swxY w Y   |                                }|                                }|j        j        j        D ]7}t          j	        |j
        |         |j        j
        |         k              sJ 8t          j                            |          }|                                }ddddfddd	dfd
dddfddd	dfddddfdddifdddifdddifdddifdddifdddifddddfdddifddddfddddfddddfdddifdddifd dddfd!dd"dfd#ddifd$dddfd%ddifd&dd'dfd(ddifd)ddifd*dddfd+dd,dfg}t          |j        |          D ]Z\  }\  }}	|j        |k    sJ |j        |	d         k    sJ | d-|	d          d.|j                     d/|	v r|j        |	d/         k    sJ [t'          j        t*                    5  t-          |t/          | d0z                       d d d            d S # 1 swxY w Y   d S )1Nignoreoverdata/regression.xmlstring_testchar*)datatype	arraysizestring_test_210unicode_testunicodeCharfixed_unicode_teststring_array_test4unsignedByter.   shortintlongdoublefloatarrayz2*bitbitarray3x2bitvararraybitvararray2z3x2*floatComplexdoubleComplexdoubleComplexArraydoubleComplexArrayFixed2booleanbooleanArraynullsnulls_array2x2
precision1
precision2doublearray	bitarray216z
 expected z	 but get r/   zthrough_table.xml)nperrstater   r   get_first_tableto_tabler=   dtypenamesallmaskr   VOTableFiler   zipfieldsIDr.   r/   pytestwarnsr   r   r#   )
r$   votabletableastropy_tablenamevotable2tfield_typesfieldds
             r   
test_tableri   9   s   	(	#	#	# F F-.CDDEEF F F F F F F F F F F F F F F ##%%ENN$$M!' J Jvm(.%+2B42HHIIIIII**=99H  ""A 
V#>>?	vDAAB	m#FFG	MMMN	6DDE	*n56	:w'(	U#$	*f%&	J)*	:w'(	vD99:	U#$	%e<<=	U==>	e&AAB	*n56	:78	O#NNO	"s$S$ST	Z'(	e#>>?	:u%&	U??@	
H-.	
H-.	XC@@A	5t<<=9K>  +66 5 5yax4Na
m+++FFa
mFFenFF ,++!?an4444 
c		 ? ?#h)<<==>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?s!   ?AA!II	Ic                     t           j                            dd          }t          j        d          5  t          |          }t          j        |dd           d d d            d S # 1 swxY w Y   d S )N~zregression.xmlr'   r(   r`   
main_tableformattable_id)osr   joinrR   rS   r   r   read)r    r   r`   s      r   test_read_from_tilde_pathrs   s   s    7<<-..D	(	#	#	# B B++
4	LAAAAB B B B B B B B B B B B B B B B B Bs   'A**A.1A.c                 l   t          j        d          5  t          dd          5 }t          j        |dd          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          |          d	k    sJ |d
         j        J | dz  }t          j        t                    5  |
                    |dd           d d d            n# 1 swxY w Y   t          |d          5 }t          j        |dd          }d d d            n# 1 swxY w Y   t          |          d	k    sJ d S )Nr'   r(   r*   binaryencodingr`   rl   rm      r<   ztable_interface.xmlFOO)ro   rn   rb)rR   rS   r   r   rr   lenrn   r^   r_   r   writeopen)r$   fdre   fnt2s        r   !test_read_through_table_interfacer   |   sL   	(	#	#	# H H!"7(KKK 	Hr
2i,GGGA	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	HH H H H H H H H H H H H H H H
 q66Q;;;; W:$$$	)	)B 
c		 6 6	U95556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 
b$ >2Z9u===> > > > > > > > > > > > > > > r77a<<<<<<sX   A#A A#A	A#A	A##A'*A'0CCC0DDDc                  
   t          j        d          5  t          dd          5 } t          j        | dd          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          |          d	k    sJ d S )
Nr'   r(   r*   ru   rv   r`   
last_tablerm   r   )rR   rS   r   r   rr   r{   r~   re   s     r   "test_read_through_table_interface2r      s    	(	#	#	# H H!"7(KKK 	Hr
2i,GGGA	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	HH H H H H H H H H H H H H H H
 q66Q;;;;;;s4   A#A A#A	A#A	A##A'*A'c                      t          d          } t          j        | dd          }|d         j        t	          d          k    sJ d S )Nzdata/nonstandard_units.xmlr`   generic)rn   unit_formatFlux1zerg / (Angstrom cm2 s))r   r   rr   unitr   )filenamere   s     r   (test_pass_kwargs_through_table_interfacer      sL    $%ABBH
8I9EEEAW:?d#;<<<<<<<<r!   c                      t          dd          5 } t          |           }d d d            n# 1 swxY w Y   |                                                    d          }|j        g dk    sJ d S )Ndata/names.xmlru   rv   Tuse_names_over_ids)NameGLONGLATRAdegDEdegJmagHmagKmagzG3.6magzG4.5magzG5.8magzG8.0magz4.5magz8.0magEmag24magf_Namer   r   rT   rU   colnamesr~   r`   ra   s      r   test_names_over_idsr      s    	.	B	B	B b))               ##%%..$.GGE>            .22c                      t          dd          5 } t          |           }d d d            n# 1 swxY w Y   |                                                    d          }|j        g dk    sJ d S )Nr   ru   rv   Fr   )col1col2col3col4col5col6col7col8col9col10col11col12col13col14col15col16col17r   r   s      r   test_explicit_idsr      s    	.	B	B	B b))               ##%%..%.HHE>         r   c                      t          dd          5 } t          j        | d          }ddd           n# 1 swxY w Y   t          |          dk    sJ dS )z
    Issue #927.
    r   ru   rv   r`   rn   N   )r   r   rr   r{   r   s     r   #test_table_read_with_unnamed_tablesr      s     
.	B	B	B -bJr),,,- - - - - - - - - - - - - - - q66Q;;;;;;s   599c                     t          j        t          d                    } t          |                                                                           }t          |          dk    sJ t          |d         d                   dk    sJ dS )zF
    Testing when votable is passed as pathlib.Path object #4412.
    r   r   r      i
  N)pathlibPathr   r   rT   rU   r{   r9   )fpathra   s     r   test_votable_path_objectr      sz     L./?@@AAE%LL((**3355Eu::????uQx{s""""""r!   c                      t                      } t          g dd          }|                     |           t          j                    }|                     |d           d S )Nr      r   ar   rc   r`   r   )r   r   
add_columnioBytesIOr|   )re   coutputs      r   test_from_table_without_maskr      sW    AIIIC(((ALLOOOZ\\FGGF9G%%%%%r!   c                     t                      } t          g dd          }|                     |           t          j                    }|                     |dd           |                                }d|v sJ d|v sJ d	|vsJ t          j                    }|                     |dd
           |                                }d|v sJ d|v sJ d	|vsJ d S )Nr   r   r   r`   ru   rn   tabledata_formats   VOTABLE version="1.4"s   BINARYs	   TABLEDATAbinary2s   BINARY2)r   r   r   r   r   r|   getvalue)re   r   r   obuffs       r   test_write_with_formatr      s    AIIIC(((ALLOOOZ\\FGGF9xG@@@OOE#u,,,,u$$$$Z\\FGGF9yGAAAOOE#u,,,,u$$$$$$r!   c                 ,   t          dd          }| dz  }|                    |d           t          j        t          t
                    5  |                    |d           d d d            n# 1 swxY w Y   |                    |dd           d S )Nr   zoverwrite_test.votr`   r   )matchT)rn   	overwrite)r   r|   r^   raisesOSErrorr   )r$   re   r   s      r   test_write_overwriter   
  s    QA..HGGHYG'''	w&@	A	A	A , ,	+++, , , , , , , , , , , , , , ,GGHY$G77777s   A11A58A5c                    t           j                            dd          }t                      }g d|d<   |                    |dd           t           j                            |          rJ t          t           j                            |                    5 }|                                }d d d            n# 1 swxY w Y   d|v sJ d	|v sJ d
|vsJ d S )Nrk   r   r   r   r`   ru   r   VOTABLE version="1.4"BINARY	TABLEDATA)	rp   r   rq   r   r|   existsr}   
expanduserrr   )r%   fnamere   fr   s        r   test_write_tilde_pathr     s   GLLh''EAYYAcFGGE)hG??? w~~e$$$$$	bg  ''	(	( A              "e++++ue######s   B<<C C path_formatplaintildec                    | dk    rt          |dz            }n t          j                            dd          }t	                      }g d|d<   t          |          }t          ||           | dk    r!t          j                            |          rJ t          t          j        	                    |                    5 }|
                                }d d d            n# 1 swxY w Y   d|v sJ d|vsJ d	|v sJ d S )
Nr   zwriteto_test.votrk   r   r   r   r   r   r   )r#   rp   r   rq   r   r   r   r   r}   r   rr   )r   r$   r%   r   re   vtr   r   s           r   test_writetor   $  sF   g H1122S"455AYYAcF	ABBg7>>%(((((	bg  ''	(	( A              "e++++5    %s   C""C&)C&c                      t          t          d                    } |                                 }|                                 d S )Nzdata/empty_table.xml)r   r   rT   rU   r`   ra   s     r   test_empty_tabler   =  s@    )*@AABBG##%%E	NNr!   c                      t          t          d                    } |                                 }t          |j                  dk    sJ t          |j                  dk    sJ d S )N!data/no_field_not_empty_table.xmlr   r   )r   r   rT   r{   r\   infosr   s     r   test_no_field_not_empty_tabler   C  sf    )*MNNOOG##%%Eu|!!!!u{q      r!   c                      t          j        t                    5  t          t	          d          d           d d d            d S # 1 swxY w Y   d S )Nr   	exceptionverify)r^   r   r
   r   r    r!   r   'test_no_field_not_empty_table_exceptionr   J  s    	s		 
 
!"EFF	
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
   AA
A
c                  .   t          t          d                    } |                                 }|                                }t	          j        |j        j        d                   rJ t          j	                    }|
                    |d           dS )z
    Issue #8995.
    zdata/binary2_masked_strings.xmlepoch_photometry_urlr`   r   N)r   r   rT   rU   rR   anyr=   rY   r   r   r|   )r`   ra   rb   r   s       r   test_binary2_masked_stringsr   R  s    
 )*KLLMMG##%%ENN$$M vek&'=>?????Z\\Fy11111r!   c                      t          d          } t          | d          }t          |t                    sJ d|v sJ t          |           }t          |t                    sJ |du sJ dS )zn
    Issue #12603. Test that we get the correct output from votable.validate with an invalid
    votable.
    r*   Nr   z+E02: Incorrect number of elements in array.Fr   r	   
isinstancer#   bool)invalid_votable_filepathvalidate_outs     r   test_validate_output_invalidr   a  s      55JKK 4TBBBLlC(((((8LHHHH 455LlD)))))5      r!   c                      t          d          } t          | d          }t          |t                    sJ d|v sJ t          |           }t          |t                    sJ |du sJ dS )zk
    Issue #12603. Test that we get the correct output from votable.validate with a valid
    votable.
    zdata/valid_votable.xmlNr   z&astropy.io.votable found no violationsTr   )valid_votable_filepathr   s     r   test_validate_output_validr  v  s     33KLL 24@@@LlC(((((3|CCCC 233LlD)))))4r!   c                 `    t          t          j                            dd                     d S Nrk   zvalid_votable.xml)r	   rp   r   rq   r    s    r   test_validate_tilde_pathr    s'    RW\\#23344444r!   c                 d    t          t          j                            dd                    sJ d S r  )r   rp   r   rq   r  s    r   test_is_votable_tilde_pathr    s-    bgll3(;<<=======r!   c                   P    e 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S )TestVerifyOptionsc                 >    t          t          d                     d S )Ndata/gemini.xmlr   r   selfs    r   test_defaultzTestVerifyOptions.test_default  s     #$56677777r!   c                 B    t          t          d          d           d S )Nr  r'   r   r  r  s    r   test_verify_ignorez$TestVerifyOptions.test_verify_ignore  s%    #$566xHHHHHHr!   c                     t          j        t                    5 }t          t	          d          d           d d d            n# 1 swxY w Y   t          |          dk    sJ d S )Nr  warnr      r^   r_   r   r   r   r{   r  ws     r   test_verify_warnz"TestVerifyOptions.test_verify_warn  s    \)$$ 	K'(9::6JJJJ	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K1vv||||||   AA	A	c                     t          j        t                    5  t          t	          d          d           d d d            d S # 1 swxY w Y   d S )Nr  r   r   )r^   r   r   r   r   r  s    r   test_verify_exceptionz'TestVerifyOptions.test_verify_exception  s    ]9%% 	P 	P'(9::;OOOO	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	Pr   c                     t          j        t                    5 }t          t	          d          d           d d d            n# 1 swxY w Y   t          |          dk    sJ d S )Nr  Fpedantic   r  r  s     r   test_pedantic_falsez%TestVerifyOptions.test_pedantic_false  s    \)$$ 	L'(9::UKKKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L1vv||||||r  c                    t          j        t                    5  t          j        t                    5  t          t          d          d           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr  Tr  )r^   r_   r   r   r   r   r   r  s    r   test_pedantic_truez$TestVerifyOptions.test_pedantic_true  s   \344 	O 	Oy)) O O+,=>>NNNNO O O O O O O O O O O O O O O	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	Os4   A7AA7A#	#A7&A#	'A77A;>A;c                     t          j        dd          5  t          t          d                     d d d            d S # 1 swxY w Y   d S )Nr   r'   r  )r   set_tempr   r   r  s    r   test_conf_verify_ignorez)TestVerifyOptions.test_conf_verify_ignore  s    ]8X.. 	< 	<'(9::;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   A  AAc                 (   t          j        dd          5  t          j        t                    5 }t          t          d                     d d d            n# 1 swxY w Y   t          |          dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nr   r  r  r  )r   r$  r^   r_   r   r   r   r{   r  s     r   test_conf_verify_warnz'TestVerifyOptions.test_conf_verify_warn  s   ]8V,, 	  	 i(( @A+,=>>???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @q66R<<<<<	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s4   BABA	B A	!BBBc                     t          j        dd          5  t          j        t                    5  t          t          d                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   r   r  )r   r$  r^   r   r   r   r   r  s    r   test_conf_verify_exceptionz,TestVerifyOptions.test_conf_verify_exception  s   ]8[11 	@ 	@y)) @ @+,=>>???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s4   A1AA1A	A1 A	!A11A58A5c                    t          |          5  t          |dz  dz  d          5 }|                    d           d d d            n# 1 swxY w Y   t          d           t	          j        t                    5 }t          t          d                     d d d            n# 1 swxY w Y   t          |          dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nastropyastropy.cfgr  z[io.votable]
pedantic = Falseastropy.io.votabler  r  )
r   r}   r|   r   r^   r_   r   r   r   r{   )r  r$   r   r  s       r   test_conf_pedantic_falsez*TestVerifyOptions.test_conf_pedantic_false  s   X&& 	  	 h*]:C@@ :A8999: : : : : : : : : : : : : : : .///i(( @A+,=>>???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @q66R<<<<<	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 sW   CA	C	A	CA	+C<B%C%B)	)C,B)	-CCCc                    t          |          5  t          |dz  dz  d          5 }|                    d           d d d            n# 1 swxY w Y   t          d           t	          j        t                    5  t	          j        t                    5  t          t          d                     d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr+  r,  r  z[io.votable]
pedantic = Truer-  r  )r   r}   r|   r   r^   r_   r   r   r   r   r   )r  r$   r   s      r   test_conf_pedantic_truez)TestVerifyOptions.test_conf_pedantic_true  s   X&& 	D 	Dh*]:C@@ 9A78889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 .///788 D D]9-- D D/0ABBCCCD D D D D D D D D D D D D D DD D D D D D D D D D D D D D D	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds{   C.A	C.	A	C.A	+C.<CB?3C?CCCC
C.C	C.C	C..C25C2N)__name__
__module____qualname__r  r  r  r  r   r"  r%  r'  r)  r.  r0  r   r!   r   r	  r	    s        8 8 8
I I I  
P P P  
O O O< < <     @ @ @	  	  	 	D 	D 	D 	D 	Dr!   r	  )B__doc__r   rp   r   numpyrR   r^   astropy.configr   r   astropy.io.votabler   r   r   r   r	   astropy.io.votable.exceptionsr
   r   r   astropy.io.votable.tabler   r   astropy.tabler   r   astropy.table.table_helpersr   astropy.unitsr   astropy.utils.datar   r   r   astropy.utils.exceptionsr   astropy.utils.miscr   fixturer    r%   ri   rs   r   r   r   r   r   r   r   r   r   r   r   markparametrizer   r   r   r   r   r   r  r  r  r	  r   r!   r   <module>rC     s?    
			 				       9 9 9 9 9 9 9 9 K K K K K K K K K K K K K K = = = = = = = = = = 3 3 3 3 3 3 3 3 ' ' ' ' ' ' ' ' 4 4 4 4 4 4               
 ? > > > > > 9 9 9 9 9 9 , , , 
5 
5 
57? 7? 7?tB B B  .  = = =  6  6  # # #& & &% % %(8 8 8$ $ $" '(:;;    <; 0  ! ! !
 
 
2 2 2! ! !*     ,5 5 5> > >GD GD GD GD GD GD GD GD GD GDr!   