o
    ic,                     @   s:  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
 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)subprocess_run_for_testing)check_figures_equalxyreplace_nameslabel_namerxyzc              
   C   *   dt | dt | d| d| d| 
S Nzx: z, y: z, ls: z, w: z	, label: listaxr   r   Zlslabelw r   t/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-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_inputN   s   
r4   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/   r3   -x: [1, 2], y: [8, 9], ls: x, w: xyz, label: br   r   r3   r)   r   r3   ,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   r3   r   r2   r   r   r   !test_function_call_with_dict_dataV   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-   r7   )r.   r   Nr.   r/   r9   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   r2   r   r   r   -test_function_call_with_dict_data_not_in_datah   s&   rA   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dtyper5   r6   r7   r8   Nr.   r/   r9   r:   r;   r)   r<   r=   r*   r>   r?   )Z	DataFramenparrayZint32)r   pdr3   r   r   r   #test_function_call_with_pandas_dataz   s,   rE   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-   r5   r6   r   )r.   r/   r   r   r$   r   Nr7   c              
   S   r   r   r   r   r   r   r   func_replace_all   r   z8test_function_call_replace_all.<locals>.func_replace_allr.   r/   )r   r3   r:   )r   r   r   r3   r)   )r   r   r3   r=   r*   r>   )r   r   r   r   r3   )r   Nr7   r   )r3   rF   r   r   r   test_function_call_replace_all   s*   rG   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-   r5   r6   r7   r8   r.   r/   r9   z0x: [1, 2], y: [8, 9], ls: x, w: xyz, label: Noner;   r)   r<   r=   r*   r>   r   Nr   r   )rH   r3   r   r   r   test_no_label_replacements   s   rJ   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-   r5   r6   r7   r8   r.   r/   r#   r9   )r,   )r   r%   r&   	TypeErrorr2   r   r   r   !test_more_args_than_pos_parameter   s   "rL   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   rM   rN   r   r   r   r   r#   barr   r   r   rO      r   rQ   c                 S   rM   rN   r   rP   r   r   r   rO      r   z&the following parameters .*: \*bar\*\.r   tc                 S   rM   rN   r   )r   r   r   r#   rR   r   r   r   rO      r   z+the following parameters .*: \*x\*, \*t\*\.r   )r   research__doc__)rO   r   r   r   test_docstring_addition   s(   

rV   c                  C   s0   d} t jd| g}t|ddd}d|jvsJ dS )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)r*   capture_outputzdata parameter docstring errorN)sys
executabler   stderr)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subplotsr0   r1   )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 )Nra   rc   xvalyval)rn   ro   r9   )ri   )rj   r_   rk   rl   r   r   r   r   r   test_data_kwarg  s   zTestPlotTypes.test_data_kwargN)__name__
__module____qualname__r   ZscatterrQ   ZplotZplottersr%   markparametrizer   rm   rp   r   r   r   r   r^   	  s    
	
r^   rI   )rS   rX   numpyrB   r%   Z
matplotlibr   Zmatplotlib.axesr   Zmatplotlib.testingr   Zmatplotlib.testing.decoratorsr   r   Z	all_funcsZall_func_idsr(   rt   ru   r+   r4   r@   rA   rE   rG   rJ   rL   rV   r]   r^   r   r   r   r   <module>   s:    	!





4