U
    \	a~+                     @   s  d Z ddlZddlZddlmZ ddlmZ ddl	m
Z ddlmZ G dd dZG dd dZG d	d
 d
Zejdd ZejejejgZdddgZG dd dZG dd dZdd ZG dd dZG dd dZG dd dZejdedgddd  Z d!d" Z!dS )#z#Catch all for categorical functions    N)Axes)check_figures_equalc                	   @   s   e Zd Zddgdgffddgdgffdddd	d
dgdddddgffgZee \ZZejj	deeddd Z
dd ZddejfdddgfdddgfgZee \ZZejj	deeddd Zejj	deeddd  Zd!S )"TestUnitDatasinglehello worldr   unicode   Здравствуйте мирmixedAznp.nanBz3.14   мир            z
data, locsidsc                 C   s:   t |}t|j |ks tt|j |ks6td S N)catUnitDatalist_mappingkeysAssertionErrorvalues)selfdatalocsunit r   B/tmp/pip-unpacked-wheel-wjyw_3jo/matplotlib/tests/test_category.py	test_unit   s    
zTestUnitData.test_unitc                 C   s   ddg}ddg}dddg}ddddg}ddddg}t |}t|j |ksRtt|j |ksht|| t|j |kstt|j |kstd S )	Nadr   r   ber   r   )r   r   r   r   r   r   r   update)r   r   r   Zdata_updateZunique_dataZupdated_locsr   r   r   r    test_update   s    


zTestUnitData.test_update)numberQ	@nanr   r)      z
mixed typefdatac              	   C   s$   t t t| W 5 Q R X d S r   )pytestraises	TypeErrorr   r   )r   r,   r   r   r    test_non_string_fails-   s    z"TestUnitData.test_non_string_failsc              	   C   s,   t  }tt || W 5 Q R X d S r   )r   r   r-   r.   r/   r&   )r   r,   Zunitdatar   r   r    test_non_string_update_fails2   s    z)TestUnitData.test_non_string_update_failsN)__name__
__module____qualname__
test_caseszipr   r   r-   markparametrizer!   r'   npr*   failing_test_casesfidsr,   r0   r1   r   r   r   r    r      s&   


 

r   c                   @   s   e Zd Zdd ZdS )FakeAxisc                 C   s
   || _ d S r   )units)r   r=   r   r   r    __init__:   s    zFakeAxis.__init__N)r2   r3   r4   r>   r   r   r   r    r<   9   s   r<   c                   @   s2  e Zd ZdZddgfddgfdddd	gfd
ddgfdddddddddddddddddddd d!d"d#d$d%d&d'gfgZee \ZZd(d)dej	gfd*d+d,gfgZ
ee
 \ZZejd-d.d/d0 Zejjd1eed2d3d4 Zejjd5d6d7gddgd2d8d9 Zd:d; Zd<d= Zejjd>eed2d?d@ ZdAdB ZdCdD ZdES )FTestStrCategoryConverterz
    Based on the pandas conversion and factorization tests:

    ref: /pandas/tseries/tests/test_converter.py
         /pandas/tests/test_algos.py:TestFactorize
    r   r   asciir   r   r"   r$   czinteger string12zsingle + values>10r
   r   CDEFGHIJKLMNOPQRSTUVWXYZr	   r)   string integer42*   T)Zautousec                 C   s$   t  | _t  | _t| j| _d S r   )r   ZStrCategoryConverterccr   r   r<   ax)r   requestr   r   r    	mock_axisU   s    

z"TestStrCategoryConverter.mock_axisvalsr   c                 C   s,   t j| j|| jj| jtt| d S r   )	r9   testingassert_allcloser_   convertr`   r=   rangelen)r   rc   r   r   r    test_convert\   s
    
z%TestStrCategoryConverter.test_convertvaluehir   c                 C   s    | j || j| jdkstd S )Nr   )r_   rf   r   r`   r   )r   rj   r   r   r    test_convert_one_stringb   s    z0TestStrCategoryConverter.test_convert_one_stringc                 C   s.   | j d| j| j}tj|tdg d S )N        )r_   rf   r   r`   r9   rd   re   array)r   actualr   r   r    test_convert_one_numberf   s    z0TestStrCategoryConverter.test_convert_one_numberc                 C   sF   t jdddgtd}| j|| j| j}t j|t dddg d S )Nr   r   r   )Zdtype      ?       @g      @)	r9   rn   floatr_   rf   r   r`   rd   re   )r   r   ro   r   r   r    test_convert_float_arrayj   s    z1TestStrCategoryConverter.test_convert_float_arrayfvalsc              	   C   s.   t t | j|| j| j W 5 Q R X d S r   )r-   r.   r/   r_   rf   r   r`   )r   ru   r   r   r    test_convert_failo   s    z*TestStrCategoryConverter.test_convert_failc                 C   s:   | j | j| j}t|jtjs$tt|j	tj
s6td S r   )r_   Zaxisinfor   r`   
isinstanceZmajlocr   StrCategoryLocatorr   ZmajfmtStrCategoryFormatter)r   axisr   r   r    test_axisinfot   s    z&TestStrCategoryConverter.test_axisinfoc                 C   s"   t | jdg| jtjstd S )Nr"   )rw   r_   Zdefault_unitsr`   r   r   r   r   r   r   r    test_default_unitsy   s    z+TestStrCategoryConverter.test_default_unitsN)r2   r3   r4   __doc__r5   r6   r   r   r9   infr:   r;   fvaluesr-   fixturerb   r7   r8   ri   rl   rp   rt   rv   r{   r}   r   r   r   r    r?   >   sX   
                	





r?   c                   C   s   t   S r   )pltfiguresubplotsr   r   r   r    r`   }   s    r`   scatterplotbarc                   @   s.   e Zd Zdd Zejjdeeddd Z	dS )TestStrCategoryLocatorc                 C   sT   ddddddddd	d
dg}t dd |D }t |j}tj|d d | d S )Nr   r   r   r   r               	   
   c                 S   s   g | ]}t |qS r   )str).0jr   r   r    
<listcomp>   s     zBTestStrCategoryLocator.test_StrCategoryLocator.<locals>.<listcomp>)r   r   rx   r   r9   rd   assert_array_equalZtick_values)r   r   r   ticksr   r   r    test_StrCategoryLocator   s    z.TestStrCategoryLocator.test_StrCategoryLocatorplotterr   c                 C   s6   ||dddgdddg t j|jj td d S )Nr   r   r   r"   r$   rA   )r9   rd   r   yaxismajorlocatorrg   r   r`   r   r   r   r    test_StrCategoryLocatorPlot   s    z2TestStrCategoryLocator.test_StrCategoryLocatorPlotN)
r2   r3   r4   r   r-   r7   r8   	PLOT_LISTPLOT_IDSr   r   r   r   r    r      s   r   c                   @   sx   e Zd ZddddgfdddgfgZee \ZZejj	deed	d
d Z
ejj	deed	ejj	deed	dd ZdS )TestStrCategoryFormatterr@   helloworldrk   r      Здравствуйте   приветydatar   c                 C   sP   t |}t |j}t|D ],\}}||||ks8t||d |kstqd S r   )r   r   ry   r   	enumerater   )r   r`   r   r   labelsir#   r   r   r    test_StrCategoryFormatter   s
    
z2TestStrCategoryFormatter.test_StrCategoryFormatterr   c                 C   sZ   ||t t|| t|D ]\}}|jj||kstq|jj|d dksVtd S )Nr    )rg   rh   r   r   r   	formatterr   )r   r`   r   r   r   r#   r   r   r    test_StrCategoryFormatterPlot   s    z6TestStrCategoryFormatter.test_StrCategoryFormatterPlotN)r2   r3   r4   r5   r6   r   Zcasesr-   r7   r8   r   r   r   r   r   r   r   r    r      s   

r   c                    s   t tt|}tj  |  fdd|D }|dd |D ksJtt  jj	
 dd |D ksltt  jj	 |kstd S )Nc                    s   g | ]} j ||qS r   )r   r   )r   r   rz   r   r    r      s     zaxis_test.<locals>.<listcomp>c                 S   s   g | ]}t j|qS r   )r   ry   Z_textr   lr   r   r    r      s     c                 S   s   g | ]}|qS r   r   r   r   r   r    r      s     )r   rg   rh   r9   rd   r   Zget_majorticklocsr   r=   r   r   r   )rz   r   r   Zgraph_labelsr   r   r    	axis_test   s    "r   c                   @   sr   e Zd Zddddgfddddgfd	edddgfgZee \ZZe	j
jd
eede	j
jdeeddd ZdS )TestPlotBytesstring listr"   r$   rA   
bytes list   a   b   cbytes ndarrayr   r   bdatac                 C   s,   t dddg}|||| t|j| d S Nr   r   r   r9   rn   r   xaxis)r   r`   r   r   countsr   r   r    test_plot_bytes   s    zTestPlotBytes.test_plot_bytesN)r2   r3   r4   r9   rn   Zbytes_casesr6   Z	bytes_ids
bytes_datar-   r7   r8   r   r   r   r   r   r   r    r      s   r   c                	   @   s   e Zd Zddddgfdedddgfdddd	gfd
eddd	gfgZee \ZZe	j
jdeede	j
jdeeddd ZdS )TestPlotNumliker   rB   Z113zstring ndarrayr      1s   11   3r   r   r   ndatac                 C   s,   t dddg}|||| t|j| d S r   r   )r   r`   r   r   r   r   r   r    test_plot_numlike   s    z!TestPlotNumlike.test_plot_numlikeN)r2   r3   r4   r9   rn   Znumlike_casesr6   Znumlike_idsZnumlike_datar-   r7   r8   r   r   r   r   r   r   r    r      s   r   c                   @   sh  e Zd Zejjdeeddd Zej	dd Z
ejdejjdeeddd	 Zejdejjdeedd
d Zejdejjdeeddd Zejjdeeddd ZdddgfdddgfdddgfddejgfgZee \ZZejejejejejjdgZejdeejjdeeddd Zejdeejjdeeddd  Zd!S )"TestPlotTypesr   r   c                 C   s(   ddg}|||ddg t |j| d S )Nr   r   r   r   )r   r   )r   r`   r   wordsr   r   r    test_plot_unicode   s    zTestPlotTypes.test_plot_unicodec                 C   s4   dddg| _ dddg| _ddd	g| _dd
dg| _d S )Nr   Zhappyr   r   r   r   PythonisZfunr   r   )xxyyyxr|   r   r   r    	test_data   s    zTestPlotTypes.test_datar   c                 C   s"   ||| j | j t|j| j  d S r   )r   r   r   r   r   r`   r   r   r   r   r    test_plot_xaxis   s    zTestPlotTypes.test_plot_xaxisc                 C   s"   ||| j | j t|j| j d S r   )r   r   r   r   r   r   r   r    test_plot_yaxis   s    zTestPlotTypes.test_plot_yaxisc                 C   s0   ||| j | j t|j| j  t|j| j d S r   )r   r   r   r   r   r   r   r   r    test_plot_xyaxis   s    zTestPlotTypes.test_plot_xyaxisc                 C   st   ||ddgddg ||dddgdddg ||dddgdddg t |jddddg t |jddddddg d S )Nr"   r$   r%   gr#   frA   )r   r   r   r   r   r   r    test_update_plot   s
    zTestPlotTypes.test_update_plotr	   r
   r)   znumber integerrB   r   r\   r]   r^   missingZ12)Zmarksxdatac              	   C   s*   t t |||ddg W 5 Q R X d S )Nr   r   r-   r.   r/   r   r`   r   r   r   r   r    test_mixed_type_exception  s    z'TestPlotTypes.test_mixed_type_exceptionc              	   C   s>   t t* ||ddgddg |||ddg W 5 Q R X d S )Nr   r   r   r   r   r   r   r   r     test_mixed_type_update_exception  s    z.TestPlotTypes.test_mixed_type_update_exceptionN)r2   r3   r4   r-   r7   r8   r   r   r   r   r   Zusefixturesr   r   r   r   r9   r*   r:   r6   r;   r   r   r   r   paramr   ZxfailZplottersr   r   r   r   r   r    r      s<   








r   defaultZpng)
extensionsc                 C   s   ddl m } |ddd}|ddd}|ddd}|ddd}|  }| }t||gi td d dfD ]h\}	}
|	j||gd	d
gf|
 |	jj}|	jj}|	j||gd	d
gf|
 ||	jjkst||	jjksftqfd S )Nr   )datetimei  r   r   r   r   )ZxunitsZyunitsZV1ZV2)	r   r   r6   dictr   r   r=   r   r   )Zfig_testZfig_refr   t0t1t2t3Zax_testZax_refr`   kwargsZx_unitsZy_unitsr   r   r    test_overriding_units_in_plot  s     r   c                  C   sZ   t  \} }|dddddg\}}}|jdks4ttj|ddddddddddg
 d S )	Nr"   r$   rA   ff)r   rr   rm   rq   )r   r   histshaper   r9   rd   re   )Zfigr`   nZbinsZpatchesr   r   r    	test_hist,  s    r   )"r~   r-   Znumpyr9   Zmatplotlib.axesr   Zmatplotlib.pyplotZpyplotr   Zmatplotlib.categorycategoryr   Zmatplotlib.testing.decoratorsr   r   r<   r?   r   r`   r   r   r   r   r   r   r   r   r   r   r   r7   styler   r   r   r   r   r    <module>   s.   .?


A

