U
    e»{jÇ  ã                   @   sÀ   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„ eD ƒZG dd	„ d	ƒZG d
d„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deeƒZG dd„ deeƒZdS )é    N)Ú	CosmologyÚ	ParameterÚrealizations)Úunits)Ú_COSMOLOGY_CLASSES)Ú	availablec                 C   s   g | ]}t t|ƒ‘qS © )Úgetattrr   )Ú.0Únamer   r   ú^/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/cosmology/io/tests/base.pyÚ
<listcomp>   s     r   c                   @   s   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   c                   @   s@   e Zd ZdZejdd�dd„ ƒZejdd�dd„ ƒZd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                 C   s   t jS )z7Convert to Cosmology using ``Cosmology.from_format()``.)r   Úfrom_format©Úselfr   r   r   r   (   s    zToFromTestMixinBase.from_formatc                 C   s   |j S )z2Convert Cosmology instance using ``.to_format()``.)Ú	to_format©r   Úcosmor   r   r   r   -   s    zToFromTestMixinBase.to_formatc                 C   s   |t jjjkS )z)Check whether a format can auto-identify.)r   r   ÚregistryZ_identifiers)r   Úformatr   r   r   Úcan_autodentify2   s    z#ToFromTestMixinBase.can_autodentifyN)	r   r   r   r   ÚpytestÚfixturer   r   r   r   r   r   r   r      s   	



r   c                   @   sF   e Zd ZdZejdd�dd„ ƒZejdd�dd„ ƒZejd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                 C   s   t jS )z3Read Cosmology instance using ``Cosmology.read()``.)r   Úreadr   r   r   r   r#   A   s    zReadWriteTestMixinBase.readc                 C   s   |j S )z#Write Cosmology using ``.write()``.)Úwriter   r   r   r   r$   F   s    zReadWriteTestMixinBase.writec              	   c   s    t  t¡� dV  W 5 Q R X dS )z8Add :mod:`astropy.cosmology.units` to the enabled units.N)ÚuZadd_enabled_unitsÚcur   r   r   r   Úadd_cuK   s    zReadWriteTestMixinBase.add_cuN)	r   r   r   r   r    r!   r#   r$   r'   r   r   r   r   r"   7   s   	



r"   c                   @   sP   e Zd ZdZejddd�dd„ ƒZejded�dd	„ ƒZejdd
�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   Zautousec                 c   s(   G dd„ dt ƒ}dV  t |jd¡ dS )zSetup and teardown for tests.c                       s*   e Zd Zeejd�Zd‡ fdd„	Z‡  ZS )z3IODirectTestBase.setup.<locals>.CosmologyWithKwargs)Úunitr   úcosmology with kwargsNc                    s    t ƒ j||d� |tj> | _d S )N)r   Úmeta)ÚsuperÚ__init__r%   ÚKZ_Tcmb0)r   ÚTcmb0r   r+   Úkwargs©Ú	__class__r   r   r-   j   s    z<IODirectTestBase.setup.<locals>.CosmologyWithKwargs.__init__)r   r*   N)	r   r   r   r   r%   r.   r/   r-   Ú__classcell__r   r   r1   r   ÚCosmologyWithKwargsg   s
        ÿr4   N)r   r   Úpopr   )r   r4   r   r   r   Úsetupc   s    	zIODirectTestBase.setup)r   Úparamsc                 C   s"   t |jtƒrt|j dd�S |jS )zCosmology instance.é   )r/   )Ú
isinstanceÚparamÚstrr   )r   Úrequestr   r   r   r   v   s    zIODirectTestBase.cosmor   c                 C   s   |j S )zCosmology classes.r1   r   r   r   r   Ú	cosmo_cls}   s    zIODirectTestBase.cosmo_clsN)
r   r   r   r   r    r!   r6   Úcosmo_instancesr   r=   r   r   r   r   r(   V   s   


r(   c                   @   s8   e Zd ZdZejdd�dd„ ƒZejdd�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                    s   ‡ fdd„}|S )z-Convert to Cosmology using function ``from``.c                     s   |  dd ¡ ˆ jd | |ŽS )Nr   Úfrom©r5   Ú	functions©Úargsr0   r   r   r   Úuse_from_format™   s    z9ToFromDirectTestBase.from_format.<locals>.use_from_formatr   )r   rE   r   r   r   r   •   s    z ToFromDirectTestBase.from_formatc                    s   ‡ ‡fdd„}|S )z2Convert Cosmology to format using function ``to``.c                     s   ˆj d ˆ f| ž|ŽS )NÚto©rB   rC   ©r   r   r   r   Úuse_to_format£   s    z5ToFromDirectTestBase.to_format.<locals>.use_to_formatr   )r   r   rI   r   rH   r   r   Ÿ   s    zToFromDirectTestBase.to_formatN)r   r   r   r   r    r!   r   r   r   r   r   r   r?   ƒ   s
   

	
r?   c                   @   s8   e Zd ZdZejdd�dd„ ƒZejdd�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                    s   ‡ fdd„}|S )z1Read Cosmology from file using function ``read``.c                     s   |  dd ¡ ˆ jd | |ŽS )Nr   r#   rA   rC   r   r   r   Úuse_read¿   s    z.ReadWriteDirectTestBase.read.<locals>.use_readr   )r   rK   r   r   r   r#   »   s    zReadWriteDirectTestBase.readc                    s   ‡ ‡fdd„}|S )z1Write Cosmology to file using function ``write``.c                     s   ˆj d ˆ f| ž|ŽS )Nr$   rG   rC   rH   r   r   Ú	use_writeÉ   s    z0ReadWriteDirectTestBase.write.<locals>.use_writer   )r   r   rL   r   rH   r   r$   Å   s    zReadWriteDirectTestBase.writeN)r   r   r   r   r    r!   r#   r$   r   r   r   r   rJ   ©   s
   

	
rJ   )r    Zastropy.unitsr   r%   Zastropy.cosmologyr   r   r   r&   Zastropy.cosmology.corer   Zastropy.cosmology.realizationsr   r>   r   r   r"   r(   r?   rJ   r   r   r   r   Ú<module>   s   -&