o
    eX>                     @   s  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mZmZm	Z	m
Z
mZmZ d dlmZ d dlmZ d dlmZ d+ddZdd	 Zed
fddZed
fddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zed
fdd Zd!d" Z d#d$ Z!d%d& Z"d'd( Z#d)d* Z$dS ),    N)curryis_valid_argsis_partial_argsis_aritynum_required_argshas_varargshas_keywords)builtins)raisesTc                 C   sB   |  ds	d|  } |rd}nd}i }td| |f t | |d S )N(z(%s)z1raise ValueError("function should not be called")zreturn Truezdef func%s:
    %sfunc)
startswithexecglobals)Zparam_stringraise_if_calledbodyd r   MD:\Projects\ConvertPro\env\Lib\site-packages\toolz/tests/test_inspect_args.py	make_func   s   
r   c                      s  t d tt fddsJ tt fddsJ t ddd   s%J tt fdds0J t ddd  d	s<J  d	d
sCJ  d	dsJJ  d	ddsRJ tt fdds]J t ddd  d	siJ  d	d
spJ  d	dswJ  d	ddsJ tt fddsJ d S )N c                      s     S Nr   r   fr   r   <lambda>   s    z test_make_func.<locals>.<lambda>c                          dS N   r   r   r   r   r   r          F)r   c                      r   r   r   r   r   r   r   r       r   zx, y=1r   x   r    yc                          dddS Nr   r!      r   r   r   r   r   r   '       z(x, y=1)c                      r$   r%   r   r   r   r   r   r   .   r'   )r   r
   
ValueError	TypeErrorr   r   r   r   test_make_func   s$   
r*   Fc                    s  |   fdd} t d}| |sJ | |ddu sJ | |dddu s%J t d}| ||u s1J | |ds8J | |dds@J | |ddddu sKJ | |ddd	du sVJ | |dddu s`J | |ddd
du skJ t d}| |suJ | |ds|J | |ddsJ | |ddddu sJ | |ddd	du sJ | |dddu sJ | |ddd
du sJ t d}| |sJ | |dsJ | |ddsJ | |dddu sJ t d}| |sJ | |ddsJ | |ddd
sJ | |ddu sJ t d}| ||u sJ | |dsJ | |ddsJ | |ddsJ | |ddddu s)J | |ddd	du s5J t d}| ||u sBJ | |dsJJ | |ddsSJ | |dds\J | |ddddsgJ | |dddd	du stJ t d}| ||u sJ | |d|u sJ | |ddsJ | |ddd|u sJ | |ddddu sJ | |dddddu sJ | |dddddu sJ | ddu sJ d S )Nc                        | ||S r   r   r   argskwargsZorig_check_validr   r   r   3   r'   ztest_is_valid.<locals>.<lambda>r   r   Fr   r    r!   r#   r"   zx=1*args**kwargszx, *argszx, y=1, **kwargsr&   r    r#   zza, b, c=3, d=4)c)eb)r   check_valid
incompleter   r   r/   r   test_is_valid1   sn   r<   c                    st  |   fdd} t d}| ||u sJ | |dsJ | |dds#J | |ddds,J | |dddu s6J | |ddd	du sAJ t d
}| ||u sMJ | |dsTJ | |dds\J | |dddseJ | |ddddsoJ | |ddswJ | |ddd	du sJ t d}| |sJ | |ddu sJ | |ddsJ | |dd	du sJ t d}| ||u sJ | |d|u sJ | |dd|u sJ | |dddsJ | |dddsJ | |dddu sJ | |ddd	du sJ | |dddddu sJ t d}| ||u sJ | |ddd	|u sJ | |ddsJ | |ddds%J | |ddds/J | |dddds:J | |dddddu sGJ | |dddddu sTJ t d}| ||u saJ | |d|u skJ | |dddsuJ t d}| ||u sJ | |d|u sJ | |dd|u sJ | |dddd|u sJ | |dddddsJ | |ddddddddd
|u sJ t d}| ||u sJ | |d|u sJ | |dd|u sJ | |ddsJ t d}| ||u sJ | |d|u sJ | |dd|u sJ | |ddsJ d|_| |du s$J G d d! d!t}| }| |d u s8J d S )"Nc                    r+   r   r   r,   r/   r   r   r   v   r'   z#test_is_valid_py3.<locals>.<lambda>z	x, *, y=1r   r   r!   r0   Fr4   zx, *args, y=1z*, y=1zx, *, yr"   )r#   r4   zx=1, *, y, z=3r&   r3   zw, x=2, *args, y, z=4z%a, b, c=3, d=4, *args, e=5, f=6, g, h   )g   )r?   h         	   za: int, b: floatr7   z(a: int, b: float) -> float"   c                   @       e Zd Zdd Zedd ZdS )z+test_is_valid_py3.<locals>.RaisesValueErrorc                 S      d S r   r   selfr   r   r   __call__      z4test_is_valid_py3.<locals>.RaisesValueError.__call__c                 S      t dNzTesting Python 3.4r(   rI   r   r   r   __signature__      z9test_is_valid_py3.<locals>.RaisesValueError.__signature__N__name__
__module____qualname__rK   propertyrP   r   r   r   r   RaisesValueError       rW   )r   rP   object)r:   r;   r   rW   r   r/   r   test_is_valid_py3t   s   $rZ   c                   C   s   t tdd ttdd d S NTr:   r;   )r<   r   rZ   r   r   r   r   test_is_partial   s   r]   c                  C   sZ   ddd} t j| dd}t|dd t|dd t j| dd}t|dd t|dd d S )NTc                 S   s   z;t | |i | t | g|R  di | t | fi ||  t | g|R i |  t| tdd s9W d S |W S  tyE   Y dS  tyN   Y dS w )Nc                   S   rH   r   r   r   r   r   r   r          z:test_is_valid_curry.<locals>.check_curry.<locals>.<lambda>TFr   )r   
isinstancetyper(   r)   )r   r-   r.   r;   r   r   r   check_curry   s   z(test_is_valid_curry.<locals>.check_curry)r;   r\   FT)	functoolspartialr<   rZ   )ra   r:   r   r   r   test_is_valid_curry   s   
re   c                  C   s   ddd} t | di sJ t | di sJ t | ddd isJ t | ddd idu s+J t| di s3J t| di s;J t| ddd isEJ t| ddd idu sQJ d S )Nc                 S   rH   r   r   r   r   r   r   r      rL   ztest_func_keyword.<locals>.fr   r   r   F)r   r   r   r   r   r   test_func_keyword   s   
rg   c                  C   s   t ddu sJ t tsJ t tddu sJ t tddu s"J t tds*J t tddu s4J t tds<J t tddu sFJ t td	du sPJ td} d
| _t | du s_J G dd dt}| } t | d u srJ d S )Nr   Fr   zx, y, zr1   r2   zx, y, *args, **kwargsz	x, y, z=1zx, y, z=1, **kwargsrF   c                   @   rG   )z/test_has_unknown_args.<locals>.RaisesValueErrorc                 S   rH   r   r   rI   r   r   r   rK     rL   z8test_has_unknown_args.<locals>.RaisesValueError.__call__c                 S   rM   rN   rO   rI   r   r   r   rP     rQ   z=test_has_unknown_args.<locals>.RaisesValueError.__signature__NrR   r   r   r   r   rW     rX   rW   )r   mapr   rP   rY   )r   rW   r   r   r   test_has_unknown_args   s   ri   c                   C   s   t dd dks
J t dd dksJ t dd dksJ t dd dks(J t dd d	ks2J t td	ks:J t td u sBJ d S )
Nc                   S   rH   r   r   r   r   r   r   r     r^   z(test_num_required_args.<locals>.<lambda>r   c                 S   rH   r   r   r   r   r   r   r     r^   r   c                 W   rH   r   r   r    r-   r   r   r   r     r^   c                 [   rH   r   r   r    r.   r   r   r   r     r^   c                 _   rH   r   r   )r    r#   r-   r.   r   r   r   r     r^   r!   )r   rh   dictr   r   r   r   test_num_required_args  s   rm   c                   C   s   t dd du s
J t dd du sJ t dddsJ t dd s%J t ts+J t ts1J t ts7J t tdu s?J t td u sGJ d S )	Nc                   S   rH   r   r   r   r   r   r   r     r^   z#test_has_keywords.<locals>.<lambda>Fc                 S   rH   r   r   r   r   r   r   r     r^   r   c                 S   rH   r   r   r   r   r   r   r     r^   c                  [   rH   r   r   r.   r   r   r   r     r^   )r   )r   intsortedmaxrh   	bytearrayr   r   r   r   test_has_keywords  s   rs   c                   C   sX   t dd du s
J t dd sJ t dd du sJ t ts"J t td u s*J d S )Nc                   S   rH   r   r   r   r   r   r   r   %  r^   z"test_has_varargs.<locals>.<lambda>Fc                  W   rH   r   r   )r-   r   r   r   r   &  r^   c                  [   rH   r   r   rn   r   r   r   r   '  r^   )r   rh   rq   r   r   r   r   test_has_varargs$  s
   rt   c                   C   s   t ddd s	J t ddd du sJ t ddd sJ t dd	d s&J t dd
d du s1J t ddd du s<J t dtsCJ t dtdu sLJ t dtd u sUJ d S )Nr   c                   S   rH   r   r   r   r   r   r   r   -  r^   ztest_is_arity.<locals>.<lambda>r   c                   S   rH   r   r   r   r   r   r   r   .  r^   Fc                 S   rH   r   r   r   r   r   r   r   /  r^   r&   c                 S   rH   r   r   r3   r   r   r   r   0  r^   c                 W   rH   r   r   rj   r   r   r   r   1  r^   c                 [   rH   r   r   rk   r   r   r   r   2  r^   r!   )r   allrh   ranger   r   r   r   test_is_arity,  s   rw   c                    s  |   fdd} t td}| |sJ | |dsJ | |dds$J | |ddds-J | |dddddu s9J | |d	d
du sCJ | |dsKJ | |ddsTJ | |ddds^J | |dddddu skJ | |ddddu swJ | |dddsJ | |ddddu sJ | |ddddsJ | |dddsJ | |dddddsJ | |dddddu sJ t jtdddd}| |du sJ | |dddu sJ t td}| |sJ | |dsJ | |ddsJ | |dddsJ | |dddds
J | |dddddsJ | |dddddds%J | |dds/J | |ddddu s<J | |ddddsHJ d S )Nc                    r+   r   r   )Z_funcr-   r.   r/   r   r   r   :  r'   z1test_introspect_curry_valid_py3.<locals>.<lambda>	x, y, z=0r   r!   r&   rB   FT)Zinvalid_keywordr   r0   r=   zx, y, *args, zr   )toolzr   r   r9   r   r/   r   test_introspect_curry_valid_py38  sD   rz   c                   C   s   t tdd d S r[   )rz   r   r   r   r   r   !test_introspect_curry_partial_py3`     r{   c                  C   sf  t td} t| dksJ td| sJ t| du sJ t| du s&J t td} t| dks5J td| du s>J td| du sGJ t| du sOJ t| sUJ t td} t| dksdJ td| du smJ td| du svJ td| du sJ td| du sJ t| du sJ t| sJ t td	} t| dksJ t| sJ t| sJ d S )
Nr   r   Fr    r   rx   r!   r&   z*args, **kwargs)ry   r   r   r   r   r   r   r   r   r   r   test_introspect_curry_py3d  s.   r}   c               	      s  t tttttjtjtjtjg	} t	   fdd}|t d |t d |t d |t d  fdd}i }| D ]%}|j
}t| D ]\}}||||rZ||vrSg ||< || | qAq6|rg }t| D ]\}}	d	|d
t|	}
||
 qfd}t|d| d S )Nc                    s"   t | |r t| | d S d S r   )hasattraddgetattr)modattrZdenylistr   r   add_denylist  s   
z5test_introspect_builtin_modules.<locals>.add_denylist
basestringNoneType__metaclass__Zsequenceiteratorc                    s   | dr| dsdS | ds|drdS z
t|tr!W dS W n	 ty+   Y nw zt|oF|jd uoF| |jv oFt|di duoF| vW S  tyQ   Y dS w )N___FZ__pyx_unpickle_Z	_cython__r   T)	r   endswith
issubclassBaseExceptionr)   callablerT   r   AttributeError)modnamenamer   r   r   r   
is_missing  s0   
z3test_introspect_builtin_modules.<locals>.is_missingz
{}:
    {}z
    z4Missing introspection for the following callables:

z

)r	   rc   	itertoolsoperatorry   Z	functoolzZ	itertoolzZ	dicttoolzZrecipessetrS   varsitemsappendrp   formatjoinAssertionError)modsr   r   missingr   r   r   r   messagesnamesmsgmessager   r   r   test_introspect_builtin_modules  s8   




r   c                  C   s   G dd dt } | dd }t|}|tjtdtjjtdtjjgdks+J t| du s3J td	d
d fftj	| < t| dksHJ tj	| = d S )Nc                   @   (   e Zd Zdd Zdd Zedd ZdS )z-test_inspect_signature_property.<locals>.AddXc                 S   
   || _ d S r   rf   rJ   r   r   r   r   __init__     
z6test_inspect_signature_property.<locals>.AddX.__init__c                 _   s   || j |i | S r   rf   )rJ   addxr-   r.   r   r   r   rK     s   z6test_inspect_signature_property.<locals>.AddX.__call__c                 S   sD   t | j}t|j }t jj}t d|}|g| }|j|dS )Nr   
parameters)	inspect	signaturer   listr   values	ParameterPOSITIONAL_OR_KEYWORDreplace)rJ   sigparamskindZnewparamr   r   r   rP     s   
z;test_inspect_signature_property.<locals>.AddX.__signature__N)rS   rT   rU   r   rK   rV   rP   r   r   r   r   AddX  
    r   c                 S      | S r   r   r   r   r   r   r     r^   z1test_inspect_signature_property.<locals>.<lambda>r   r    r   Fr   c                 S   rH   r   r   rf   r   r   r   r     r^   r   )
rY   r   r   	Signaturer   r   r   _sigs
expand_sig
signatures)r   r   r   r   r   r   test_inspect_signature_property  s   
r   c                  C   sv   G dd dt } dd }| |}t|t|ksJ t| d u s$J tddd fftj| < t| dks9J d S )Nc                   @   r   )z.test_inspect_wrapped_property.<locals>.Wrappedc                 S   r   r   rf   r   r   r   r   r     r   z7test_inspect_wrapped_property.<locals>.Wrapped.__init__c                 _   s   | j |i |S r   rf   )rJ   r-   r.   r   r   r   rK     r|   z7test_inspect_wrapped_property.<locals>.Wrapped.__call__c                 S   s   | j S r   rf   rI   r   r   r   __wrapped__  s   z:test_inspect_wrapped_property.<locals>.Wrapped.__wrapped__N)rS   rT   rU   r   rK   rV   r   r   r   r   r   Wrapped  r   r   c                 S   r   r   r   r   r   r   r   r     r^   z/test_inspect_wrapped_property.<locals>.<lambda>r   c                 S   rH   r   r   rf   r   r   r   r     r^   r   )rY   r   r   r   r   r   r   )r   r   wrappedr   r   r   test_inspect_wrapped_property  s   r   rb   )%rc   r   r   r   ry   Ztoolz.functoolzr   r   r   r   r   r   r   Ztoolz._signaturesr	   Z_signaturesr   Ztoolz.utilsr
   r   r*   r<   rZ   r]   re   rg   ri   rm   rs   rt   rw   rz   r{   r}   r   r   r   r   r   r   r   <module>   s6    $
CV
(3!