
    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
 d dlmZ d eD             Z G d d          Z G d	 d
e          Z G d de          Z G d de          Z G d dee          Z G d dee          ZdS )    N)	Cosmology	Parameterrealizations)units)_COSMOLOGY_CLASSES)	availablec                 8    g | ]}t          t          |          S  )getattrr   ).0names     ?lib/python3.11/site-packages/astropy/cosmology/io/tests/base.py
<listcomp>r      s"    EEE47<..EEE    c                       e Zd ZdZdS )
IOTestBasea  Base class for Cosmology I/O tests.

    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.
    N)__name__
__module____qualname____doc__r
   r   r   r   r      s           r   r   c                       e Zd ZdZ ej        d          d             Z ej        d          d             Zd ZdS )ToFromTestMixinBasea  Tests for a Cosmology[To/From]Format with some ``format``.

    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.
    classscopec                     t           j        S )z7Convert to Cosmology using ``Cosmology.from_format()``.)r   from_formatselfs    r   r   zToFromTestMixinBase.from_format(   s     $$r   c                     |j         S )z2Convert Cosmology instance using ``.to_format()``.)	to_formatr   cosmos     r   r!   zToFromTestMixinBase.to_format-        r   c                 2    |t           j        j        j        v S )z)Check whether a format can auto-identify.)r   r   registry_identifiers)r   formats     r   can_autodentifyz#ToFromTestMixinBase.can_autodentify2   s    .7DDDr   N)	r   r   r   r   pytestfixturer   r!   r)   r
   r   r   r   r      s          V^'"""% % #"% V^'"""  #"E E E E Er   r   c                       e Zd ZdZ ej        d          d             Z ej        d          d             Zej        d             ZdS )ReadWriteTestMixinBasea  Tests for a Cosmology[Read/Write].

    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.
    r   r   c                     t           j        S )z3Read Cosmology instance using ``Cosmology.read()``.)r   readr   s    r   r/   zReadWriteTestMixinBase.readA   s     ~r   c                     |j         S )z#Write Cosmology using ``.write()``.)writer"   s     r   r1   zReadWriteTestMixinBase.writeF   s     {r   c              #   v   K   t          j        t                    5  dV  ddd           dS # 1 swxY w Y   dS )z8Add :mod:`astropy.cosmology.units` to the enabled units.N)uadd_enabled_unitscur   s    r   add_cuzReadWriteTestMixinBase.add_cuK   s        $$ 	 	EEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   .22N)	r   r   r   r   r*   r+   r/   r1   r6   r
   r   r   r-   r-   7   s          V^'"""  #" V^'"""  #" ^  ^  r   r-   c                       e Zd ZdZ ej        dd          d             Z ej        de          d             Z ej        d          d	             Z	d
S )IODirectTestBasea  Directly test Cosmology I/O functions.

    These functions are not public API and are discouraged from public use, in
    favor of the I/O methods on |Cosmology|. They are tested b/c they are used
    internally and because some tests for the methods on |Cosmology| don't need
    to be run in the |Cosmology| class's large test matrix.

    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.
    r   T)r   autousec              #   l   K    G d dt                     }dV  t          j        |j        d           dS )zSetup and teardown for tests.c                   D     e Zd Z eej                  Z	 d fd	Z xZS )3IODirectTestBase.setup.<locals>.CosmologyWithKwargs)unitr   cosmology with kwargsNc                 v    t                                          ||           |t          j        z  | _        d S )N)r   meta)super__init__r3   K_Tcmb0)r   Tcmb0r   r@   kwargs	__class__s        r   rB   z<IODirectTestBase.setup.<locals>.CosmologyWithKwargs.__init__j   s3       d 666#qslr   )r   r>   N)	r   r   r   r   r3   rC   rE   rB   __classcell__rG   s   @r   CosmologyWithKwargsr<   g   sX        I13'''E CG+ + + + + + + + + +r   rJ   N)r   r   popr   )r   rJ   s     r   setupzIODirectTestBase.setupc   sZ      	+ 	+ 	+ 	+ 	+) 	+ 	+ 	+ 	 	2?FFFFFr   )r   paramsc                 z    t          |j        t                    rt          |j                 d          S |j        S )zCosmology instance.   )rE   )
isinstanceparamstrr   )r   requests     r   r#   zIODirectTestBase.cosmov   s8     gmS)) 	>%gm41====}r   r   c                     |j         S )zCosmology classes.rI   r"   s     r   	cosmo_clszIODirectTestBase.cosmo_cls}   r$   r   N)
r   r   r   r   r*   r+   rL   cosmo_instancesr#   rU   r
   r   r   r8   r8   V   s        
 
 V^'4000G G 10G$ V^'/:::  ;: V^'"""  #"  r   r8   c                   z    e Zd ZdZ ej        d          d             Z ej        d          d             ZdS )ToFromDirectTestBasea  Directly test ``to/from_<format>``.

    These functions are not public API and are discouraged from public use, in
    favor of ``Cosmology.to/from_format(..., format="<format>")``. They are
    tested because they are used internally and because some tests for the
    methods on |Cosmology| don't need to be run in the |Cosmology| class's
    large test matrix.

    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 should have an attribute ``functions`` which is a dictionary
    containing two items: ``"to"=<function for to_format>`` and
    ``"from"=<function for from_format>``.
    r   r   c                       fd}|S )z-Convert to Cosmology using function ``from``.c                  V    |                     dd             j        d         | i |S )Nr(   fromrK   	functionsargsrF   r   s     r   use_from_formatz9ToFromDirectTestBase.from_format.<locals>.use_from_format   3    JJx&&&)4>&)4:6:::r   r
   )r   r`   s   ` r   r   z ToFromDirectTestBase.from_format   s$    	; 	; 	; 	; 	; r   c                       fd}|S )z2Convert Cosmology to format using function ``to``.c                  2     j         d         g| R i |S )Ntor]   r_   rF   r#   r   s     r   use_to_formatz5ToFromDirectTestBase.to_format.<locals>.use_to_format   s*    '4>$'???????r   r
   )r   r#   rg   s   `` r   r!   zToFromDirectTestBase.to_format   s0    	@ 	@ 	@ 	@ 	@ 	@ r   N)r   r   r   r   r*   r+   r   r!   r
   r   r   rX   rX      st         " V^'"""  #" V^'"""  #"  r   rX   c                   z    e Zd ZdZ ej        d          d             Z ej        d          d             ZdS )ReadWriteDirectTestBasea  Directly test ``read/write_<format>``.

    These functions are not public API and are discouraged from public use, in
    favor of ``Cosmology.read/write(..., format="<format>")``. They are tested
    because they are used internally and because some tests for the
    methods on |Cosmology| don't need to be run in the |Cosmology| class's
    large test matrix.

    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 should have an attribute ``functions`` which is a dictionary
    containing two items: ``"read"=<function for read>`` and
    ``"write"=<function for write>``.
    r   r   c                       fd}|S )z1Read Cosmology from file using function ``read``.c                  V    |                     dd             j        d         | i |S )Nr(   r/   r\   r^   s     r   use_readz.ReadWriteDirectTestBase.read.<locals>.use_read   ra   r   r
   )r   rl   s   ` r   r/   zReadWriteDirectTestBase.read   s#    	; 	; 	; 	; 	; r   c                       fd}|S )z1Write Cosmology to file using function ``write``.c                  2     j         d         g| R i |S )Nr1   re   rf   s     r   	use_writez0ReadWriteDirectTestBase.write.<locals>.use_write   s*    *4>'*5B4BBB6BBBr   r
   )r   r#   ro   s   `` r   r1   zReadWriteDirectTestBase.write   s0    	C 	C 	C 	C 	C 	C r   N)r   r   r   r   r*   r+   r/   r1   r
   r   r   ri   ri      st         " V^'"""  #" V^'"""  #"  r   ri   )r*   astropy.unitsr   r3   astropy.cosmologyr   r   r   r5   astropy.cosmology.corer   astropy.cosmology.realizationsr   rV   r   r   r-   r8   rX   ri   r
   r   r   <module>rt      s          @ @ @ @ @ @ @ @ @ @ ) ) ) ) ) ) 5 5 5 5 5 5 4 4 4 4 4 4EE9EEE       E E E E E* E E E2    Z   >* * * * *z * * *Z# # # # #+-@ # # #L# # # # #.0C # # # # #r   