U
    e»{j M  ć                k   @   s¾  d Z ddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ejdfejd d	fejej d
fejej d	fejejd  dfejej dfejdfejejd ej ej  dfejejd ej ej  dfejejd ej ej  dfejdfejdfejjej d
fejej dfejej dfejej ejd  dfejejd  dfejej dfej ej! dfe "d”dfejd dfejdfej dfej#dfejejd  dfejd fej$d!fej%d"fej&d#fej'd#fejj(d#fejj)d#fejj)ej d$fejd%fej*dfej+d&fej,dfej-ejd  d'fejd ej- d(fej%ejd  d)fej-ej ej d*fej-ejd  ej dfej ej dfej ejd  d+fej$ejej  d,fejd ej d-fejd. d/fej.dfejd0fej/d1fej0d2fej1d3fej2d4fejej d5fej.ejd  dfej/ej d6fejejd  d7fejejd  d8fej2ej d9fej3dfejd:fej.ej d;fej4ej d<fej4d=fej5d>fej6d?fej7d@fej,ej# dAfej5ejd  dBfej8j9dCfej8j:dDfej;jdfej;jej dEfej<j=dFfej<j>dGfej<j?dHfej<j@dIfejjAejej ejj(  dJfejjBej' dKfejjBej' ej$ dLfej*ejdM  ejd.  dNfej,ejd  dNfejd ej% dOfejej1 dPfej1ej dQfej.ejd  dRfej*ej dRfejCd. ejdS  dTfejejd  dUfejejdV  dWfejejdX  dYfejejdZ  d[fej'ej d\fejj(ej d\fejj)ejjD d\fejjEej$ d]fej%ejF ej d^fejjGejjD ejd  d_fej%ej d`fejjHej' ej% dafej%ej- dbfejjIejJ dcfejjDd ej ddfejej defej+d. dffejKdfgjZLejM NdgeL”dhdi ZOejjPZQejjPZRejej jPZSejd jPZTejd. jPZUejKjPZVej+jPZWej-ej ej jPZXejM NdjdkejdfdldXej dfeQeQfej+dmfdng”dodp ZYejM NdqdeZfdreZfdshe[fg”dtdu Z\dvdw Z]eQeQdxdyfeQeTdxdzfeQddxdyfdeQdxe^feVeVdxdyfeXd*dxdyfeWdmdxdyfejd jPddxdyfejd jPejd{ jPdxdzfeQeQd|dzfeSeRd|dyfeWeVd|dyfeQejdxe^feQeQd}eTfeSeRd}eQfeSeRd~eQfeQeRdeSfeTeQdeQfeQeTdeQfeVeVd}eVfeVeVdeVfeQddeTfeTddeQfeVdVdeVfejeQd}e^fdeQd}e^fejeRde^fdeQde^feQejd}eTfeQejd~eTfeSejd}eQfeQdd}eQfeQdd~eQfeQejdeSfeTddeTfeRejdeSfeQddeUfeQddeTfeQdd}e^feQdd~e^feQdde^feQd.de^feQdd}eTfeQdd~eTfeTddeQfeQddeQfg.Z_ejM Nde_”dd Z`ejdhfej-ej ej ddhfej+dd&dhfgZaejM Ndea”dd Zbdd Zcdd Zdejejfejejfejej-ej ejdM  fejej ejd fej&ej'fej&ejj)fej&ejj(fej'ejj(fejd ejed fg	ZfejM Ndef”dd ZgejM Ndef”dd Zhejejfejd ejd fejej*fejejj(fgZiejM Ndei”dd ZjeQdfeSdfeWdfej'jPd#fej*ej& ej- jPdfgZkeQd feSd”feWd¢fej'jPd£fej*ej& ej- jPd¤fgZlejM Nd„ek”d¦d§ ZmejM NdØel”d©dŖ Znd«d¬ ZoejM Nd­ep d®dd.g”dÆd° Zqd±d² Zrd³d“gZsejM Ndµes”d¶d· ZtG død¹ d¹ZuejM Ndŗd»d¼d½d¾g”dædĄ ZvdĮdĀ ZwejM NdĆdd
dÄg”dÅdĘ ZxdĒdČ ZydS )ÉzC
Unit tests for the handling of physical types in `astropy.units`.
é    N)Śunits)Śhbar)Śphysical)ŚAstropyDeprecationWarningŚlengthé   ŚvolumeŚspeedé   ŚunknownŚdimensionlesszangular momentumé   zspectral flux density wavzphoton flux density wavzphoton flux densityzdata quantityŚpowerzelectrical currentzelectrical current densityzmagnetic fluxZenergyzangular speedé   ŚareaŚtimeZanglezsolid angleZaccelerationZ	frequencyZmasszamount of substanceZtemperatureZtemperature_gradientŚforceŚpressurezmass densityzspecific volumezmolar concentrationzmomentum/impulsezangular accelerationzdynamic viscosityzkinematic viscosityé’’’’Ś
wavenumberzelectrical chargezelectrical potentialzelectrical resistancezelectrical conductancezelectrical capacitancezelectrical dipole momentzelectrical field strengthzelectrical flux densityzelectrical charge densityZpermittivityzmagnetic flux densityzmagnetic field strengthzelectromagnetic field strengthZ
inductancezluminous intensityzluminous fluxzluminous emittance/illuminancezradiant intensityZ	luminancezspectral flux densityzphoton fluxŚ	bandwidthzelectrical charge (ESU)zelectrical current (ESU)zelectrical current (EMU)zelectrical charge (EMU)zthermal conductivityzheat capacityzspecific heat capacityéž’’’zenergy fluxzmolar volumezelectrical resistivityzelectrical conductivityzmagnetic momentéż’’’zvolumetric rateZjerké   Zsnapé   Zcrackleé   Śpopztemperature gradientzspecific energyzreaction ratezmoment of inertiazcatalytic activityzmolar heat capacityZmolalityZabsementzvolumetric flow ratezfrequency driftZcompressibilityzunit, physical_typec                 C   s*   | j |ks&t| d|d| j ddS )zĆ
    Test that the `physical_type` attribute of `u.Unit` objects provides
    the expected physical type for various units.

    Many of these tests are used to test backwards compatibility.
    z&.physical_type was expected to return z, but instead returned Ś.N©Śphysical_typeŚAssertionError)Śunitr   © r"   ś`/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/units/tests/test_physical.pyŚtest_physical_type_names}   s    ’r$   z0physical_type_representation, physical_type_name)ē      š?r   )Śworkr&   Śenergy_density)r'   r'   c                 C   s*   t  | ”}t|t jst||ks&tdS )z/Test different ways of getting a physical type.N)r   Śget_physical_typeŚ
isinstanceŚPhysicalTyper    )Zphysical_type_representationŚphysical_type_namer   r"   r"   r#   Śtest_getting_physical_type   s    
r,   zargument, exceptionznot a name of a physical typez'this set cannot be made into a Quantityc              	   C   s$   t  |” t | ” W 5 Q R X dS )zo
    Test that `get_physical_type` raises appropriate exceptions when
    provided with invalid arguments.
    N)ŚpytestŚraisesr   r(   )ŚargumentŚ	exceptionr"   r"   r#   Ś%test_getting_physical_type_exceptionsØ   s    r1   c                	   C   s,   t  t” t tjjtj” W 5 Q R X dS )z¦
    Test that `PhysicalType` instances cannot be cast into `Quantity`
    objects.  A failure in this test could be related to failures
    in subsequent tests.
    N)r-   r.   Ś	TypeErrorŚuZQuantityŚmr   r"   r"   r"   r#   Ś)test_physical_type_cannot_become_quantity¹   s    r5   Ś__eq__TFé	   Ś__ne__Ś__mul__Ś__rmul__Ś__truediv__Ś__rtruediv__Ś__pow__g      ą?g	@r%   é    zleft, right, operator, expectedc                 C   s   t | |||kstdS )zg
    Test that `PhysicalType` dunder methods that require another
    argument behave as intended.
    N)Śgetattrr    )ŚleftŚrightŚoperatorŚexpectedr"   r"   r#   Śtest_physical_type_operationsö   s    rD   ZimpulseŚmomentumśenergy densityŚstresszunit, expected_setc                 C   s   t | j}||kstdS )z<Test making a `physical.PhysicalType` instance into a `set`.N)Śsetr   r    )r!   Zexpected_setZresulting_setr"   r"   r#   Śtest_physical_type_as_set  s    
rI   c                  C   s$   dd t D } | dddgks tdS )z5Test iterating through different physical type names.c                 S   s   g | ]}|qS r"   r"   )Ś.0r+   r"   r"   r#   Ś
<listcomp>  s     z0test_physical_type_iteration.<locals>.<listcomp>rF   r   rG   N)r   r    )Zphysical_type_namesr"   r"   r#   Śtest_physical_type_iteration  s    rL   c                   C   s   dt kstdtkstdS )ze
    Test that `in` works as expected for `PhysicalType` objects with one
    or multiple names.
    r   r   N)r   r    r   r"   r"   r"   r#   Śtest_physical_type_in  s    rM   é   zunit1, unit2c                 C   s,   | j |j kdkst| j |j kdks(tdS )zi
    Test that `physical.PhysicalType` instances for units of the same
    dimensionality are equal.
    TFNr   )Śunit1Śunit2r"   r"   r#   Ś$test_physical_type_instance_equality)  s    rQ   c                 C   s8   t  | ”}t  |”}||ks t|dkr4||ks4tdS )z¬
    Test that `get_physical_type` retrieves the same `PhysicalType`
    instances for equivalent physical types, except for unknown types
    which are not cataloged.
    r   N)r   r(   r    ©rO   rP   Zphysical_type1Zphysical_type2r"   r"   r#   Ś'test_get_physical_type_equivalent_pairs3  s
    

rS   é   c                 C   s<   t  | d”}t  |d”}||kdks(t||kdks8tdS )zy
    Test that `physical.PhysicalType` instances for units with different
    dimensionality are considered unequal.
    Zptype1Zptype2TFN)r   r*   r    rR   r"   r"   r#   Ś&test_physical_type_instance_inequalityI  s    rU   zspeed/velocityzenergy density/pressure/stressz'specific entropy/specific heat capacityzPhysicalType('length')z#PhysicalType({'speed', 'velocity'})z6PhysicalType({'energy density', 'pressure', 'stress'})zPhysicalType('temperature')z<PhysicalType({'specific entropy', 'specific heat capacity'})zphysical_type, expected_strc                 C   s   t | |kstdS )z.Test using `str` on a `PhysicalType` instance.N)Śstrr    )r   Zexpected_strr"   r"   r#   Śtest_physical_type_stri  s    rW   zphysical_type, expected_reprc                 C   s   t | |kstdS )z/Test using `repr` on a `PhysicalType` instance.N)Śreprr    )r   Zexpected_reprr"   r"   r#   Śphysical_type_repro  s    rY   c                  C   s   t di} | t  dkstdS )z>Test that a `PhysicalType` instance can be used as a dict key.é*   N)r   r    )Ś
dictionaryr"   r"   r#   Śtest_physical_type_hashw  s    r\   ŚmultiplicandrZ   c              	   C   s"   t  t” t|   W 5 Q R X dS )zv
    Test that multiplication of a physical type returns `NotImplemented`
    when attempted for an invalid type.
    N)r-   r.   r2   r   )r]   r"   r"   r#   Ś!test_physical_type_multiplication}  s    r^   c                  C   s4   t jddd} | j}t|tjs$t|dks0tdS )zU
    Test basic functionality for the physical type of an unrecognized
    unit.
    ŚparrotZsilent)Zparse_strictr   N)r3   ŚUnitr   r)   r   r*   r    )Zunrecognized_unitr   r"   r"   r#   Ś$test_unrecognized_unit_physical_type  s    ra   )rZ   )zvalid inputrZ   Śinvalid_inputc              	   C   s>   t jd }t t” t || ” W 5 Q R X |jdks:tdS )zø
    Test that `PhysicalType` cannot be instantiated when one of the
    supplied names is not a string, while making sure that the physical
    type for the unit remains unknown.
    éW   r   N)	r3   Śsr-   r.   Ś
ValueErrorr   r*   r   r    )rb   Zobscure_unitr"   r"   r#   Śtest_invalid_physical_types  s    
rf   c                   @   sT   e Zd Zejd Zejd Zdd Zdd Z	dd Z
d	d
 Zedd Zdd ZdS )ŚTestDefPhysTypeéc   rZ   c              	   C   s6   t  t” t | jd” W 5 Q R X dtjks2tdS )z.Test that a unit cannot be defined as unknown.r   N)r-   r.   re   r   Śdef_physical_typeŚ
weird_unitŚ_unit_physical_mappingr    ©Śselfr"   r"   r#   Ś,test_attempt_to_define_unknown_physical_type¦  s    z<TestDefPhysType.test_attempt_to_define_unknown_physical_typec              	   C   s<   t  t” t | jddh” W 5 Q R X | jjdks8tdS )z²
        Test that `def_physical_type` raises an exception when it tries to
        set the physical type of a new unit as the name of an existing
        physical type.
        r   Z	somethingr   N)r-   r.   re   r   ri   rj   r   r    rl   r"   r"   r#   Ś&test_multiple_same_physical_type_names¬  s    z6TestDefPhysType.test_multiple_same_physical_type_namesc                 C   s  d}d}zJz.t  | j|” | jj|ks6td| j W n t	k
rN    Y nX W 5 t j | dd”d” t j |d” X zJz.t  | j|” t
| jj||hksØtdW n t	k
rĄ    Y nX W 5 t j | dd”d” t j |d” t j | dd”d” t j |d” X dS )z{
        Test that calling `def_physical_type` on an existing physical
        type adds a new physical type name.
        z
weird namezstrange nameś Ś_Nz unable to set physical type for z2did not correctly append a new physical type name.)r   Ś_attrname_physical_mappingr   ŚreplaceZ_name_physical_mappingri   rj   r   r    Ś	ExceptionrH   )rm   Z
weird_nameZstrange_namer"   r"   r#   Ś&test_expanding_names_for_physical_type¶  s:    
’
ž
žż
 ’z6TestDefPhysType.test_expanding_names_for_physical_typec              	   C   s(   t  t” t | jd” W 5 Q R X dS )z
        Test that a physical type name already in use cannot be assigned
        for another unit (excluding `"unknown"`).
        r   N)r-   r.   re   r   ri   rj   rl   r"   r"   r#   Śtest_redundant_physical_typeŚ  s    z,TestDefPhysType.test_redundant_physical_typec                 C   s6   t | jD ]}tj|= q
tj|  ” = | jdks2tdS )z-Reset the physical type of unit to "unknown".r   N)Ślistr   r   rk   Z_physical_unit_mappingZ_get_physical_type_idr    )r!   Śnamer"   r"   r#   Ś_undef_physical_typeā  s    
z$TestDefPhysType._undef_physical_typec                 C   sL   | j | jfD ]:}t |”}|dkr,|  |” |jdkstd| dqdS )z
        Remove the definitions of the physical types that were added
        using `def_physical_unit` for testing purposes.
        r   zthe physical type for z., which was added fortesting, was not deleted.N)rj   Śstrange_unitr   r(   ry   r   r    )rm   r!   r   r"   r"   r#   Śteardown_methodź  s    


’zTestDefPhysType.teardown_methodN)Ś__name__Ś
__module__Ś__qualname__r3   r4   rj   rd   rz   rn   ro   ru   rv   Śstaticmethodry   r{   r"   r"   r"   r#   rg   ¢  s   


$
rg   zmethod, expected)ŚtitleZLength)ŚisalphaT)Ś	isnumericF)ŚupperZLENGTHc              	   C   s6   t jtdd tt|  }W 5 Q R X ||ks2tdS )zj
    Test that str methods work for `PhysicalType` instances while issuing
    a deprecation warning.
    zPhysicalType instances©ŚmatchN)r-   Zwarnsr   r?   r   r    )ŚmethodrC   Zresult_of_method_callr"   r"   r#   Ś.test_that_str_methods_work_with_physical_typesł  s    	r   c                	   C   s    t  t” tj W 5 Q R X dS )zē
    Test that a missing attribute raises an `AttributeError`.

    This test should be removed when the deprecated option of calling
    string methods on PhysicalType instances is removed from
    `PhysicalType.__getattr__`.
    N)r-   r.   ŚAttributeErrorr   Z0not_the_name_of_a_str_or_physical_type_attributer"   r"   r"   r#   Ś$test_missing_physical_type_attribute  s    r   Ś
ptype_nameZentropyc                 C   s.   t  | ”}t |”}t |”}||ks*td S )N)r3   r(   ŚpickleŚdumpsŚloadsr    )r   ŚptypeZpklŚotherr"   r"   r#   Śtest_pickling  s    


r   c               	   C   s   t tt tj ” ”stt tt tj”s4ttj ” D ].} tj|  }tt| sZtt	t| |ks>tq>t
jtdd tj W 5 Q R X d S )Nzhas no attributer   )rH   Śdirr   Ś
issupersetrr   Śkeysr    Ś__all__Śhasattrr?   r-   r.   r   Znot_a_valid_physical_type_name)Zpnamer   r"   r"   r#   Ś!test_physical_types_module_access  s    
r   )zŚ__doc__r   r-   Zastropyr   r3   Zastropy.constantsr   Zastropy.unitsr   Zastropy.utils.exceptionsr   r4   ŚcmŚkmŚhZbarnZMpcrd   r!   ZergZAAZphotonZHzŚbyteŚbitZimperialŚmiŚweekŚCŚTŚNZradŚmsr`   ŚsrŚgZmolŚKZdeg_CZdeg_FZdeg_RŚJZPaŚWZkgŚAŚVZOhmŚSŚFZWbŚHŚcdZlmŚlxZ	astrophysZJyŚRŚmiscZcgsZFranklinZ
statampereZBiotZ	abcoulombZbtuŚcalŚyrŚftZCalorieŚLZlbfZkcalZinchŚhrZdimensionless_unscaledZunit_physical_type_pairsŚmarkZparametrizer$   r   r   r   r	   r   r   r   r   rE   r,   re   r2   r1   r5   ŚNotImplementedZoperation_parametersrD   Zunit_with_physical_type_setrI   rL   rM   ZpcZequivalent_unit_pairsrQ   rS   Znonequivalent_unit_pairsrU   Zphysical_type_with_expected_strZ physical_type_with_expected_reprrW   rY   r\   rw   r^   ra   Zinvalid_inputsrf   rg   r   r   r   r   r"   r"   r"   r#   Ś<module>   s  








n
łž
żž
	



































Ņ2
	
ż




÷
	


ü

ū	
žū
 ’

	
W
ž


