B
    ÛT•\Y  ã               @   s@   d dl mZmZmZ dd„ Zdd„ Zdd„ ZG dd	„ d	eƒZd
S )é    )Úabsolute_importÚdivisionÚprint_functionc             C   s   | d S )Né   © )Úxr   r   ú.lib/python3.7/site-packages/dask/utils_test.pyÚinc   s    r	   c             C   s   | d S )Nr   r   )r   r   r   r   Údec   s    r
   c             C   s   | | S )Nr   )r   Úyr   r   r   Úadd   s    r   c               @   sh   e Zd Z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d„ Zdd„ ZdS )ÚGetFunctionTestMixina  
    The GetFunctionTestCase class can be imported and used to test foreign
    implementations of the `get` function specification. It aims to enforce all
    known expectations of `get` functions.

    To use the class, inherit from it and override the `get` function. For
    example:

    > from dask.utils_test import GetFunctionTestMixin
    > class TestCustomGet(GetFunctionTestMixin):
         get = staticmethod(myget)

    Note that the foreign `myget` function has to be explicitly decorated as a
    staticmethod.
    c             C   sV   dt dftddfdœ}|  |d¡dks*t‚|  |d¡dks>t‚|  |d¡dksRt‚d S )Nr   z:xz:y)z:xz:yz:zé   z:zé   )r	   r   ÚgetÚAssertionError)ÚselfÚdr   r   r   Útest_get    s    zGetFunctionTestMixin.test_getc             C   sh   dt dftddfdœ}y|  |d¡}W n tk
r:   Y n*X d}|d |¡7 }dsdt| | jj¡ƒ‚d S )	Nr   z:xz:y)z:xz:yz:zÚbadkeyz-Expected `{}` with badkey to raise KeyError.
zObtained '{}' instead.F)r	   r   r   ÚKeyErrorÚformatr   Ú__name__)r   r   ÚresultÚmsgr   r   r   Útest_badkey)   s    z GetFunctionTestMixin.test_badkeyc             C   sl   ddt ddgfdœ}y|  |dgdg¡}W n tk
r>   Y n*X d}|d |¡7 }d	sht| | jj¡ƒ‚d S )
Nr   r   r   r   )r   r   Úzr   z-Expected `{}` with badkey to raise KeyError.
zObtained '{}' instead.F)Úsumr   r   r   r   r   )r   r   r   r   r   r   r   Útest_nested_badkey6   s    z'GetFunctionTestMixin.test_nested_badkeyc             C   s(   dt ddfdœ}|  |d¡dks$t‚d S )Nr   r   é
   )r   r   r   é   )r   r   r   )r   r   r   r   r   Útest_data_not_in_dict_is_okB   s    z0GetFunctionTestMixin.test_data_not_in_dict_is_okc             C   sD   ddt ddgfdœ}|  |ddg¡dks,t‚|  |d¡dks@t‚d S )	Nr   r   r   r   )r   r   r   )r   r   r   r   )r   r   r   )r   r   r   r   r   Útest_get_with_listF   s    z'GetFunctionTestMixin.test_get_with_listc             C   sì   dddgddt dfgtdfgddgtdfdgtdfgdgdœ}|  |d¡dddgksXt‚|  |d¡dddgksrt‚|  |d¡ddgksŠt‚|  |d¡d	gks t‚|  |d
¡dddgdddggksÄt‚|  |d¡d	ddggd	gdgksèt‚d S )Nr   r   r   ÚaÚbÚc)r#   r$   r%   r   ÚeÚfr   é   r&   r'   )r	   r   r   r   )r   r   r   r   r   Útest_get_with_list_top_levelL   s    
$z1GetFunctionTestMixin.test_get_with_list_top_levelc             C   sF   ddt ddgfdœ}|  |dgdg¡dks.t‚|  |d¡dksBt‚d S )	Nr   r   r   r   )r   r   r   ))r   r   r   r   )r   r   r   )r   r   r   r   r   Útest_get_with_nested_listZ   s    z.GetFunctionTestMixin.test_get_with_nested_listc             C   s6   dd„ }d|dt dgƒfdœ}|  |d¡dks2t‚d S )Nc             S   s   | t |ƒ S )N)Úlen)r   r   r   r   r   Ú<lambda>a   s    zPGetFunctionTestMixin.test_get_works_with_unhashables_in_values.<locals>.<lambda>r   r   )r   r   r   r   )Úsetr   r   )r   r'   r   r   r   r   Ú)test_get_works_with_unhashables_in_values`   s    z>GetFunctionTestMixin.test_get_works_with_unhashables_in_valuesc             C   s2   dt dftt dfdfdœ}|  |d¡dks.t‚d S )Nr   r   r   )r   r   r   r   é   )r	   r   r   r   )r   r   r   r   r   Útest_nested_tasksf   s    z&GetFunctionTestMixin.test_nested_tasksc             C   s2   dd„ t dƒD ƒ}d|d< |  |d¡dks.t‚d S )Nc             S   s"   i | ]}t d | fd |d  “qS )zx%dr   )r	   )Ú.0Úir   r   r   ú
<dictcomp>n   s    z=GetFunctionTestMixin.test_get_stack_limit.<locals>.<dictcomp>i'  r   Zx0Zx10000)Úranger   r   )r   r   r   r   r   Útest_get_stack_limitm   s    z)GetFunctionTestMixin.test_get_stack_limitc             C   s\   ddl m} dtdfdœdttdfdfidœ}dd	hdœ}|||ƒ}|  |d¡d
ksXt‚d S )Nr   )ÚHighLevelGraphr   )r   r   r   r   )r#   r$   r   r#   r/   )Zhighlevelgraphr6   r	   r   r   r   )r   r6   ZlayersZdependenciesZgraphr   r   r   Útest_with_HighLevelGraphr   s    

z-GetFunctionTestMixin.test_with_HighLevelGraphN)r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r!   r"   r)   r*   r.   r0   r5   r7   r   r   r   r   r      s   	r   N)	Z
__future__r   r   r   r	   r
   r   Úobjectr   r   r   r   r   Ú<module>   s   