o
    :ao,                     @   s6  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%d	d
ZegZd
gZdd Zejjdeeddd Zejjdeeddd Zejjdeeddd Zejjdeeddd Zejjdeeddd Zdd Zdd Zdd Zdd  Zd!d" ZG d#d$ d$ZdS )&    N_preprocess_data)Axes)check_figures_equalxyreplace_nameslabel_namerxyzc                 C      dt |t ||||f S Nz&x: %s, y: %s, ls: %s, w: %s, label: %slistaxr   r   Zlslabelw r   G/usr/lib/python3/dist-packages/matplotlib/tests/test_preprocess_data.py	plot_func      r   c                  C   sH  dd } dd }dd }dd }t d	d
gd|  t d	d
gd| t d	d
gd| tt t g dd| W d   n1 sDw   Y  t g dd|  t g dd| t g dd| t g dd| tt t dd|  W d   n1 sw   Y  tt t dd| W d   dS 1 sw   Y  dS )z.Test decorator invocations -> no replacements.c                 S      d S Nr   )r   r   r   r   r   r   func        z%test_compiletime_checks.<locals>.funcc                 W   r   r   r   )r   r   r   argsr   r   r   	func_args!   r   z*test_compiletime_checks.<locals>.func_argsc                 [   r   r   r   )r   r   r   kwargsr   r   r   func_kwargs"   r   z,test_compiletime_checks.<locals>.func_kwargsc                  _   r   r   r   )r   r   r   r   r   func_no_ax_args#   r   z0test_compiletime_checks.<locals>.func_no_ax_argsr   r   r	   )r   r   zNr   r"   r
   )r   pytestraisesAssertionError)r   r   r   r    r   r   r   test_compiletime_checks   s(   "r'   r   )Zidsc                 C   s   | 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s9J | dddd	dd
ksEJ dS )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   r   r   r   test_function_call_without_data>   s$   
r*   c                 C   s*   ddd}| d|  | dksJ dS )z8Tests with dict input, unpacking via preprocess_pipeline      )abNz4x: ['a', 'b'], y: [1, 2], ls: x, w: xyz, label: None)keysvaluesr   datar   r   r   "test_function_call_with_dict_inputO   s   
r3   c                 C   s   ddgddg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sIJ | ddd	d|ddksVJ dS )zCTest with dict data -> label comes from the value of 'x' parameter.r+   r,      	   NOTr-   r.   r   Nr-   r.   r2   -x: [1, 2], y: [8, 9], ls: x, w: xyz, label: br   r   r2   r(   r   r2   ,x: [1, 2], y: [8, 9], ls: x, w: xyz, label: r)   0x: [1, 2], y: [8, 9], ls: x, w: xyz, label: textr   r   r   r2   r   r1   r   r   r   !test_function_call_with_dict_dataW   s&   r?   c                 C   s   ddg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s9J | dddd|ddksFJ | dddd|ddksSJ dS )zETest the case that one var is not in data -> half replaces, half keptr+   r,   r6   )r-   r   Nr-   r.   r8   z,x: [1, 2], y: ['b'], ls: x, w: xyz, label: br:   r(   r;   z+x: [1, 2], y: ['b'], ls: x, w: xyz, label: r)   z/x: [1, 2], y: ['b'], ls: x, w: xyz, label: textr>   r   r1   r   r   r   -test_function_call_with_dict_data_not_in_datai   s&   r@   c                 C   s   | tjddgtjdtjddgtjdddgd}| dd	d
|ddks'J | dd	d
|ddks3J | dd	d
d|ddks@J | dd	d
d|ddksMJ | dd	d
d|ddksZJ | dd	d
d|ddksgJ dS )zDTest with pandas dataframe -> label comes from ``data["col"].name``.r+   r,   )Zdtyper4   r5   r6   r7   Nr-   r.   r8   r9   r:   r(   r;   r<   r)   r=   r>   )Z	DataFramenpZarrayZint32)r   pdr2   r   r   r   #test_function_call_with_pandas_data{   s,   rC   c                  C   s   ddgddgdd} t ddddd}|d
ddd	| ddks!J |d
ddd	| ddks.J |d
ddd	d| ddks<J |d
ddd	d| ddksJJ |d
ddd	d| ddksXJ |d
ddd	d| ddksfJ d
S )zETest without a "replace_names" argument, all vars should be replaced.r+   r,   r4   r5   r   )r-   r.   r   r   r#   r   Nr6   c                 S   r   r   r   r   r   r   r   func_replace_all   r   z8test_function_call_replace_all.<locals>.func_replace_allr-   r.   )r   r2   r9   )r   r   r   r2   r(   )r   r   r2   r<   r)   r=   )r   r   r   r   r2   )r   Nr6   r   )r2   rD   r   r   r   test_function_call_replace_all   s0   
rE   c                  C   s   t ddgddddd} dd	gd
dg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sIJ dS )z<Test with "label_namer=None" -> no label replacement at all.r   r   Nr   r   c                 S   r   r   r   r   r   r   r   func_no_label   r   z1test_no_label_replacements.<locals>.func_no_labelr+   r,   r4   r5   r6   r7   r-   r.   r8   z0x: [1, 2], y: [8, 9], ls: x, w: xyz, label: Noner:   r(   r;   r<   r)   r=   r   Nr   r   )rF   r2   r   r   r   test_no_label_replacements   s   rH   c               	   C   sr   t ddgddddd} ddgdd	gd
d}tt | d dddd|d W d    d S 1 s2w   Y  d S )Nr   r   r   r+   c                 S   r   r   r   )r   r   r   r"   r   r   r   r      s   z/test_more_args_than_pos_parameter.<locals>.funcr,   r4   r5   r6   r7   r-   r.   r"   r8   )r+   )r   r$   r%   	TypeErrorr1   r   r   r   !test_more_args_than_pos_parameter   s   "rJ   c                  C   s   t  dd } td| jsJ td| jrJ t g dddd} td| jr,J td| jr5J t dgdddd} td| jrIJ td	| jrRJ t d
dgdddd} td| jrgJ td| jrpJ d S )Nc                 _      dS z
        Parameters
        ----------
        data : indexable object, optional
            DATA_PARAMETER_PLACEHOLDER
        Nr   )r   r   r   r   r   r   funcy   r   z&test_docstring_addition.<locals>.funcyz#all parameters also accept a stringzthe following parametersr!   c                 S   rK   rL   r   r   r   r   r"   barr   r   r   rM      r   rO   c                 S   rK   rL   r   rN   r   r   r   rM      r   z&the following parameters .*: \*bar\*\.r   tc                 S   rK   rL   r   )r   r   r   r"   rP   r   r   r   rM      r   z+the following parameters .*: \*x\*, \*t\*\.r   )r   research__doc__)rM   r   r   r   test_docstring_addition   s(   

rT   c                  C   s2   d} t jd| g}tj|ddd}d|jvsJ dS )z
    Test that 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)r)   Zcapture_outputzdata parameter docstring errorN)sys
executable
subprocessrunstderr)ZprogramcmdZcompleted_procr   r   r   test_data_parameter_replacement   s
   r[   c                   @   s`   e Zd ZejejejgZej	
deedgddd Zej	
deedgddd ZdS )	TestPlotTypesplotterZpng)
extensionsc                 C   sJ   g d}g d}t t||}|| | |  || || d S )Nr+   r,               )dictzipsubplotsr/   r0   )selfr]   fig_testfig_refr   r   Zddictr   r   r   test_dict_unpack  s   zTestPlotTypes.test_dict_unpackc                 C   s>   g d}g d}||  dd||dd ||  || d S )Nr_   ra   xvalyval)rl   rm   r8   )rg   )rh   r]   ri   rj   r   r   r   r   r   test_data_kwarg  s   zTestPlotTypes.test_data_kwargN)__name__
__module____qualname__r   ZscatterrO   ZplotZplottersr$   markparametrizer   rk   rn   r   r   r   r   r\   
  s    
	
r\   rG   )rQ   rW   rU   ZnumpyrA   r$   Z
matplotlibr   Zmatplotlib.axesr   Zmatplotlib.testing.decoratorsr   r   Z	all_funcsZall_func_idsr'   rr   rs   r*   r3   r?   r@   rC   rE   rH   rJ   rT   r[   r\   r   r   r   r   <module>   s:    	!





4