
    HR-e-                         d Z ddlZddlZddlZddlmZ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  G d de          Z G d	 d
e          Z G d de          Z G d de          ZdS )z-Tests for :mod:`astropy.cosmology.comparison`    N)	CosmologyFlatCosmologyMixinPlanck18cosmology_equal)convert_registry)_cosmology_not_equal_CosmologyWrapper_parse_format_parse_formats)ToFromTestMixinBasec                      e Zd ZdZ ej        d          d             Z ej        d          d             Z ej        dd ej	        
                                D             dhz
            d	             Z ej        d          d
             Z ej        d          d             Z ej        d          d             Z ej        d          d             Z ej        d          d             ZdS )ComparisonFunctionTestBasea  Tests for cosmology comparison functions.

    This class inherits from
    `astropy.cosmology.io.tests.base.ToFromTestMixinBase` because the cosmology
    comparison functions all have a kwarg ``format`` that allow the arguments to
    be converted to a |Cosmology| using the ``to_format`` architecture.

    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.
    classscopec                     t           S N)r   )selfs    Mlib/python3.11/site-packages/astropy/cosmology/funcs/tests/test_comparison.pycosmoz ComparisonFunctionTestBase.cosmo"   s        c                 f    t          |t                    r|j        S t          j        d           d S NzIcosmology is not flat, so does not have an equivalent non-flat cosmology.
isinstancer   nonflatpytestskipr   r   s     r   cosmo_eqvxflatz)ComparisonFunctionTestBase.cosmo_eqvxflat&   s>    e/00 	!= W	
 	
 	
 	
 	
r   c                     h | ]\  }}|S  r"   ).0k_s      r   	<setcomp>z$ComparisonFunctionTestBase.<setcomp>1   s    ???da???r   astropy.cosmology)r   paramsc                     |j         S r   )param)r   requests     r   formatz!ComparisonFunctionTestBase.format/   s    
 }r   c                 \    |                      |          st          j        d           dS dS )z4`pytest.fixture` form of method ``can_autoidentify`.zcannot autoidentifyN)can_autodentifyr   xfail)r   r,   s     r   xfail_cant_autoidentifyz2ComparisonFunctionTestBase.xfail_cant_autoidentify6   s;     ##F++ 	0L./////	0 	0r   c                 >    |dk    r ||d          S  ||          S Nzastropy.modelcomoving_distance)methodr"   )r   	to_formatr,   s      r   	convertedz$ComparisonFunctionTestBase.converted<   s3    _$$9V,?@@@@y   r   c                     |j         d         }t          ||          } |j        di ||dk    r|dz  ndt          |dd          z  i}|S )Nr   gqh ?gMbP?unit   r"   )__parameters__getattrclone)r   r   pvcosmo2s        r   
pert_cosmoz%ComparisonFunctionTestBase.pert_cosmoB   sm      #E1 
 
Q!f**EGAvq4I4I,IJ
 
 r   c                 f    t          |t                    r|j        S t          j        d           d S r   r   )r   r@   s     r   pert_cosmo_eqvxflatz.ComparisonFunctionTestBase.pert_cosmo_eqvxflatL   s?    j"455 	&%%W	
 	
 	
 	
 	
r   c                 f    |dk    r|                     |d          S |                     |          S r2   )r5   )r   r@   r,   s      r   pert_convertedz)ComparisonFunctionTestBase.pert_convertedU   s;    _$$''7J'KKK##F+++r   N)__name__
__module____qualname____doc__r   fixturer   r    r   _readerskeysr,   r0   r6   r@   rB   rD   r"   r   r   r   r      s       
 
 V^'"""  #" V^'"""
 
 #"
 V^??.7<<>>???CVBWW   	  V^'"""0 0 #"0
 V^'"""! ! #"!
 V^'"""  #" V^'"""
 
 #"
 V^'""", , #", , ,r   r   c                   j    e Zd ZdZ ej        d          d             Zd Zd Zd Z	d Z
d	 Zd
 ZdS )Test_parse_formatz!Test functions ``_parse_format``.r   r   c                     |dk    r ||d          S  ||          }t          |t          j                  rt          |          }|S r2   )r   r	   _cantbroadcast)r   r5   r,   r6   s       r   r6   zTest_parse_format.converted_   s]    _$$9V,?@@@@If%%	 i!2!ABB 	5))44Ir   c                 N    dD ]!}t          ||          |u sJ | d            "dS )z&Test the already-a-cosmology shortcut.>   FNTr'   z failedN)r
   )r   r   fmts      r   test_shortcutzTest_parse_format.test_shortcutn   sM     < 	G 	GC ,,555#5555	G 	Gr   c                 d    t          ||          }t          |t                    sJ ||k    sJ dS )z'Test converting a cosmology-like objectN)r
   r   r   )r   r6   r,   r   outs        r   test_convertzTest_parse_format.test_convertw   s8    Iv..#y)))))e||||||r   c                     t          j        t          t          j        d                    5  t          |d           ddd           dS # 1 swxY w Y   dS )zs
        Test ``_parse_format`` errors when given a Cosmology object and format
        is not compatible.
        z!for parsing a Cosmology, 'format'matchmappingN)r   raises
ValueErrorreescaper
   r   s     r   $test_parse_format_error_wrong_formatz6Test_parse_format.test_parse_format_error_wrong_format~   s    
 ]bi(KLL
 
 
 	, 	, %+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   AAAc                     t                      }t          j        t          t	          j        d                    5  t          |d           ddd           dS # 1 swxY w Y   dS )zp
        Test ``_parse_format`` errors when given a non-Cosmology object
        and format is `False`.
        zif 'format' is FalserW   FN)objectr   rZ   	TypeErrorr\   r]   r
   )r   	notacosmos     r   1test_parse_format_error_noncosmology_cant_convertzCTest_parse_format.test_parse_format_error_noncosmology_cant_convert   s    
 HH	]9BI6L,M,MNNN 	, 	,)U+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   AA!Ac                    t          ||gd           }t          |          dk    sJ t          j        ||k              sJ t          |d d g          }t          |          dk    sJ t          j        ||k              sJ t          ||g||ggd |g|d gg          }|j        dk    sJ t          j        ||k              sJ d S )N   )re   re   )r
   lennpallshape)r   r   r,   r6   rT   s        r   test_parse_format_vectorizedz.Test_parse_format.test_parse_format_vectorized   s    UEND113xx1}}}}vcUl##### ED$<003xx1}}}}vcUl##### Y)U!34f~PT~6V
 
 yF""""vcUl#######r   c                    t          ||d           }t          |          dk    sJ t          j        ||k              sJ t	          j        t          d          5  t          |d d g           d d d            d S # 1 swxY w Y   d S )Nr,   re   zoperands could not be broadcastrW   )r   rf   rg   rh   r   rZ   r[   )r   r   rT   s      r   test_parse_formats_vectorizedz/Test_parse_format.test_parse_formats_vectorized   s    UE$7773xx1}}}}vcUl##### ]:-NOOO 	7 	75$6666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s   A>>BBN)rE   rF   rG   rH   r   rI   r6   rR   rU   r^   rc   rj   rm   r"   r   r   rM   rM   \   s        ++V^'"""
 
 #"
G G G  , , ,, , ,$ $ $$7 7 7 7 7r   rM   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
Test_cosmology_equalz9Test :func:`astropy.cosmology.comparison.cosmology_equal`c                 V    t          ||          du sJ t          ||          du sJ d S )NTFr   r   r   r@   s      r   test_cosmology_equal_simplez0Test_cosmology_equal.test_cosmology_equal_simple   s@    ue,,4444 uj11U::::::r   c                     t          ||d          du sJ t          ||d          du sJ t          ||d          du sJ t          ||d          du sJ d S )NTallow_equivalentFrq   r   r   r    r@   rB   s        r   test_cosmology_equal_equivalentz4Test_cosmology_equal.test_cosmology_equal_equivalent   s     untLLLPTTTTTunuMMMQVVVVV J(;dSSS    J(;eTTT     r   c                     t          j        t          d          5  t          |||           d d d            d S # 1 swxY w Y   d S )Nz,cosmology_equal takes 2 positional argumentsrW   r   rZ   ra   r   r   s     r   #test_cosmology_equal_too_many_cosmoz8Test_cosmology_equal.test_cosmology_equal_too_many_cosmo   s    ]K
 
 
 	1 	1 E5%000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1   ;??c                    t          j        t                    5  t          ||           d d d            n# 1 swxY w Y   t          j        t                    5  t          ||d           d d d            d S # 1 swxY w Y   d S NFrl   rz   r   r   r6   s      r   !test_cosmology_equal_format_errorz6Test_cosmology_equal.test_cosmology_equal_format_error   s   ]9%% 	. 	.E9---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. ]9%% 	< 	<E9U;;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<   7;;A;;A?A?c                 ^    t          ||d           du sJ t          ||d          du sJ d S Nrl   Trq   )r   r   r6   r0   s       r    test_cosmology_equal_format_autoz5Test_cosmology_equal.test_cosmology_equal_format_auto   sJ     ui===EEEEui===EEEEEEr   c                     t          ||d |g          du sJ t          |||d g          du sJ t          ||d |g          du sJ d S Nrl   TFrq   r   r   r,   r6   rD   s        r   #test_cosmology_equal_format_specifyz8Test_cosmology_equal.test_cosmology_equal_format_specify   sy     uivGGG4OOOOy%GGG4OOOO undF^LLLPUUUUUUUr   c                 j    t          ||d |gd          du sJ t          |||d gd          du sJ d S )NTr,   rv   rq   r   r   r,   r6   r    s        r   .test_cosmology_equal_equivalent_format_specifyzCTest_cosmology_equal.test_cosmology_equal_equivalent_format_specify   s    
 	4.SW       >64.SW        r   N)rE   rF   rG   rH   rs   rx   r{   r   r   r   r   r"   r   r   ro   ro      s        CC; ; ;
 
 
 1 1 1< < <F F FV V V
 
 
 
 
r   ro   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
Test_cosmology_not_equalz>Test :func:`astropy.cosmology.comparison._cosmology_not_equal`c                 V    t          ||          du sJ t          ||          du sJ d S )NFTr   rr   s      r   test_cosmology_not_equal_simplez8Test_cosmology_not_equal.test_cosmology_not_equal_simple   s@    #E511U:::: $E:66$>>>>>>r   c                     t          j        t          d          5  t          |||           d d d            d S # 1 swxY w Y   d S )Nz'_cosmology_not_equal takes 2 positionalrW   r   rZ   ra   r   r   s     r   'test_cosmology_not_equal_too_many_cosmoz@Test_cosmology_not_equal.test_cosmology_not_equal_too_many_cosmo  s    ]9,UVVV 	6 	6 u555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6r|   c                     t          ||d          du sJ t          ||d          du sJ t          ||d          du sJ t          ||d          du sJ d S )NFru   Tr   rw   s        r   #test_cosmology_not_equal_equivalentz<Test_cosmology_not_equal.test_cosmology_not_equal_equivalent  s    
 !OOOSWWWWW !NNNRWWWWW !/%       !-@SWXXX     r   c                    t          j        t                    5  t          ||           d d d            n# 1 swxY w Y   t          j        t                    5  t          ||d           d d d            d S # 1 swxY w Y   d S r~   r   r   s      r   %test_cosmology_not_equal_format_errorz>Test_cosmology_not_equal.test_cosmology_not_equal_format_error  s   ]9%% 	3 	3 	222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 ]9%% 	A 	A 	%@@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	Ar   c                 ^    t          ||d           du sJ t          ||d          du sJ d S r   r   )r   r   rD   r0   s       r   $test_cosmology_not_equal_format_autoz=Test_cosmology_not_equal.test_cosmology_not_equal_format_auto&  sJ     $E>$GGG4OOOO#E>$GGG4OOOOOOr   c                     t          ||d |g          du sJ t          |||d g          du sJ t          ||d |g          du sJ d S r   r   r   s        r   'test_cosmology_not_equal_format_specifyz@Test_cosmology_not_equal.test_cosmology_not_equal_format_specify,  s}    
 !f~NNNRVVVVV !~NNNRVVVVV $E9dF^LLLPUUUUUUUr   c                     t          ||d |gd          du sJ t          ||d |gd          du sJ t          |||d gd          du sJ d S )NFr   Tr   r   s        r   2test_cosmology_not_equal_equivalent_format_specifyzKTest_cosmology_not_equal.test_cosmology_not_equal_equivalent_format_specify:  s    
 !	4.SX       !	4.SW       !>64.SW        r   N)rE   rF   rG   rH   r   r   r   r   r   r   r   r"   r   r   r   r      s        HH? ? ?6 6 6
 
 
,A A AP P PV V V
 
 
 
 
r   r   )rH   r\   numpyrg   r   astropy.cosmologyr   r   r   r   astropy.cosmology.connectr   "astropy.cosmology.funcs.comparisonr   r	   r
   r   astropy.cosmology.io.tests.baser   r   rM   ro   r   r"   r   r   <module>r      s   4 3 				      V V V V V V V V V V V V 6 6 6 6 6 6            @ ? ? ? ? ?D, D, D, D, D,!4 D, D, D,NP7 P7 P7 P7 P72 P7 P7 P7fH
 H
 H
 H
 H
5 H
 H
 H
VV
 V
 V
 V
 V
9 V
 V
 V
 V
 V
r   