B
    XT                 @   s   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m	Z
 d dlmZ d dlmZ d dl	m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dd Zdd ZdS )    N)takefirstsecondsorted
merge_withreducemergeoperator)import_module)defaultdict)addc               C   s&   t tddddgddgks"td S )N         )listr   AssertionError r   r   7lib/python3.7/site-packages/toolz/tests/test_curried.py	test_take
   s    r   c               C   s   t tjj kstd S )N)r   toolzZ	itertoolzr   r   r   r   r   
test_first   s    r   c               C   s^   t dd dddiddiks"tt ddiddiks:tt ddidd dddiksZtd S )Nc               S   s   t tS )N)r   intr   r   r   r   <lambda>   s    ztest_merge.<locals>.<lambda>)factoryr   c               S   s   t tS )N)r   r   r   r   r   r   r      s    )r   r   r   r   r   r   
test_merge   s    "r   c               C   s&   t tddiddiddiks"td S )Nr   r   r   )r   sumr   r   r   r   r   test_merge_with   s    r   c               C   s&   t tddiddigddiks"td S )Nar   r   r   )r   r   r   r   r   r   r   test_merge_with_list   s    r   c               C   s"   t tdddgddgkstd S )N)key)r   r   )r   r   )r   r   r   r   r   r   r   test_sorted    s    r    c               C   s   t tddkstd S )N)r   r   r      )r   r   r   r   r   r   r   test_reduce$   s    r"   c               C   s   t jjdkstd S )Nztoolz.curried)r   curried__name__r   r   r   r   r   test_module_name(   s    r%   c              C   s   xt t D ]p\} }t|s qt|tjsy|d W q tk
r|   y|d W n tk
rh   Y nX wtd|  Y qX qW t	t
t tt
dddg@ dkstd S )Nr   xz)toolz.curried.operator.%s is not curried!r   submulr   )varscopitemscallable
isinstancer   curry	TypeErrorr   lenset)kvr   r   r   test_curried_operator,   s    r4   c                 s^  t d} i }dd   fdd}|tt}|t| }|t|| tt|}tttjj}||krZt	|t	| }|rt
ddt| t	|t	| }|rt
ddt| tt||}td	d
 |}g }	xdt| D ]T\}
\}}|
|kr|	d|
  q tt|
r:|	d|
  q|	d|
  qW t
d|	d S )Nztoolz.curried.exceptionsc             S   sL   t | rt| tjrdS tj| }|d ks4|dkr8dS |dkoJtj| S )NFr   T)r,   r-   r   r.   Z	functoolzZnum_required_argsZhas_keywords)funcnargsr   r   r   should_curryH   s    z,test_curried_namespace.<locals>.should_curryc                s   t  fdd|  D S )Nc             3   s4   | ],\}}d |kr| |r&t |n|fV  qdS )__N)r   r.   ).0namef)r7   r   r   	<genexpr>S   s   zBtest_curried_namespace.<locals>.curry_namespace.<locals>.<genexpr>)dictr+   )ns)r7   r   r   curry_namespaceQ   s    
z/test_curried_namespace.<locals>.curry_namespacez4There are missing functions in toolz.curried:
    %sz    
z2There are extra functions in toolz.curried:
    %sc             S   s   | d | d kS )Nr   r   r   )r&   r   r   r   r   h   s    z(test_curried_namespace.<locals>.<lambda>z,%s should come from toolz.curried.exceptionsz%s should be curried from toolzz,%s should come from toolz and NOT be curried
)r
   r)   r   updater   Z	valfilterr,   r#   __dict__r1   r   joinr   r   r   r+   appendgetattr)
exceptions	namespacer?   Z
from_toolzZfrom_exceptionsZcurried_namespaceZmissingZextraZunequalZmessagesr:   Z	orig_funcZ	auto_funcr   )r7   r   test_curried_namespaceD   s8    	

rH   )r   Ztoolz.curriedr   r   r   r   r   r   r   r	   r*   Ztoolz.compatibilityr
   collectionsr   r   r   r   r   r   r   r    r"   r%   r4   rH   r   r   r   r   <module>   s   (