
    G8cj,                     "   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ  eddgd      dd       ZegZd	gZd
 Zej                   j#                  dee      d        Zej                   j#                  dee      d        Zej                   j#                  dee      d        Zej                   j#                  dee      d        Zej                   j#                  dee      d        Zd Zd Zd Zd Zd Z G d d      Zy)    N_preprocess_data)Axes)check_figures_equalxyreplace_nameslabel_namerc           
      H    dt        |      dt        |      d|d|d|
S Nzx: z, y: z, ls: z, w: z	, label: listaxr   r   lslabelws         G/usr/lib/python3/dist-packages/matplotlib/tests/test_preprocess_data.py	plot_funcr      s!     	Qa"a( )    r   c                     d } d }d }d } t        ddg      |         t        ddg      |        t        ddg      |       t        j                  t              5   t        g d      |       d	d	d	        t        g d	
      |         t        g d	
      |        t        g d	
      |        t        g d	
      |       t        j                  t              5   t        d      |        d	d	d	       t        j                  t              5   t        d      |       d	d	d	       y	# 1 sw Y   xY w# 1 sw Y   JxY w# 1 sw Y   y	xY w)z.Test decorator invocations -> no replacements.c                      y N )r   r   r   s      r   funcz%test_compiletime_checks.<locals>.func        r   c                      y r   r   )r   r   r   argss       r   	func_argsz*test_compiletime_checks.<locals>.func_args!   r   r   c                      y r   r   )r   r   r   kwargss       r   func_kwargsz,test_compiletime_checks.<locals>.func_kwargs"   r   r   c                       y r   r   )r   r"   s     r   func_no_ax_argsz0test_compiletime_checks.<locals>.func_no_ax_args#   r   r   r   r   r
   )r   r   zNr	   r'   r   )r   pytestraisesAssertionError)r   r    r#   r%   s       r   test_compiletime_checksr,      s:    (-. /C:.t4.C:.{;.C:.y9 
~	& C77	BC
 9248>8248C8248E8248I 
~	& 0)S)$/0 
~	& 5)S))45 5C C0 05 5s$   "D4$E E4D= E	Er   )idsc                      | ddd      dk(  sJ  | ddd      dk(  sJ  | dddd      dk(  sJ  | dddd	      d
k(  sJ  | dddd      dk(  sJ  | dddd	      d
k(  sJ y)z%Test without data -> no replacements.Nr   r   z.x: ['x'], y: ['y'], ls: x, w: xyz, label: None)r   r    )r   z*x: ['x'], y: ['y'], ls: x, w: xyz, label: textz.x: ['x'], y: ['y'], ls: x, w: xyz, label: text)r   r   r   r   )r   s    r   test_function_call_without_datar1   >   s     sC <= > =$<= > =sCr*89 : 9sCv.<= > =2.89 : 962<= > =r   c                 d    ddd} | d|j                         |j                               dk(  sJ y)z8Tests with dict input, unpacking via preprocess_pipeline      )abNz4x: ['a', 'b'], y: [1, 2], ls: x, w: xyz, label: None)keysvaluesr   datas     r   "test_function_call_with_dict_inputr;   O   s;     Dtyy{DKKM2BC D Cr   c                     ddgddgdd} | ddd	|
      dk(  sJ  | ddd	|      dk(  sJ  | ddd	d|      dk(  sJ  | ddd	d|      dk(  sJ  | ddd	d|      dk(  sJ  | ddd	d|      dk(  sJ y)zCTest with dict data -> label comes from the value of 'x' parameter.r3   r4      	   NOTr5   r6   r   Nr5   r6   r:   -x: [1, 2], y: [8, 9], ls: x, w: xyz, label: br   r   r:   r/   r   r:   ,x: [1, 2], y: [8, 9], ls: x, w: xyz, label: r0   0x: [1, 2], y: [8, 9], ls: x, w: xyz, label: textr   r   r   r:   r   r9   s     r   !test_function_call_with_dict_datarH   W   s     Qq!f51DsCd+;< = <$/;< = <sCr5:; < ;sCvD9>? @ ?2D9:; < ;6=>? @ ?r   c                     ddgdd} | ddd|      d	k(  sJ  | ddd|
      d	k(  sJ  | dddd|      dk(  sJ  | dddd|      dk(  sJ  | dddd|      dk(  sJ  | dddd|      dk(  sJ y)zETest the case that one var is not in data -> half replaces, half keptr3   r4   r?   )r5   r   Nr5   r6   rA   z,x: [1, 2], y: ['b'], ls: x, w: xyz, label: brC   r/   rD   z+x: [1, 2], y: ['b'], ls: x, w: xyz, label: r0   z/x: [1, 2], y: ['b'], ls: x, w: xyz, label: textrG   r   r9   s     r   -test_function_call_with_dict_data_not_in_datarJ   i   s     Qe$DsCd+:; < ;$/:; < ;sCr59: ; :sCvD9=> ? >2D99: ; :6==> ? >r   c                    |j                  t        j                  ddgt        j                        t        j                  ddgt        j                        ddgd      } | dd	d
|      dk(  sJ  | dd	d
|      dk(  sJ  | dd	d
d|      dk(  sJ  | dd	d
d|      dk(  sJ  | dd	d
d|      dk(  sJ  | dd	d
d|      dk(  sJ y)zDTest with pandas dataframe -> label comes from ``data["col"].name``.r3   r4   )dtyper=   r>   r?   r@   Nr5   r6   rA   rB   rC   r/   rD   rE   r0   rF   rG   )	DataFramenparrayint32)r   pdr:   s      r   #test_function_call_with_pandas_datarR   {   s    <<bhh1vRXX> hh1vRXX>$en. /D sCd+;< = <$/;< = <sCr5:; < ;sCvD9>? @ ?2D9:; < ;6=>? @ ?r   c                     ddgddgdd} t        d      dd       } |d
ddd	|       dk(  sJ  |d
ddd	|       dk(  sJ  |d
ddd	d|       dk(  sJ  |d
ddd	d|       dk(  sJ  |d
ddd	d|       dk(  sJ  |d
ddd	d|       dk(  sJ y
)zETest without a "replace_names" argument, all vars should be replaced.r3   r4   r=   r>   xyz)r5   r6   r   r   r(   r   Nc           
      H    dt        |      dt        |      d|d|d|
S r   r   r   s         r   func_replace_allz8test_function_call_replace_all.<locals>.func_replace_all   !     GT!Wb!U, 	,r   r5   r6   )r   r:   rB   )r   r   r   r:   r/   )r   r   r:   rE   r0   rF   )r   r   r   r   r:   )r   Nr?   r   )r:   rV   s     r   test_function_call_replace_allrX      s	   Qq!f51D#&, ', T3s>;< = <TSC3TB;< = <T3s"4H:; < ; 	sC3f4H:	;<	; 	s"4H6	78	7 	s&tL:	;<	;r   c                      t        ddgd      dd       } ddgdd	gd
d} | ddd|      dk(  sJ  | ddd|      dk(  sJ  | dddd|      dk(  sJ  | dddd|      dk(  sJ y)z<Test with "label_namer=None" -> no label replacement at all.r   r   Nr	   c           
      H    dt        |      dt        |      d|d|d|
S r   r   r   s         r   func_no_labelz1test_no_label_replacements.<locals>.func_no_label   rW   r   r3   r4   r=   r>   r?   r@   r5   r6   rA   z0x: [1, 2], y: [8, 9], ls: x, w: xyz, label: NonerC   r/   rD   rE   r0   rF   r   NrT   r   )r[   r:   s     r   test_no_label_replacementsr]      s     S#JDA, B, Qq!f51D$St4>? @ ?$#48>? @ ?$S>:; < ;$STB>? @ ?r   c            	          t        ddgd      dd       } ddgddgd	d
}t        j                  t              5   | d dddd|       d d d        y # 1 sw Y   y xY w)Nr   r   r	   r3   c                      y r   r   )r   r   r   r'   s       r   r   z/test_more_args_than_pos_parameter.<locals>.func   s    r   r4   r=   r>   r?   r@   r5   r6   r'   rA   )r3   )r   r)   r*   	TypeErrorr9   s     r   !test_more_args_than_pos_parameterra      si    S#JC@ A Qq!f51D	y	! 2T3S#D12 2 2s   AAc                     t               d        } t        j                  d| j                        sJ t        j                  d| j                        rJ t        g       dd       } t        j                  d| j                        rJ t        j                  d| j                        rJ t        dg      dd       } t        j                  d| j                        rJ t        j                  d| j                        rJ t        d	d
g      dd       } t        j                  d| j                        rJ t        j                  d| j                        rJ y )Nc                      yz
        Parameters
        ----------
        data : indexable object, optional
            DATA_PARAMETER_PLACEHOLDER
        Nr   )r   r   r"   s      r   funcyz&test_docstring_addition.<locals>.funcy   r   r   z#all parameters also accept a stringzthe following parametersr&   c                      yrd   r   r   r   r   r'   bars        r   re   z&test_docstring_addition.<locals>.funcy   r   r   rh   c                      yrd   r   rg   s        r   re   z&test_docstring_addition.<locals>.funcy   r   r   z&the following parameters .*: \*bar\*\.r   tc                      yrd   r   )r   r   r   r'   rj   s        r   re   z&test_docstring_addition.<locals>.funcy   r   r   z+the following parameters .*: \*x\*, \*t\*\.r   )r   research__doc__)re   s    r   test_docstring_additionro      sG     99;U]]KKKyy4emmDDDB' ( yy?OOOyy4emmDDDUG, - yy?OOOyyB( ( ( S#J/ 0 yy?OOOyyG( ( ( (r   c                  ~    d} t         j                  d| g}t        j                  |dd      }d|j                  vsJ y)z
    Test that the docstring contains the correct *data* parameter stub
    for all methods that we run _preprocess_data() on.
    zYimport logging; logging.basicConfig(level=logging.DEBUG); import matplotlib.pyplot as pltz-cT)r0   capture_outputzdata parameter docstring errorN)sys
executable
subprocessrunstderr)programcmdcompleted_procs      r   test_data_parameter_replacementrz      sD    	* 
 >>4
)C^^Cd4HN+>3H3HHHHr   c                      e Zd Zej                  ej
                  ej                  gZej                  j                  de       edg      d               Zej                  j                  de       edg      d               Zy)TestPlotTypesplotterpng)
extensionsc                     g d}g d}t        t        ||            } ||j                         |j                         |j	                                 ||j                         ||       y )Nr3   r4               )dictzipsubplotsr7   r8   )selfr}   fig_testfig_refr   r   ddicts          r   test_dict_unpackzTestPlotTypes.test_dict_unpack  sV     SAY!!#

elln	.  "Aq)r   c                 ~    g d}g d} ||j                         dd||d        ||j                         ||       y )Nr   r   xvalyval)r   r   rA   )r   )r   r}   r   r   r   r   s         r   test_data_kwargzTestPlotTypes.test_data_kwarg  sB     !!#VV+	-  "Aq)r   N)__name__
__module____qualname__r   scatterrh   plotplottersr)   markparametrizer   r   r   r   r   r   r|   r|   
  s    dhh		2H[[Y1UG,* - 2* [[Y1UG,* - 2*r   r|   r\   )rl   rt   rr   numpyrN   r)   
matplotlibr   matplotlib.axesr   matplotlib.testing.decoratorsr   r   	all_funcsall_func_idsr,   r   r   r1   r;   rH   rJ   rR   rX   r]   ra   ro   rz   r|   r   r   r   <module>r      sP   	  
   '   = c
<) =)
 K	}5B => >>  =D >D =@ >@" =? >?" =@ >@(<4@&21(hI* *r   