
    HR-eR                         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mZ d dlmZmZmZ ddlmZmZ d Zd	 Z G d
 de          Z G d dee          ZdS )    N)	CosmologyFlatLambdaCDMPlanck18)units)	from_yamlto_yamlyaml_constructoryaml_representer)AstropyDumperdumpload   )ToFromDirectTestBaseToFromTestMixinBasec                      t          d          } t          |           sJ t          t                    }t	          |t
                    sJ |                    d          sJ dS )z9Test :func:`~astropy.cosmology.io.yaml.yaml_representer`.z!!astropy.cosmology.flrw.LambdaCDMz%!astropy.cosmology.flrw.FlatLambdaCDMN)r
   callabler   r   
isinstancestr
startswith)representerymls     Dlib/python3.11/site-packages/astropy/cosmology/io/tests/test_yaml.pytest_yaml_representerr      sh     ##FGGKK      x..Cc3>>ABBBBBBB    c                  n   t          t                    } t          |           sJ t          t                    }t          j        t                    5  t          |          }ddd           n# 1 swxY w Y   t          |t                    sJ |t          k    sJ |j
        t          j
        k    sJ dS )z9Test :func:`~astropy.cosmology.io.yaml.yaml_constructor`.N)r	   r   r   r   r   uadd_enabled_unitscur   r   meta)constructorr   cosmos      r   test_yaml_constructorr"   &   s     #=11KK      x..C	
	R	 	   S		              e]+++++H:&&&&&&s   A//A36A3c                       e Zd ZdZej        d             Zd Zd Zd Z	ej
                            dg d          d             Zd	 Zd
S )ToFromYAMLTestMixina  
    Tests for a Cosmology[To/From]Format with ``format="yaml"``.
    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.
    c                 V    |t           j        vrt          j        d| d           dS dS )z
        YAML I/O only works on registered classes. So the thing to check is
        if this class is registered. If not, :func:`pytest.xfail` this test.
        Some of the tests define custom cosmologies. They are not registered.
        zCosmologies of type z are not registered with YAML.N)r   yaml_representerspytestxfail)self	cosmo_clss     r   !xfail_if_not_registered_with_yamlz5ToFromYAMLTestMixin.xfail_if_not_registered_with_yamlD   sF     M;;;LPyPPP     <;r   c                 x     |d          }t          |t                    sJ |                    d          sJ dS )zTest cosmology -> YAML.yamlz!astropy.cosmology.N)r   r   r   )r)   r!   	to_formatr+   r   s        r   test_to_yamlz ToFromYAMLTestMixin.test_to_yamlR   sF    i#s#####~~34444444r   c                      |d          } ||d          }|j         |j         k    sJ |j        |j        k    sJ  ||d          }||k    sJ |j        |j        k    sJ dS )z$Test cosmology -> YAML -> cosmology.r-   formatN)namer   )r)   r!   r.   from_formatr+   r   gots          r   test_from_yaml_defaultz*ToFromYAMLTestMixin.test_from_yaml_defaultY   s     ik#f---x5:%%%%x5:%%%% k#f---e||||x5:%%%%%%r   c                     |                      d          du sJ  |d          }t          j        t          t          f          5   ||           ddd           dS # 1 swxY w Y   dS )zAs a non-path string, it does NOT auto-identifies 'format'.

        TODO! this says there should be different types of I/O registries.
              not just hacking object conversion on top of file I/O.
        r-   FN)can_autodentifyr'   raisesFileNotFoundErrorOSError)r)   r!   r.   r4   r+   r   s         r   test_from_yaml_autoidentifyz/ToFromYAMLTestMixin.test_from_yaml_autoidentifyl   s     ##F++u4444 i]-w788 	 	K	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA"%A"r2   )TFNc                      |d          }t          |t                    rJ |                    ||          }|du sJ dS )a#  Test :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 YAML string. YAML can't be identified without "format" specified.
        r-   r1   FN)r   r   is_equivalent)r)   r!   r.   r2   r+   objis_equivs          r   test_is_equivalent_to_yamlz.ToFromYAMLTestMixin.test_is_equivalent_to_yaml   sX     ic9-----&&s6&::5      r   c                 N    |                      |d          d          du sJ dS )zTest :meth:`astropy.cosmology.Cosmology.is_equivalent`.

        Same as ``test_is_equivalent_to_yaml`` but with ``format="yaml"``.
        r-   r1   TN)r>   )r)   r!   r.   r+   s       r   )test_is_equivalent_to_yaml_specify_formatz=ToFromYAMLTestMixin.test_is_equivalent_to_yaml_specify_format   s8     ""99V#4#4V"DDLLLLLLr   N)__name__
__module____qualname____doc__r'   fixturer+   r/   r6   r<   markparametrizerA   rC    r   r   r$   r$   :   s          ^	 	 ^	5 5 5& & &&  2 [X':':':;;! ! <;!M M M M Mr   r$   c                   T    e Zd ZdZd Z ej        dd          d             Zd ZdS )	TestToFromYAMLa'  
    Directly test ``to/from_yaml``.
    These are not public API and are discouraged from use, in favor of
    ``Cosmology.to/from_format(..., format="yaml")``, but should be tested
    regardless b/c 3rd party packages might use these in their Cosmology I/O.
    Also, it's cheap to test.
    c                 .    t           t          d| _        dS )zBSet up fixtures to use ``to/from_yaml``, not the I/O abstractions.)tofromN)r   r   	functionsr)   s    r   setup_classzTestToFromYAML.setup_class   s     ';;r   classT)scopeautousec              #      K   dV  dS )z
        Setup and teardown for tests.
        This overrides from super because `ToFromDirectTestBase` adds a custom
        Cosmology ``CosmologyWithKwargs`` that is not registered with YAML.
        NrK   rR   s    r   setupzTestToFromYAML.setup   s       	r   c                     dS )z
        If directly calling the function there's no auto-identification.
        So this overrides the test from `ToFromYAMLTestMixin`
        NrK   )r)   r!   r.   r4   s       r   r<   z*TestToFromYAML.test_from_yaml_autoidentify   s      r   N)	rD   rE   rF   rG   rS   r'   rH   rX   r<   rK   r   r   rM   rM      si         < < < V^'4000  10    r   rM   )r'   astropy.unitsr   r   astropy.cosmologyr   r   r   r   astropy.cosmology.io.yamlr   r   r	   r
   astropy.io.misc.yamlr   r   r   baser   r   r   r"   r$   rM   rK   r   r   <module>r_      s]          @ @ @ @ @ @ @ @ @ @ ) ) ) ) ) )            ; : : : : : : : : : ; ; ; ; ; ; ; ;	C 	C 	C' ' '(bM bM bM bM bM- bM bM bMJ    )+>     r   