
    HR-e'                         d dl 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mZmZ d dlmZ d dlmZ ddlmZmZ  G d	 d
e          Z G d dee          ZdS )    N)_FORMAT_TABLEread_html_tablewrite_html_table)	Parameter)QTableTablevstack)NoneType)HAS_BS4   )ReadWriteDirectTestBaseReadWriteTestMixinBasec                      e Zd ZdZej                            e d          d             Zej                            e d          d             Z	ej        
                    deeg          ej                            e d          d                         Zej                            e d          d             Zej                            e d          d	             Zej                            e d          ej        
                    d
ddg          d                         Zej                            e d          d             ZdS )ReadWriteHTMLTestMixina  
    Tests for a Cosmology[Read/Write] with ``format="ascii.html"``.
    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 dfine a :func:`pytest.fixture`
    ``cosmo`` that returns/yields an instance of a |Cosmology|.
    See ``TestCosmology`` for an example.
    requires beautifulsoup4reasonc                 0   |dz  } ||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 incorrectz!test_to_html_table_bad_index.html
ascii.htmlformatzindex 2 out of rangematch   indexr   NzNo matches found for keyrow 0)pytestraises
IndexErrorKeyError)selfreadwritetmp_pathfps        Dlib/python3.11/site-packages/astropy/cosmology/io/tests/test_html.pytest_to_html_table_bad_indexz3ReadWriteHTMLTestMixin.test_to_html_table_bad_index   s;    ;;b&&&& ]:-CDDD 	3 	3D1\2222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 ]8+EFFF 	9 	9D7<8888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9s#   A		AA/BBBc                     |dz  }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"test_to_html_table_failed_cls.htmlz'cls' must ber   r   r   clsN)r   r   	TypeErrorlist)r"   r$   r%   r&   s       r'   test_to_html_table_failed_clsz4ReadWriteHTMLTestMixin.test_to_html_table_failed_cls-   s     <<]9O<<< 	5 	5E"\t4444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s   AA	Atbl_clsc                 ,    |dz  } ||d|           d S )Nztest_to_html_table_cls.htmlr   r*    )r"   r$   r/   r%   r&   s        r'   test_to_html_table_clsz-ReadWriteHTMLTestMixin.test_to_html_table_cls5   s,     55b7333333    c                    |dz  } ||d           t          j        |          }|d         |j        k    sJ d|d<   |                    |dd           t	          |j        j                                                  d	         j        d
k    r, ||d          }	|	j	        |u sJ |	j        |j        k    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 |                    d           |                    |dd            ||d          }	|	|k    sJ  ||d          }	|	|k    sJ  ||          }	|	|k    sJ dS )z*Test cosmology -> ascii.html -> cosmology.z'test_readwrite_html_table_instance.htmlr   r   namez
will errormismatchingT)r   	overwrite   Nzthere are unused parametersr   )r   move_to_meta)r   r#   r5   r$   tuple_init_signature
parametersvalueskind	__class__r   r   r,   remove_column)
r"   	cosmo_clscosmor#   r$   r%   add_cur&   tblgots
             r'   "test_readwrite_html_table_instancez9ReadWriteHTMLTestMixin.test_readwrite_html_table_instance=   s   
 AA
 	b&&&& k"oo6{ej((((
 *M		"\T	::: &188::;;B?DII$r,///C=I----8uz)))) F ]9,IJJJ 	* 	*DL))))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* d2l>>>e|||| 	-(((		"\T	:::d2l+++e|||| d2l+++e||||d2hhe||||||s   C22C69C6c                 <   |dz  } ||dd           t          j        |          }|j        dd         D ]}|t          j                    v sJ  ||d          }|                    d          }|j        d	d         D ]}|t          j                    v sJ dS 
zTests renaming columnsz#test_rename_html_table_columns.htmlr   Tr   latex_namesr   Nr   astropy.tabler   r   r#   colnamesr   r>   	to_formatkeys	r"   r#   r$   r%   r&   rE   column_namerC   converted_tbls	            r'   test_rename_html_table_columnsz5ReadWriteHTMLTestMixin.test_rename_html_table_columnsw   s     ==b48888k"oo <+ 	9 	9K-"6"8"888888R---88 )1!""5 	7 	7K-"4"6"666666	7 	7r3   rK   TFc                    |dz  } ||d|           t          j        |          }	|rdn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 dS )zy
        Test writing from an instance and reading from that class.
        This works with missing information.
        z)test_read_html_subclass_partial_info.htmlr   rJ   z	$$T_{0}$$Tcmb0T)r7   r   )r   	cosmology)r5   rV   m_nuN)r   r#   r$   __qualname__rV   r<   r=   defaultcloner5   rX   )r"   rB   rC   r#   r$   rK   r%   rD   r&   rE   cnamerF   got2got3s                 r'   )test_readwrite_html_subclass_partial_infoz@ReadWriteHTMLTestMixin.test_readwrite_html_subclass_partial_info   s    CC 	b;???? k"oo  +7J		"	%%% nnRn55tB|yAAAtB|y7MNNNt$$,,,, e||||yI5@IQQQQQyyej%*yMMQVVVVVVVr3   c                    |dz  }|                     d          }|                     d          }t          d |||fD             d          }	t          |          }
|
t          k    rJ t	          |	j        |	                                          D ]l\  }}|d	k    rt          |
|          }t          |t                    r|j
        d
t          j        fv rG|	                    |||j
        z  j        d           m|	                    |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 |	                    d           |
                    ||j        d          }||k    sJ d
S )z Test if table has multiple rows.z!test_readwrite_html_mutlirow.htmlr   )r5   zrow 2c                 8    g | ]}|                     d           S )rL   )rO   ).0cs     r'   
<listcomp>zGReadWriteHTMLTestMixin.test_readwrite_html_mutlirow.<locals>.<listcomp>   s$    KKKaQ[[))KKKr3   silent)metadata_conflictsFrW   N)copyr   r   zneed to select a specific rowr   r   r   r5   )r[   r	   typer
   ziprN   itercolsgetattr
isinstancer   unituonereplace_columnvaluer$   r   r   
ValueErrorr#   r5   	add_index)r"   rC   r#   r$   r%   rD   r&   cosmo1cosmo2tablerB   ncolparamrF   r]   s                   r'   test_readwrite_html_mutlirowz3ReadWriteHTMLTestMixin.test_readwrite_html_mutlirow   s>    ;; '**'**KKFE63JKKK'
 
 

 KK	  L%.%..*:*:;; 	K 	KFAsKIq))EeY// 5:$3N3N  SEJ%6$=E JJJJB|,,, ]:-LMMM 	* 	*DL))))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* nnRqn>>e|||| nnRuz,nGGe|||| 	~~b
<~HHu}}}}}}s   2EEEN)__name__
__module__rY   __doc__r   markskipifr   r(   r.   parametrizer   r   r2   rG   rT   r_   rz   r1   r3   r'   r   r      s         [G,EFF9 9 GF9  [G,EFF5 5 GF5 [Y88[G,EFF4 4 GF 984 [G,EFF7 7 GF7r [G,EFF7 7 GF7* [G,EFF[]T5M::W W ;: GFWF [G,EFF/ / GF/ / /r3   r   c                   d    e Zd ZdZd Zej                            e d          d             Z	dS )TestReadWriteHTMLz
    Directly test ``read/write_html``.
    These are not public API and are discouraged from use, in favor of
    ``Cosmology.read/write(..., format="ascii.html")``, but should be
    tested regardless b/c they are used internally.
    c                 .    t           t          d| _        d S )N)r#   r$   )r   r   	functions)r"   s    r'   setup_classzTestReadWriteHTML.setup_class   s    "1<LMMr3   r   r   c                 <   |dz  } ||dd           t          j        |          }|j        dd         D ]}|t          j                    v sJ  ||d          }|                    d          }|j        d	d         D ]}|t          j                    v sJ dS rI   rM   rQ   s	            r'   %test_rename_direct_html_table_columnsz7TestReadWriteHTML.test_rename_direct_html_table_columns   s     ==b48888k"oo <+ 	9 	9K-"6"8"888888R---88 )1!""5 	7 	7K-"4"6"666666	7 	7r3   N)
r{   r|   rY   r}   r   r   r~   r   r   r   r1   r3   r'   r   r      se         N N N [G,EFF7 7 GF7 7 7r3   r   )r   astropy.unitsunitsrn   astropy.cosmology.io.htmlr   r   r   astropy.cosmology.parameterr   astropy.tabler   r   r	   astropy.units.decoratorsr
   "astropy.utils.compat.optional_depsr   baser   r   r   r   r1   r3   r'   <module>r      s          V V V V V V V V V V 1 1 1 1 1 1 / / / / / / / / / / - - - - - - 6 6 6 6 6 6 A A A A A A A A
P P P P P3 P P Pf 7  7  7  7  7/1G  7  7  7  7  7r3   