o
    hc,                     @   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   lslabelw r   y/var/www/html/construction_image-detection-poc/venv/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   )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   
r6   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r0   r1   r   Nr0   r1   r5   -x: [1, 2], y: [8, 9], ls: x, w: xyz, label: br   r   r5   r+   r   r5   ,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   r5   r   r4   r   r   r   !test_function_call_with_dict_dataV   s&   rB   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/   r9   )r0   r   Nr0   r1   r;   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: textrA   r   r4   r   r   r   -test_function_call_with_dict_data_not_in_datah   s&   rC   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/   )dtyper7   r8   r9   r:   Nr0   r1   r;   r<   r=   r+   r>   r?   r,   r@   rA   )	DataFramenparrayint32)r   pdr5   r   r   r   #test_function_call_with_pandas_dataz   s,   rJ   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/   r7   r8   r   )r0   r1   r   r   r%   r   Nr9   c              
   S   r   r   r   r   r   r   r   func_replace_all   r   z8test_function_call_replace_all.<locals>.func_replace_allr0   r1   )r   r5   r<   )r   r   r   r5   r+   )r   r   r5   r?   r,   r@   )r   r   r   r   r5   )r   Nr9   r   )r5   rK   r   r   r   test_function_call_replace_all   s*   rL   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/   r7   r8   r9   r:   r0   r1   r;   z0x: [1, 2], y: [8, 9], ls: x, w: xyz, label: Noner=   r+   r>   r?   r,   r@   r   Nr   r   )rM   r5   r   r   r   test_no_label_replacements   s   rO   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/   r7   r8   r9   r:   r0   r1   r$   r;   )r.   )r   r&   r'   	TypeErrorr4   r   r   r   !test_more_args_than_pos_parameter   s   "rQ   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   rR   rS   r   r   r   r   r$   barr   r   r   rT      r   rV   c                 S   rR   rS   r   rU   r   r   r   rT      r   z&the following parameters .*: \*bar\*\.r   tc                 S   rR   rS   r   )r   r   r   r$   rW   r   r   r   rT      r   z+the following parameters .*: \*x\*, \*t\*\.r   )r   research__doc__)rT   r   r   r   test_docstring_addition   s(   

r[   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cmdcompleted_procr   r   r   test_data_parameter_replacement   s   rc   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plotterpng)
extensionsc                 C   sJ   g d}g d}t t||}|| | |  || || d S )Nr.   r/               )dictzipsubplotsr2   r3   )selfre   fig_testfig_refr   r   ddictr   r   r   test_dict_unpack  s   zTestPlotTypes.test_dict_unpackc                 C   s>   g d}g d}||  dd||dd ||  || d S )Nrh   rj   xvalyval)rv   rw   r;   )rp   )rq   re   rr   rs   r   r   r   r   r   test_data_kwarg  s   zTestPlotTypes.test_data_kwargN)__name__
__module____qualname__r   scatterrV   plotplottersr&   markparametrizer   ru   rx   r   r   r   r   rd   	  s    
	
rd   rN   )rX   r]   numpyrF   r&   
matplotlibr   matplotlib.axesr   matplotlib.testingr   matplotlib.testing.decoratorsr   r   	all_funcsall_func_idsr)   r   r   r-   r6   rB   rC   rJ   rL   rO   rQ   r[   rc   rd   r   r   r   r   <module>   s:    	!





4