o
    liZ$                     @   s  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e dkrPd ndddd Zedgdde dkred 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$G d3d4 d4Z%d5d6 Z&dS )7    )datetimetimezone	timedeltaN)	MagicMock)check_figures_equalimage_comparison)UnitDatac                   @   s<   e Zd Zd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   Y/home/ubuntu/SoloSpeech/.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| jS r
   )r	   r   r   r   r   r   r   __copy__      zQuantity.__copy__c                 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   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>8   s    z7quantity_converter.<locals>.convert.<locals>.<listcomp>c                    s"   g | ]}t |  jqS r   )r	   	get_unitsr   r   r.   axisr1   r   r   r2   :   s    )hasattrr   r   r%   r&   AttributeErrorr	   r3   )valuer1   r5   r   r4   r   convert3   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   )r6   r   r%   r&   )r8   r5   r0   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>I   r    z$quantity_converter.<locals>.<lambda>)r@   ConversionInterfacer   r9   axisinfor:   )qcr9   r:   r   r   r   quantity_converter-   s   	rH   zplot_pint.pngmpl20x86_64g{Gz?)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xaxisr9   calledrF   r:   )rH   yxfigaxr   r   r   test_numpy_facadeQ   s   

re   zplot_masked_units.pngT)remove_textrK   rL   c                  C   sL   t dd} t jj| | dk| dk @ d}t|d}t \}}|| d S )NrO      )maskmeters)r%   rW   maarrayr	   rT   rX   rZ   )r   data_maskeddata_masked_unitsrc   rd   r   r   r   test_plot_masked_unitsl   s
   
rp   c                 C   sJ   | t jt< t \}}|tddtdd |tddtdd d S )Nrk      r      )r@   rV   r	   rT   rX   set_xlimset_ylim)rH   rc   rd   r   r   r    test_empty_set_limits_with_unitsw   s   
rv   zjpl_bar_units.pngdpirS   )savefig_kwargrK   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     @   ri              dt)bottomrq   jt?)matplotlib.testing.jpl_unitstesting	jpl_unitsregisterDurationkmEpochr   rT   rX   barru   r   dayrb   wbrc   rd   r   r   r   test_jpl_bar_units   s   *r   zjpl_barh_units.pngc                  C   ry   )Nr   rz   r{   r|   ri   r}   r~   r   r   r   rP   rq   r   )r   r   r   r   r   r   r   r   rT   rX   barhrt   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)rT   scatterr%   rm   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nanrT   rX   r   canvasdraw)timesra   rc   rd   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 )  rO   ri   r|   )r   r/   ir   r   r   r2      s     z-test_errorbar_mixed_units.<locals>.<listcomp>g      ?)days)r%   r   rT   rX   errorbarr   r   r   )rb   ra   rc   rd   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  r|   r   o)r   rX   rZ   )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   r|   r   r   ri   r   r}   r   allsharexshareyr   r   )r@   rV   r	   r%   rW   rT   rX   rZ   r_   r3   r]   r^   )rH   rb   y1y2rc   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   r|   tzinfor   r   utcr   r   r   r   r2          z-test_shared_axis_datetime.<locals>.<listcomp>r|      c                 S   r   )i  r|   r   r   r   r   r   r   r2      r   ri   T)r   rO   )r   )	rangerT   rX   rZ   r]   r^   r   r   r   )r   r   rc   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 )
Nr|   ri   )rC   r   r}   r   Tr   cd)
rT   rX   rZ   keysvaluesr_   r^   r   r3   _mapping)d1d2rc   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   r<   rN   r   r}   rr   ri   r   )r   ri   )r   rN   )r   r   )g     <@g     ?@)r@   rV   r	   rT   rX   r_   update_unitsdraw_without_renderingget_xlimr]   get_ylimr[   rZ   r%   r   r\   )rH   rc   r   rd   r   r   r   test_empty_default_limits   sH   




r   c                   @   s(   e Zd Zdd Zdd Zedd ZdS )Kernelc                 C   s   t || _d S r
   )r%   
asanyarray_array)r   rm   r   r   r   r     s   zKernel.__init__c                 C   s   | j S r
   )r   r   r   r   r   r*     s   zKernel.__array__c                 C   s   | j jS r
   )r   shaper   r   r   r   r     s   zKernel.shapeN)r+   r,   r-   r   r*   propertyr   r   r   r   r   r     s
    r   c                  C   s   t g d} t|  d S )N)r|   ri   r}   r   rO   )r   rT   rZ   )kernelr   r   r   test_plot_kernel  s   r   )'r   r   r   platformunittest.mockr   matplotlib.pyplotpyplotrT   matplotlib.testing.decoratorsr   r   matplotlib.unitsr   r@   matplotlib.categoryr   numpyr%   pytestr	   fixturerH   machinere   rp   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sP    
#


		

	

*