B
    Afxa                 @   s  d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl	Z	d dl
mZ d dlmZmZ ddlmZmZmZmZmZ dZed	d
e  d d d d Zedd
e  d d ZedZG dd de jZdd Zd1ddZd2ddZe	jj e ddZ!e	jj eddZ"dd Z#d d! Z$d"d# Z%d$d% Z&e	jj e d&dZ'e	jj ed'dZ(e	jj e d(dZ)e	jj ed)dZ*e	j+d*d+d, e,ej-d- D Z.e	j+d.d/d0gZ/dS )3    N)LooseVersion)Number)Quantity)ndarraynp   )	HAS_BABEL	HAS_NUMPYHAS_NUMPY_ARRAY_FUNCTIONHAS_UNCERTAINTIES	NUMPY_VERz(([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)z<Quantity\(\s*z(?P<magnitude>%s)z\s*,\s*z'(?P<unit>.*)'z\s*z\)>z\sz(?P<unit>.*)z<Unit\((.*)\)>c                   s   e Zd Z fddZ  ZS )PintOutputCheckerc          	      sl  t  |||}|r|S yt|t|kr.dS W n tk
rD   Y nX xttfD ]}yx||dd }||dd }t	|d }t	|d }	t
||	 t
|d krdS |d |d krdS dS  tk
r   Y qPX qPW d}
xhtfD ]^}yB|d	|\}}|
|7 }
|d	|\}}|
|7 }
||kr6dS W q tk
rN   Y qX qW |
rh| |||S dS )
NTz\\ 	magnitudei  FZunitr   )supercheck_outputeval	Exception_q_re_sq_rematchreplace	groupdictfloatabs_unit_resubn)selfZwantZgotZoptionflagsZcheckZregexZ
parsed_gotZparsed_wantZv1Zv2ZcntZtmpZtemp)	__class__ 5lib/python3.7/site-packages/pint/testsuite/helpers.pyr   )   sF    


zPintOutputChecker.check_output)__name__
__module____qualname__r   __classcell__r    r    )r   r!   r   (   s   r   c             C   s   t | trFt |trF|| }| j|jks6t|d | j|j }}nrt | trz| jsbt|d | d} | j| }}n>t |tr|jst|d |d}| |j }}n
| | }}||fS )Nz Units are not equal.z  The first is not dimensionless.r   z! The second is not dimensionless.)
isinstancer   toZunitsAssertionErrorr   Zdimensionless)firstsecondmsgm1m2r    r    r!   _get_comparable_magnitudes[   s    





r.   c             C   s   |d krd| |f }t | ||\}}|d||f 7 }t|tsHt|tr\tjj|||d n|t|tsttt	 d S t|tstt	 d S t
|rt
|st|n.t
|rt
|st|n||kst|d S )NzComparing %r and %r. z (Converted to %r and %r))err_msg)r.   r&   r   r   testingZassert_array_equalr   warningswarnRuntimeWarningmathisnanr(   )r)   r*   r+   r,   r-   r    r    r!   assert_quantity_equaln   s"    





r6   Hz>c             C   s  |d krXyd| |f }W n> t k
rV   yd| |f }W n tk
rP   d}Y nX Y nX t| ||\}}|d||f 7 }t|tst|trtjj|||||d nt|tst	
t d S t|tst	
t d S t|rt|st|nt|rt|st|nvt|r6t|st|nTt|rXt|st|n2t|| t|tt|t| |kst|d S )NzComparing %r and %r. zComparing %s and %s. Z	Comparingz (Converted to %r and %r))rtolatolr/   )	TypeErrorr   r.   r&   r   r   r0   Zassert_allcloser   r1   r2   r3   r4   r5   r(   Zisinfr   max)r)   r*   r8   r9   r+   r,   r-   r    r    r!   assert_quantity_almost_equal   s6    




r<   zRequires NumPy)reasonz#Requires NumPy not to be installed.c               C   s"   t stjdS tjjt ddS )NzRequires NumPyz2Requires __array_function__ protocol to be enabled)r=   )r	   pytestmarkskipskipifr
   r    r    r    r!    requires_array_function_protocol   s
    rB   c               C   s    t stjdS tjjtddS )NzRequires NumPyzBRequires __array_function__ protocol to be unavailable or disabled)r=   )r	   r>   r?   r@   rA   r
   r    r    r    r!   $requires_not_array_function_protocol   s
    rC   c             C   s2   t stjdS tjjttt| k  d|  dS )NzRequires NumPyzRequires NumPy < %s)r=   )r	   r>   r?   r@   rA   r   r   )versionr    r    r!   requires_numpy_previous_than   s
    rE   c             C   s2   t stjdS tjjttt| k d|  dS )NzRequires NumPyzRequires NumPy >= %s)r=   )r	   r>   r?   r@   rA   r   r   )rD   r    r    r!   requires_numpy_at_least   s
    rF   z!Requires Babel with units supportz"Requires Babel not to be installedzRequires Uncertaintiesz+Requires Uncertainties not to be installed.)Zprotocolc             C   s   g | ]
}|fqS r    r    ).0pr    r    r!   
<listcomp>   s    rI      Z	check_allFT)N)r7   r   N)0Zdoctestr4   picklerer1   Zdistutils.versionr   Znumbersr   r>   Zpintr   Zpint.compatr   r   compatr   r	   r
   r   r   Z
_number_recompiler   r   r   ZOutputCheckerr   r.   r6   r<   r?   rA   Zrequires_numpyZrequires_not_numpyrB   rC   rE   rF   Zrequires_babelZrequires_not_babelZrequires_uncertaintiesZrequires_not_uncertaintiesZparametrizerangeZHIGHEST_PROTOCOLZ	allprotosZcheck_all_boolr    r    r    r!   <module>   sL   
3

#
				

