
    HR-e                         d dl Z d dlZd dlZ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 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)	Cosmology)_CosmologyModel
from_modelto_model)get_redshift_methods)
Gaussian1D)	HAS_SCIPY   )ToFromDirectTestBaseToFromTestMixinBasec                       e Zd ZdZ ej        d          d             Zd Zd Zd Z	d Z
d	 Zd
 Zej                            dg d          d             ZdS )ToFromModelTestMixina  Tests for a Cosmology[To/From]Format with ``format="astropy.model"``.

    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 ``TestCosmologyToFromFormat`` or ``TestCosmology`` for examples.
    class)scopec                    t          |dd          }t          |          D ]}t          j        t	          ||                    j                                        }t          t          f}t          s|t          fz   }t          j        t          |                    dz   }	  t	          ||          |  # |$ r |                    |           Y w xY w|r!t          j        t          |                    nd S )NFT)include_private
include_z2r
   )r   tupleinspect	signaturegetattr
parameterskeysNotImplementedError
ValueErrorr	   ModuleNotFoundErrornparangelendiscardrandomchoice)selfcosmomethodsnparamsERROR_SEIVEargss          Elib/python3.11/site-packages/astropy/cosmology/io/tests/test_model.pymethod_namez ToFromModelTestMixin.method_name!   s    'uePTUUU w 	# 	#A&wua'8'899DIIKKF.
;K C)-@,BB9S[[))A-D#!q!!4((( # # #"""""# 18Av}U7^^,,,TAs   "B66CCc                     t          dd          }t          j        t                    5   ||           ddd           dS # 1 swxY w Y   dS )z)Test when Model is not the correct class.
      )	amplitudemeanN)r   pytestraisesAttributeError)r#   from_formatmodels      r*   test_fromformat_model_wrong_clsz4ToFromModelTestMixin.test_fromformat_model_wrong_cls<   s    Rb111]>** 	 	K	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                     t          j        t                    5   |dd           ddd           dS # 1 swxY w Y   dS )z!Test when method is not a method.astropy.modelz this is definitely not a method.methodN)r1   r2   r3   r#   	to_formats     r*   test_toformat_model_not_methodz3ToFromModelTestMixin.test_toformat_model_not_methodC   s    ]>** 	R 	RIo.PQQQQ	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R 	R   599c                     t          j        t                    5   |dd           ddd           dS # 1 swxY w Y   dS )z*Test when method is actually an attribute.r8   namer9   N)r1   r2   r   r;   s     r*    test_toformat_model_not_callablez5ToFromModelTestMixin.test_toformat_model_not_callableH   s    ]:&& 	6 	6Iof5555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6r>   c                 0   |dS  |d|          }t          |t                    sJ t          fdj        D                       }|j        |k    sJ t          j        |j                  dz   } |j        | } t          |          | }t          j
        ||k              sJ  || } t          |          | }t
          j                            ||           d|vrt          j        |j        df          j        t          j        |j                  z   j        } |j        | } t          |          | }t          j
        ||k              sJ  || } t          |          | }t
          j                            ||           dS dS )z Test cosmology -> astropy.model.Nr8   r9   c              3   <   K   | ]}t          |          |V  d S )N)r   ).0r&   r$   s     r*   	<genexpr>z;ToFromModelTestMixin.test_toformat_model.<locals>.<genexpr>V   s2      XXQ'%:K:K:Wq:W:W:W:WXX    r
   scalar   )
isinstancer   r   __parameters__param_namesr   r   n_inputsevaluater   alltestingassert_allcloseonesT)	r#   r$   r<   r+   r5   expectr)   gotexpecteds	    `       r*   test_toformat_modelz(ToFromModelTestMixin.test_toformat_modelM   s   F	/+>>>%11111 XXXX%"6XXXXX F**** y((1,end#.75+..5vcXo&&&&&eTl.75+..5

""3111 ;&&GU^Q/002RYu~5N5NNQD %.$'C2wuk22D9H6#/*****%,C2wuk22D9HJ&&sH55555 '&rF   c                 8   |dS  |d|          }t          |t                    sJ |j        |u sJ |j        |k    sJ |j        |k    sJ  ||d          }||k    sJ t          |j                                                                      |j                                                  sJ  ||          }||k    sJ t          |j                                                                      |j                                                  sJ dS )z-Test cosmology -> astropy.model -> cosmology.Nr8   r9   format)	rI   r   cosmology_class	cosmologyr+   setmetar   issubset)r#   	cosmo_clsr$   r+   r<   r4   r5   rT   s           r*    test_tofromformat_model_instancez5ToFromModelTestMixin.test_tofromformat_model_instancep   s-    F 	/+>>>%11111$	1111%'''' K//// k%888e||||5:??$$%%..sx}}????? k%  e||||5:??$$%%..sx}}???????rF   c                     dS )zy
        Test writing from an instance and reading from that class.
        This works with missing information.
        N r#   s    r*   +test_fromformat_model_subclass_partial_infoz@ToFromModelTestMixin.test_fromformat_model_subclass_partial_info   s	    
 	rF   rY   )TFNr8   c                     |dS  |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 model.
        Nr8   r9   rX   F)rI   r   is_equivalent)r#   r$   r+   r<   rY   objis_equivs          r*   test_is_equivalent_to_modelz0ToFromModelTestMixin.test_is_equivalent_to_model   sm     Fi<<<c9-----&&s6&::F%/000000rF   N)__name__
__module____qualname____doc__r1   fixturer+   r6   r=   rA   rV   r`   rd   markparametrizeri   rb   rF   r*   r   r      s          V^'"""B B #"B4  R R R
6 6 6
!6 !6 !6F@ @ @B   [X'K'K'KLL1 1 ML1 1 1rF   r   c                       e Zd ZdZd ZdS )TestToFromModelz Directly test ``to/from_model``.c                 .    t           t          d| _        d S )N)tofrom)r   r   	functionsrc   s    r*   setup_classzTestToFromModel.setup_class   s     (*==rF   N)rj   rk   rl   rm   rw   rb   rF   r*   rr   rr      s)        **> > > > >rF   rr   )r   r!   numpyr   r1   astropy.cosmology.corer   astropy.cosmology.io.modelr   r   r   astropy.cosmology.tests.helperr   astropy.modeling.modelsr   "astropy.utils.compat.optional_depsr	   baser   r   r   rr   rb   rF   r*   <module>r      s          - , , , , , L L L L L L L L L L ? ? ? ? ? ? . . . . . . 8 8 8 8 8 8 ; ; ; ; ; ; ; ;
P1 P1 P1 P1 P1. P1 P1 P1f> > > > >*,@ > > > > >rF   