o
    tBh"                     @   sl  d dl m Z mZmZ d dlZd dlmZ d dlmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlZd dlZG dd dZejdd	 Zed
gdde dkrQd ndddd Zedgdde dkrfd ndddd Zdd Zedgddidddd Zedgddidddd  Zd!d" Zd#d$ Zd%d& Ze
d'gd(d)d* Z d+d, Z!d-d. Z"d/d0 Z#d1d2 Z$dS )3    )datetimetimezone	timedeltaN)	MagicMock)check_figures_equalimage_comparison)UnitDatac                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )Quantityc                 C   s   || _ || _d S N)	magnitudeunits)selfdatar    r   r/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/matplotlib/tests/test_units.py__init__   s   
zQuantity.__init__c                 C   sH   ddddddd}| j |kr|| j |f }t|| j |S t| j| j S )Ni  g?<   g0(?   i  ))hoursseconds)minutesr   )r   r   )feetmiles)r   inches)r   r   )r   r	   r   )r   	new_unitsfactorsmultr   r   r   to   s   
zQuantity.toc                 C   s   t | j|S r
   )getattrr   )r   attrr   r   r   __getattr__      zQuantity.__getattr__c                 C   s,   t | jrt| j| | jS t| j| jS r
   )npiterabler   r	   r   )r   itemr   r   r   __getitem__    s   zQuantity.__getitem__c                 C   s   t | jS r
   )r"   asarrayr   )r   r   r   r   	__array__&   r!   zQuantity.__array__N)__name__
__module____qualname__r   r   r    r%   r'   r   r   r   r   r	      s    
r	   c                  C   sD   t  } dd }dd }t|d| _tdd d| _t|d| _| S )Nc                    sr   t | dr| jS t| r.z
fdd| D W S  ty-    fdd| D  Y S w t|   jS )Nr   c                    s   g | ]}|  jqS r   )r   r   .0v)unitr   r   
<listcomp>5   s    z7quantity_converter.<locals>.convert.<locals>.<listcomp>c                    s"   g | ]}t |  jqS r   )r	   	get_unitsr   r   r+   axisr.   r   r   r/   7   s    )hasattrr   r   r"   r#   AttributeErrorr	   r0   )valuer.   r2   r   r1   r   convert0   s   


z#quantity_converter.<locals>.convertc                 S   s@   t | dr| jS t| r| D ]}t |dr|j  S qd S d S )Nr   )r3   r   r"   r#   )r5   r2   r-   r   r   r   default_units<   s   



z)quantity_converter.<locals>.default_units)side_effectc                 S   s   t j| ddS )Nr   d   )labeldefault_limits)munitsAxisInfo)uar   r   r   <lambda>F   s   z$quantity_converter.<locals>.<lambda>)r=   ConversionInterfacer   r6   axisinfor7   )qcr6   r7   r   r   r   quantity_converter*   s   	rE   zplot_pint.pngFmpl20x86_64g{Gz?)remove_textstyletolc                 C   s   dt jd< | tjt< ttddd}ttddd}t  \}}|jdd	 |	||d
 |j
tdddd |jtdddd |jd |jd | jjsUJ | jjs[J | jjsaJ d S )N)i   zaxes.formatter.limitsr      r      r   g333333?leftztab:bluei g  r   ztab:red)colorx   r   z	tab:greenr   r   )pltrcParamsr=   registryr	   r"   linspacesubplotssubplots_adjustplotaxhlineaxvlineyaxis	set_unitsxaxisr6   calledrC   r7   )rE   yxfigaxr   r   r   test_numpy_facadeN   s   

rc   zplot_masked_units.pngTc                  C   sL   t dd} t jj| | dk| dk @ d}t|d}t \}}|| d S )NrM      )maskmeters)r"   rU   maarrayr	   rR   rV   rX   )r   data_maskeddata_masked_unitsra   rb   r   r   r   test_plot_masked_unitsi   s
   
rm   c                 C   sJ   | t jt< t \}}|tddtdd |tddtdd d S )Nrh      r      )r=   rT   r	   rR   rV   set_xlimset_ylim)rE   ra   rb   r   r   r    test_empty_set_limits_with_unitst   s   
rs   zjpl_bar_units.pngdpirQ   )savefig_kwargrI   c                  C      dd l m  m}  |   | dd}d| j d| j d| j g}d| d| d| g}| jdtddd	d
}t	 \}}|j
|||d ||d|  ||d  d|  g d S )Nr   ET     @   rf              dt)bottomrn   jt?)matplotlib.testing.jpl_unitstesting	jpl_unitsregisterDurationkmEpochr   rR   rV   barrr   r   dayr`   wbra   rb   r   r   r   test_jpl_bar_units}   s   *r   zjpl_barh_units.pngc                  C   rv   )Nr   rw   rx   ry   rf   rz   r{   r|   r}   r~   rN   rn   r   )r   r   r   r   r   r   r   r   rR   rV   barhrq   r   r   r   r   test_jpl_barh_units   s   *r   c                   C   s    t tjg ddtg  d S )Nzdatetime64[ns]dtype)rR   scatterr"   rj   r   r   r   r   test_empty_arrays   s    r   c                  C   sR   t jdddd} t jt| td}t j|d< t \}}|| | |j	  d S )Nz2005-02z2005-03zdatetime64[D]r   r   )
r"   arangelenfloatnanrR   rV   r   canvasdraw)timesr_   ra   rb   r   r   r   test_scatter_element0_masked   s   
r   c                  C   sF   t d} dd | D }t \}}|| |tdd |j  d S )N
   c                 S   s    g | ]}t d d|d d qS )  rM   rf   ry   )r   r,   ir   r   r   r/      s     z-test_errorbar_mixed_units.<locals>.<listcomp>g      ?)days)r"   r   rR   rV   errorbarr   r   r   )r`   r_   ra   rb   r   r   r   test_errorbar_mixed_units   s
   
r   png)
extensionsc                 C   sH   G dd dt }|  |ddddd | t ddddd d S )Nc                   @   s   e Zd ZdS )ztest_subclass.<locals>.subdateN)r(   r)   r*   r   r   r   r   subdate   s    r   i  ry   r   o)r   rV   rX   )fig_testfig_refr   r   r   r   test_subclass   s   r   c                 C   s4  | t jt< ttdddd}ttdddd}ttdddd}tjddd	d	d
\}\}}||| ||| |j	 |j	   krMdksPJ  J |j
	 |j
	   kradksdJ  J |jd |j
d |j	 |j	   krdksJ  J |j
	 |j
	   krdksJ  J d S )Nr   ry   r   r   rf   r   rz   r|   allsharexshareyr   r   )r=   rT   r	   r"   rU   rR   rV   rX   r]   r0   r[   r\   )rE   r`   y1y2ra   ax1ax2r   r   r   test_shared_axis_quantity   s   
(((,r   c                  C   s   dd t ddD } dd t ddD }tjdddd\}\}}||  || |jttd	d
 |jjttd	d
ksBJ d S )Nc                 S      g | ]}t d |dtjdqS )r   ry   tzinfor   r   utcr   r   r   r   r/          z-test_shared_axis_datetime.<locals>.<listcomp>ry      c                 S   r   )i  ry   r   r   r   r   r   r   r/      r   rf   T)r   rM   )r   )	rangerR   rV   rX   r[   r\   r   r   r   )r   r   ra   r   r   r   r   r   test_shared_axis_datetime   s   

r   c                  C   s   ddd} ddd}t jddddd\}\}}||  |   || |  |jtdd	g d|j j	 v sAJ d S )
Nry   rf   )r@   r   rz   r|   Tr   cd)
rR   rV   rX   keysvaluesr]   r\   r   r0   _mapping)d1d2ra   r   r   r   r   r   test_shared_axis_categorical   s   

r   c              	   C   s  | t jt< t \}}|jtdgd |  | dks!J |j	tdgd |  |
 dks7J t \}}|d |ttdddttdddd	 |  | d
kscJ |
 dkskJ t \}}|d |ttdddttdddd	 |  | dksJ |
 dksJ t \}}|jtdgd |d |  | dksJ |
 dksJ t \}}|j	tdgd |d |  |
 dksJ | dksJ d S )Nr   r   r9   rL   r   rz   ro   rf   r   )r   rf   )r   rL   )r   r|   )g     <@g     ?@)r=   rT   r	   rR   rV   r]   update_unitsdraw_without_renderingget_xlimr[   get_ylimrY   rX   r"   r   rZ   )rE   ra   r   rb   r   r   r   test_empty_default_limits   sH   




r   )%r   r   r   platformunittest.mockr   matplotlib.pyplotpyplotrR   matplotlib.testing.decoratorsr   r   matplotlib.unitsr   r=   matplotlib.categoryr   numpyr"   pytestr	   fixturerE   machinerc   rm   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sL    

#


		

	

