o
    iS                     @   s0  d dl 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Zd dlZG dd dZejdd Ze	d	gd
de dkrGd ndddd Ze	dgdde dkr\d 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ed$gd%d&d' ZdS )(    )datetimeN)	MagicMock)check_figures_equalimage_comparisonc                   @   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   V/var/www/edux/Edux_v2/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>4   s    z7quantity_converter.<locals>.convert.<locals>.<listcomp>c                    s"   g | ]}t |  jqS r   )r   	get_unitsr   r   r(   axisr+   r   r   r,   6   s    )hasattrr   r   r   r    AttributeErrorr   r-   )valuer+   r/   r   r.   r   convert/   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	   )r0   r	   r   r    )r2   r/   r*   r   r   r   default_units;   s   



z)quantity_converter.<locals>.default_units)side_effectc                 S   s   t j| dS )N)label)munitsAxisInfo)uar   r   r   <lambda>E   s    z$quantity_converter.<locals>.<lambda>)r7   ConversionInterfacer   r3   axisinfor4   )qcr3   r4   r   r   r   quantity_converter)   s   	r?   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rcParamsr7   registryr   r   linspacesubplotssubplots_adjustplotaxhlineaxvlineyaxis	set_unitsxaxisr3   calledr=   r4   )r?   yxfigaxr   r   r   test_numpy_facadeL   s   

r]   zplot_masked_units.pngTc                  C   sL   t dd} t jj| | dk| dk @ d}t|d}t \}}|| d S )NrG      )maskmeters)r   rO   maarrayr   rL   rP   rR   )r   data_maskeddata_masked_unitsr[   r\   r   r   r   test_plot_masked_unitsg   s
   
rg   c                 C   sJ   | t jt< t \}}|tddtdd |tddtdd d S )Nrb      r      )r7   rN   r   rL   rP   set_xlimset_ylim)r?   r[   r\   r   r   r    test_empty_set_limits_with_unitsr   s   
rm   zjpl_bar_units.pngdpirK   )savefig_kwargrC   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     @   r`              dt)bottomrh   jt?)matplotlib.testing.jpl_unitstesting	jpl_unitsregisterDurationkmEpochr   rL   rP   barrl   r	   dayrZ   wbr[   r\   r   r   r   test_jpl_bar_units{   s   *r   zjpl_barh_units.pngc                  C   rp   )Nr   rq   rr   rs   r`   rt   ru   rv   rw   rx   rH   rh   r{   )r|   r}   r~   r   r   r   r   r   rL   rP   barhrk   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)rL   scatterr   rd   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nanrL   rP   r   canvasdraw)timesrY   r[   r\   r   r   r   test_scatter_element0_masked   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  rs   r   o)r   rP   rR   )fig_testfig_refr   r   r   r   test_subclass   s   r   )r   platformunittest.mockr   matplotlib.pyplotpyplotrL   matplotlib.testing.decoratorsr   r   matplotlib.unitsr	   r7   numpyr   pytestr   fixturer?   machiner]   rg   rm   r   r   r   r   r   r   r   r   r   <module>   s@    

"


		


	