
    HR-e!                         d dl Z d dlmZ d dlmZ d dlmZmZ d dlm	Z	m
Z
mZ ddlmZmZ  G d d	e          Z G d
 dee          ZdS )    N)	Cosmology)_COSMOLOGY_CLASSES)
from_tableto_table)QTableTablevstack   )ToFromDirectTestBaseToFromTestMixinBasec                   f   e Zd ZdZd Zd Zej                            de	e
g          d             Zej                            dddg          d	             Zd
 Zd Zd Zd Zej                            dddg          d             Zej                            dg d          d             ZdS )ToFromTableTestMixina  
    Tests for a Cosmology[To/From]Format with ``format="astropy.table"``.
    This class will not be directly called by :mod:`pytest` since its name does
    not begin with ``Test``. To activate the contained tests this class must
    be inherited in a subclass. Subclasses must define a :func:`pytest.fixture`
    ``cosmo`` that returns/yields an instance of a |Cosmology|.
    See ``TestCosmology`` for an example.
    c                 "    |d          }t          j        t          d          5   ||dd           ddd           n# 1 swxY w Y   t          j        t          d          5   ||dd           ddd           dS # 1 swxY w Y   dS )	z'Test if argument ``index`` is incorrectastropy.tablezindex 2 out of rangematch   indexformatNzNo matches found for keyrow 0)pytestraises
IndexErrorKeyError)selffrom_format	to_formattbls       Elib/python3.11/site-packages/astropy/cosmology/io/tests/test_table.pytest_to_table_bad_indexz,ToFromTableTestMixin.test_to_table_bad_index   s<   i(( ]:-CDDD 	> 	>K1_====	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> ]8+EFFF 	D 	DK7?CCCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds#   AA	A(BBBc                     t          j        t          d          5   |dt                     ddd           dS # 1 swxY w Y   dS )zTest failed table type.z'cls' must ber   r   clsN)r   r   	TypeErrorlist)r   r   s     r    test_to_table_failed_clsz-ToFromTableTestMixin.test_to_table_failed_cls)   s    ]9O<<< 	1 	1Io40000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s   <A A tbl_clsc                 D     |d|          }t          ||          sJ d S )Nr   r#   )
isinstance)r   r   r(   r   s       r    test_to_table_clsz&ToFromTableTestMixin.test_to_table_cls.   s2    iW555#w'''''''    in_metaTFc                      |d|          }|r%|j         d         |j        k    sJ d|j        vsJ dS |d         d         |j        k    sJ d|j         vsJ dS )z)Test where the cosmology class is placed.r   )cosmology_in_meta	cosmologyr   N)meta__qualname__colnames)r   	cosmo_clsr   r-   r   s        r    test_to_table_in_metaz*ToFromTableTestMixin.test_to_table_in_meta5   s     i7CCC  	/8K(I,BBBBBcl222222{#A&)*@@@@@ch......r,   c                     |d          }t          |t                    sJ |j        d         |j        k    sJ |d         |j        k    sJ |j        sJ |j        D ]t}t          ||          }||         }|j        j        |j        k    sJ |j        j	        |j
        k    sJ |j        j        |j                            |          pi k    sJ udS )z Test cosmology -> astropy.table.r   r0   nameN)r*   r   r1   r2   r7   indices__parameters__getattrinfodescription__doc__get)r   r4   cosmor   r   nPcols           r    test_to_tablez"ToFromTableTestMixin.test_to_tableD   s    i(( #v&&&&&x$	(>>>>>6{ej(((({ % 	> 	>A	1%%Aa&C 8=AF****8'1944448=UZ^^A%6%6%<"=====	> 	>r,   c                     t          j        t          t          f          5   |dd           ddd           dS # 1 swxY w Y   dS )z-Test not passing a Table to the Table parser.zNOT A TABLEr   r   N)r   r   r%   
ValueError)r   r?   r   s      r    test_from_not_tablez(ToFromTableTestMixin.test_from_not_tableZ   s    ]Iz233 	? 	?Ko>>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s   <A A c                     |d          }d|d<   t          |j        j                                                  d         j        dk    r7 ||d          }|j        |u sJ |j        |j        k    sJ d|j        vsJ dS t          j	        t          d	          5   ||d           ddd           n# 1 swxY w Y    ||dd
          }||k    sJ |j        d         dk    sJ |                    d            ||d          }||k    sJ t          |j        d                  |j        d<    ||d          }||k    sJ  ||          }||k    sJ dS )z-Test cosmology -> astropy.table -> cosmology.r   z
will errormismatching   rE   Nzthere are unused parametersr   T)r   move_to_metar0   )tuple_init_signature
parametersvalueskind	__class__r7   r1   r   r   r%   remove_columnr   )r   r4   r?   r   r   r   gots          r    test_tofrom_table_instancez/ToFromTableTestMixin.test_tofrom_table_instance_   s   i(( *M &188::;;B?DII+c/:::C=I----8uz)))) 0000F ]9,IJJJ 	5 	5KO4444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 k#oDIIIe||||x&,6666 	-(((k#o666e|||| !338K3H Ik#o666e|||| k#e||||||s   B77B;>B;c                     |d          }t          |t                    sJ |j                            dd           |d= |                    |d          } ||d|          } ||d|j                  }||k    r||k    sJ ||k    sJ |j        |j        j        d         j	        k    sJ |
                    |j        |j        |j                  |k    sJ |j        |j        k    sJ dS )zy
        Test writing from an instance and reading from that class.
        This works with missing information.
        r   r0   NTcmb0rE   )r   r0   )r7   rW   m_nu)r*   r   r1   popr   r2   rW   rN   rO   defaultcloner7   rX   )	r   r4   r?   r   r   r   rT   got2got3s	            r    +test_fromformat_table_subclass_partial_infoz@ToFromTableTestMixin.test_fromformat_table_subclass_partial_info   s$    i((#v&&&&& 	[$'''L ##C#@@{3)LLL{93I
 
 
 t$$,,,, e||||yI5@IQQQQQyyej%*yMMQVVVVVx5:%%%%%%r,   	add_indexc                    |                     d          }|                     d          }t          d |||fD             d          }t          |t                    sJ |j        d         |j        k    sJ |d         d	         |j        k    sJ |r|                    d	d
           t          j	        t          d          5   ||d           ddd           n# 1 swxY w Y    ||dd          }||k    sJ  |||j        d          }||k    sJ t          ||gd          }	t          j	        t          d          5   ||	|j        d           ddd           dS # 1 swxY w Y   dS )z Test if table has multiple rows.r   )r7   zrow 2c                 8    g | ]}|                     d           S )r   )r   ).0cs     r    
<listcomp>zCToFromTableTestMixin.test_tofrom_table_mutlirow.<locals>.<listcomp>   s$    KKKaQ[[))KKKr,   silent)metadata_conflictsr0   r
   r7   T)uniquezneed to select a specific rowr   r   rE   Nr   zmore than one)r[   r	   r*   r   r1   r2   r7   r_   r   r   rF   )
r   r4   r?   r   r_   cosmo1cosmo2r   rT   tblss
             r    test_tofrom_table_mutlirowz/ToFromTableTestMixin.test_tofrom_table_mutlirow   sS    '**'**KKFE63JKKK'
 
 

 #v&&&&&x$	(>>>>>1vf~++++  	/MM&M... ]:-LMMM 	5 	5KO4444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 k#Q???e|||| k#UZHHHe|||| sCjX>>>]:_=== 	H 	HKEJGGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hs$   C!!C%(C%E,,E03E0r   )TFNr   c                      |d          }t          |t                    rJ |                    ||          }||duu sJ dS )zTest :meth:`astropy.cosmology.Cosmology.is_equivalent`.

        This test checks that Cosmology equivalency can be extended to any
        Python object that can be converted to a Cosmology -- in this case
        a |Table|.
        r   rE   FN)r*   r   is_equivalent)r   r?   r   r   objis_equivs         r    test_is_equivalent_to_tablez0ToFromTableTestMixin.test_is_equivalent_to_table   s]     i((c9-----&&s6&::F%/000000r,   N)__name__
__module__r2   r=   r!   r'   r   markparametrizer   r   r+   r5   rC   rG   rU   r^   rk   rp    r,   r    r   r      sM        
D 
D 
D1 1 1
 [Y88( ( 98( [Yu66
/ 
/ 76
/> > >,? ? ?
' ' 'R& & &@ [[4-88&H &H 98&HP [X'K'K'KLL1 1 ML1 1 1r,   r   c                       e Zd ZdZd ZdS )TestToFromTablez Directly test ``to/from_table``.c                 .    t           t          d| _        d S )N)tofrom)r   r   	functions)r   s    r    setup_classzTestToFromTable.setup_class   s     (*==r,   N)rq   rr   r2   r=   r|   ru   r,   r    rw   rw      s)        **> > > > >r,   rw   )r   astropy.cosmologyr   astropy.cosmology.corer   astropy.cosmology.io.tabler   r   astropy.tabler   r   r	   baser   r   r   rw   ru   r,   r    <module>r      s     ( ' ' ' ' ' 5 5 5 5 5 5 ; ; ; ; ; ; ; ; / / / / / / / / / / ; ; ; ; ; ; ; ;
L1 L1 L1 L1 L1. L1 L1 L1^> > > > >*,@ > > > > >r,   