o
    h-                     @   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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e dkr^d ndddd Zedgdde dkrsd 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%d)d* Z&e
d+gd,d-d. Z'd/d0 Z(d1d2 Z)d3d4 Z*d5d6 Z+d7d8 Z,G d9d: d:Z-d;d< Z.d=d> Z/dS )?    )datetimetimezone	timedeltaN)	MagicMock)check_figures_equalimage_comparison)StrCategoryConverterUnitData)DateConverterc                   @   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   o/var/www/html/construction_image-detection-poc/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>:   s    z7quantity_converter.<locals>.convert.<locals>.<listcomp>c                    s"   g | ]}t |  jqS r   )r   	get_unitsr   r   r0   axisr3   r   r   r4   <   s    )hasattrr   r   r'   r(   AttributeErrorr   r5   )valuer3   r7   r   r6   r   convert5   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   )r8   r   r'   r(   )r:   r7   r2   r   r   r   default_unitsA   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>K   r"   z$quantity_converter.<locals>.<lambda>)rB   ConversionInterfacer   r;   axisinfor<   )qcr;   r<   r   r   r   quantity_converter/   s   	rJ   zplot_pint.pngmpl20x86_64gQ?)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rcParamsrB   registryr   r'   linspacesubplotssubplots_adjustplotaxhlineaxvlineyaxis	set_unitsxaxisr;   calledrH   r<   )rJ   yxfigaxr   r   r   test_numpy_facadeS   s   

rg   zplot_masked_units.pngTg{Gz?)remove_textrM   rN   c                  C   sL   t dd} t jj| | dk| dk @ d}t|d}t \}}|| d S )NrQ      )maskmeters)r'   rY   maarrayr   rV   rZ   r\   )r   data_maskeddata_masked_unitsre   rf   r   r   r   test_plot_masked_unitsn   s
   
rr   c                 C   sJ   | t jt< t \}}|tddtdd |tddtdd d S )Nrm      r      )rB   rX   r   rV   rZ   set_xlimset_ylim)rJ   re   rf   r   r   r    test_empty_set_limits_with_unitsy   s   
rx   zjpl_bar_units.pngdpirU   )savefig_kwargrM   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     @   rk              dt)bottomrs   jt?)matplotlib.testing.jpl_unitstesting	jpl_unitsregisterDurationkmEpochr   rV   rZ   barrw   r   dayrd   wbre   rf   r   r   r   test_jpl_bar_units   s   *r   zjpl_barh_units.pngc                  C   r{   )Nr   r|   r}   r~   rk   r   r   r   r   r   rR   rs   r   )r   r   r   r   r   r   r   r   rV   rZ   barhrv   r   r   r   r   test_jpl_barh_units   s   *r   c                  C   sp   dd l m  m}  |   tddd}| jd|d}tj|	|d d }tj|	|d d }||ks6J d S )Nr   r   r   r   r|   r   )
r   r   r   r   r   r   rB   rX   get_converterr;   )r   r   jpldt_convjpl_convr   r   r   "test_jpl_datetime_units_consistent   s   r   c                   C   s    t tjg ddtg  d S )Nzdatetime64[ns]dtype)rV   scatterr'   ro   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nanrV   rZ   r   canvasdraw)timesrc   re   rf   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 )  rQ   rk   r~   )r   r1   ir   r   r   r4      s     z-test_errorbar_mixed_units.<locals>.<listcomp>g      ?)days)r'   r   rV   rZ   errorbarr   r   r   )rd   rc   re   rf   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   rZ   r\   )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   rk   r   r   r   allsharexshareyr   r   )rB   rX   r   r'   rY   rV   rZ   r\   ra   r5   r_   r`   )rJ   rd   y1y2re   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   r4          z-test_shared_axis_datetime.<locals>.<listcomp>r~      c                 S   r   )i  r~   r   r   r   r   r   r   r4      r   rk   T)r   rQ   )r   )	rangerV   rZ   r\   r_   r`   r   r   r   )r   r   re   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~   rk   rE   r   r   r   Tr   cd)
rV   rZ   r\   keysvaluesra   r`   r	   r5   _mapping)d1d2re   r   r   r   r   r   test_shared_axis_categorical   s   

r   c            
      C   s4  ddd} t  }t  }t }t \}}|j| |j |ks#J ||  | 	  |j |ks6J |j| t
t |j| W d    n1 sRw   Y  t \}}||  | 	  |j| t \}}	|	|  | 	  t
  |	j| W d    d S 1 sw   Y  d S )Nr~   rk   r   )r   r
   rV   rZ   ra   set_converterr   r\   r   r   pytestraisesRuntimeErrorwarns)
r   str_cat_converterstr_cat_converter_2date_converterfig1r   fig2r   fig3ax3r   r   r   test_explicit_converter   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>   rP   r   r   rt   rk   r   )r   rk   )r   rP   )r   r   )g     <@g     ?@)rB   rX   r   rV   rZ   ra   update_unitsdraw_without_renderingget_xlimr_   get_ylimr]   r\   r'   r   r^   )rJ   re   r   rf   r   r   r   test_empty_default_limits  sH   




r   c                   @   s*   e Zd Zdd ZdddZedd ZdS )	Kernelc                 C   s   t || _d S r   )r'   
asanyarray_array)r   ro   r   r   r   r   =  s   zKernel.__init__Nc                 C   s\   |d ur|| j jkr|d ur|std| j j d| dtj| j |d}|s)|S t|S )NzConverting array from z to z requires a copyr   )r   r   
ValueErrorr'   r+   copy)r   r   r   arrr   r   r   r,   @  s   zKernel.__array__c                 C   s   | j jS r   )r   shaper    r   r   r   r   K  s   zKernel.shape)NN)r-   r.   r/   r   r,   propertyr   r   r   r   r   r   <  s
    
r   c                  C   s   t g d} t|  d S )N)r~   rk   r   r   rQ   )r   rV   r\   )kernelr   r   r   test_plot_kernelP  s   r   c                 C   sl   t jddd\}\}}| d}|| d}|| tj|dfd|fdd||d}|| |  d S )	Nrk   )r   rQ   )nrowsfigsizez2017-01-01T12z	test testr   r   )coordsAcoordsBaxesAaxesB)	rV   rZ   	Timestampr^   r]   mpatchesConnectionPatch
add_artistr   )pdre   r   r   rd   rc   r   r   r   r   test_connection_patch_unitsV  s   



r   )0r   r   r   platformunittest.mockr   matplotlib.pyplotpyplotrV   matplotlib.testing.decoratorsr   r   matplotlib.patchespatchesr   matplotlib.unitsr   rB   matplotlib.categoryr   r	   matplotlib.datesr
   numpyr'   r   r   fixturerJ   machinerg   rr   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sZ    
#


		

	

!*