o
    l¨ÊhÄ%  ã                   @   sÚ  d Z ddlZddlmZmZmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZmZ ddlmZ d!d	d
„Zdd„ Zd!dd„Zddd„Zdd„ Zdd„ Zedd�dd„ ƒZG dd„ deƒZedeg dgdddœfedgdgd difed gd!gddifed gd!d digddifedd gd!gi feg d!d digdddœfed gd"d#ddœgdd#ifeg d"ddigddifeg d$gdd#ifg	ƒd%d&„ ƒZd'd(„ Zedeg dgddg i d)œfeg d*gdd#d+d,gi d)œfeg d-d.d#igdd/g d.d#id)œfed0gd1d.d#igdd#d.d#id2œfgƒd3d4„ ƒZg Ze�r8d ZZ e!d5ƒ e!d6ƒ e "eg dd d#igdd#dœfe g dd d#igdd#d+d7œfg¡ edeg d8d.d#igdd#gd.d#id9œfeg d:gd+d,gi d9œfge ƒd;d<„ ƒZ#d=d>„ Z$ed?ed
fedfedfgƒd@dA„ ƒZ%dBdC„ Z&dDdE„ Z'e�r�dFdG„ Z(dHdI„ Z)e!dJƒ dKdL„ Z*dMdN„ Z+edOe,dPedQdRgfe,dSedQgdRgfe,dTeg gfgƒdUdV„ ƒZ-dWdX„ Z.dYdZ„ Z/ed[ee0e1d\ƒƒgi d]feg d^¢d d_id`fgƒdadb„ ƒZ2dcdd„ Z3ededf„ ƒZ4dgdh„ Z5didj„ Z6dkdl„ Z7dS )mz
Test the func_inspect module.
é    N)Úfilter_argsÚget_func_nameÚget_func_code)Ú_clean_win_charsÚformat_signature)ÚMemory)Ú
with_numpy)ÚfixtureÚparametrizeÚraises)ÚPY3_OR_LATERc                 C   ó   d S ©N© ©ÚxÚyr   r   úO/var/www/html/env/lib/python3.10/site-packages/joblib/test/test_func_inspect.pyÚf   ó   r   c                 C   r   r   r   ©r   r   r   r   Úg   r   r   c                 O   r   r   r   )r   r   ÚargsÚkwargsr   r   r   Úh   r   r   é   c                 C   r   r   r   r   r   r   r   Úi!   r   r   c                 K   r   r   r   )r   r   r   r   r   r   Új%   r   r   c                  O   r   r   r   )r   r   r   r   r   Úk)   r   r   Úmodule)Úscopec                 C   s&   |   d¡}t|jƒ}|jdd„ ƒ}|S )NÚjoblib_test_func_inspectc                 S   ó   | S r   r   r   r   r   r   Úcached_func_inner5   s   z&cached_func.<locals>.cached_func_inner)Úmktempr   ÚstrpathÚcache)Útmpdir_factoryÚcachedirÚmemr#   r   r   r   Úcached_func-   s
   


r*   c                   @   s   e Zd Zdd„ ZdS )ÚKlassc                 C   s   |S r   r   )Úselfr   r   r   r   r   >   r   zKlass.fN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r+   <   s    r+   zfunc,args,filtered_args©r   r   r   r   )r   r   é   )r1   c                 C   ó   t | g|¢R Ž |ksJ ‚d S r   ©r   ©Úfuncr   Úfiltered_argsr   r   r   Útest_filter_argsF   s   r7   c                  C   s&   t ƒ } t| jg dƒd| dœksJ ‚d S )Nr0   r   )r   r,   ©r+   r   r   )Úobjr   r   r   Útest_filter_args_methodT   s    r:   )r   r   Ú*ú**)r   r1   é   é   r=   r>   )r   é   Úeer?   r;   )r   r1   r?   ©r   r   r<   c                 C   r2   r   r3   r4   r   r   r   Útest_filter_varargsY   s   
rB   zdef m1(x, *, y): passzdef m2(x, *, y, z=3): pass)r   r   Úz©r   r1   ©r;   r<   ©r=   r>   c                 C   r2   r   r3   r4   r   r   r   Útest_filter_kwargss   s   rG   c                  C   sp   t tg dddiƒddddidœksJ ‚t td¡} t | g dƒdgi dœks'J ‚t | dgdƒdgi dœks6J ‚d S )	NrD   r@   r1   r   rA   r0   rE   r   )r   r   Ú	functoolsÚpartialr   ©Úffr   r   r   Útest_filter_args_2}   s   ÿ"rL   zfunc,funcnamec                 C   s   t | ƒd |ks
J ‚d S )Nr   ©r   )r5   Úfuncnamer   r   r   Útest_func_name‡   s   rO   c                 C   s   t | ƒd dks
J ‚d S )Nr   r#   rM   )r*   r   r   r   Útest_func_name_on_inner_func�   s   rP   c                  C   sª   t djƒd dksJ ‚tdjƒdd … dksJ ‚dd„ } t | dd	�d d
ks(J ‚t| ƒd t dd¡ks6J ‚d| _t | dd	�d d
ksEJ ‚t| ƒd t dd¡ksSJ ‚d S )NÚaéÿÿÿÿÚlowerr   )NrR   c                 S   r"   r   r   r   r   r   r   Ú<lambda>š   ó    z*test_func_inspect_errors.<locals>.<lambda>F)Úwin_charactersz<lambda>z.pycz.pyÚ__main__)r   rS   r   Ú__file__Úreplacer.   rJ   r   r   r   Útest_func_inspect_errors–   s    rZ   c                   C   r   r   r   r   r   r   r   Úfunc_with_kwonly_args¦   r   r[   c                   C   r   r   r   r   r   r   r   Úfunc_with_signature©   r   r\   zw
def func_with_kwonly_args(a, b, *, kw1='kw1', kw2='kw2'): pass

def func_with_signature(a: int, b: int) -> None: pass
c                  C   s®   t tg ddddœƒdddddœksJ ‚ttƒ�} t tg dd	diƒ W d   ƒ n1 s+w   Y  |  d
¡ t tdd	gddddœƒdddœksHJ ‚t tdgdƒddiksUJ ‚d S )NrD   r=   r>   )Úkw1Úkw2r   r1   )rQ   Úbr]   r^   )r   r1   r=   r^   z?Keyword-only parameter 'kw1' was passed as positional parameterr_   )rQ   r]   rQ   )r   r[   r   Ú
ValueErrorÚmatchr\   )Úexcinfor   r   r   Útest_filter_args_python_3´   s   ÿþ
ÿ
ÿþrc   c                  C   s0   t ƒ } t ƒ }t| jg dƒt|jg dƒksJ ‚dS )z† Make sure that calling the same method on two different instances
        of the same class does resolv to different signatures.
    r0   Nr8   )rQ   r_   r   r   r   Útest_bound_methodsÉ   s   $rd   zexception,regex,func,argsz1ignore_lst must be a list of parameters to ignoreÚbarr   z-Ignore list: argument \'(.*)\' is not definedzWrong number of argumentsc                 C   sF   t | ƒ�}t|g|¢R Ž  W d  ƒ n1 sw   Y  | |¡ dS )za Make sure that filter_args returns decent error messages, for the
        sake of the user.
    N)r   r   ra   )Ú	exceptionÚregexr5   r   rb   r   r   r   Útest_filter_args_error_msgÒ   s   
ÿrh   c                  C   s*   ddi} t tg g | ƒ | ddiksJ ‚dS )z®None-regression test against 0.12.0 changes.

    https://github.com/joblib/joblib/pull/75

    Make sure filter args doesn't mutate the kwargs dict that gets passed in.
    r   r   N)r   r   )r   r   r   r   Ú#test_filter_args_no_kwargs_mutationâ   s   ri   c                  C   s&   d} t | ƒ}dD ]}||vsJ ‚qd S )NzC:\foo\bar\main.py)ú\ú:ú<ú>ú!)r   )ÚstringÚmangled_stringÚcharr   r   r   Útest_clean_win_charsî   s
   ÿrr   zfunc,args,kwargs,sgn_expectedé   zg([0, 1, 2, 3, 4]))r   r1   rF   Tzk(1, 2, (3, 4), y=True)c                 C   s*   t | g|¢R i |¤Ž\}}||ksJ ‚d S r   )r   )r5   r   r   Úsgn_expectedÚpathÚ
sgn_resultr   r   r   Útest_format_signatureõ   s   rw   c                     sà   d} d}d|  ‰ t tˆ ƒ\}}t|ƒ|k sJ ‚d}‡ fdd„t|ƒD ƒ}t tg|¢R Ž \}}t|ƒ|| k s8J ‚dd„ t|ƒD ƒ}t tfi |¤Ž\}}t|ƒ|| k sUJ ‚t tg|¢R i |¤Ž\}}t|ƒ|d	 | k snJ ‚d S )
NiÜ  iÆ  rQ   rs   c                    s   g | ]}ˆ ‘qS r   r   ©Ú.0Ú_©Úargr   r   Ú
<listcomp>
  s    z8test_format_signature_long_arguments.<locals>.<listcomp>c                 S   s   i | ]	\}}t |ƒ|“qS r   )Ústr)ry   r   r|   r   r   r   Ú
<dictcomp>  s    z8test_format_signature_long_arguments.<locals>.<dictcomp>r1   )r   r   ÚlenÚrangeÚ	enumerate)Úshortening_thresholdÚshortening_targetrz   Ú	signatureÚnb_argsr   r   r   r{   r   Ú$test_format_signature_long_argumentsþ   s   r‡   c                   C   s   dS )z6 Test the format signature formatting with numpy.
    Nr   r   r   r   r   Útest_format_signature_numpy  rU   rˆ   c                  C   sB   ddl m}  t| ƒ\}}}|dksJ ‚d|v sJ ‚d|v sJ ‚d S )Nr   ©Úbig5_frs   zdef big5_f():Ú"test_func_inspect_special_encoding©Ú.joblib.test.test_func_inspect_special_encodingrŠ   r   )rŠ   Ú	func_codeÚsource_fileÚ
first_liner   r   r   Útest_special_source_encoding  s
   r‘   c                  C   s   ddl m}  t| ƒd S )Nr   r‰   rŒ   r‰   r   r   r   Ú	_get_code$  s   r’   c                     sH   ddl m} m‰  | dd�‡ fdd„tdƒD ƒƒ}tt|ƒƒdks"J ‚d S )	Nr   )ÚParallelÚdelayedr1   )Ún_jobsc                 3   s   � | ]}ˆ t ƒƒ V  qd S r   )r’   rx   ©r”   r   r   Ú	<genexpr>+  s   € z-test_func_code_consistency.<locals>.<genexpr>rs   r   )Újoblib.parallelr“   r”   r�   r€   Úset)r“   Úcodesr   r–   r   Útest_func_code_consistency)  s    r›   )8Ú__doc__rH   Újoblib.func_inspectr   r   r   r   r   Újoblib.memoryr   Újoblib.test.commonr   Újoblib.testingr	   r
   r   Újoblib._compatr   r   r   r   r   r   r   r*   Úobjectr+   r7   r:   rB   Útest_filter_kwargs_extra_paramsÚm1Úm2ÚexecÚextendrG   rL   rO   rP   rZ   r[   r\   rc   rd   r`   rh   ri   rr   Úlistr�   rw   r‡   rˆ   r‘   r’   r›   r   r   r   r   Ú<module>   sØ    




øÿ

ÿÿÿÿúÿ
	þÿÿþüÿ

ÿ
	ÿ
ÿÿüÿ
	ÿÿ

