B
    u9adJ                @   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 d dlZd dlm	Z	 d dl
Z
d dlmZ 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 d dlZd dlZejddgdZejddgd	Zejd
dgd	Zejdd Zdd Zdd ZG dd deZG dd deZ G dd de!Z"G dd dZ#e$edG dd de#ej%Z&G dd de#ej%Z'erxG dd  d ej(Z)G d!d" d"ej(Z*e$edG d#d$ d$e&Z+G d%d& d&e'Z,G d'd( d(ej%Z-G d)d* d*ej%Z.G d+d, d,e.Z/e$edG d-d. d.ej%Z0G d/d0 d0Z1e$edG d1d2 d2e1ej%Z2G d3d4 d4e1ej%Z3G d5d6 d6ej%Z4ej5G d7d8 d8Z6G d9d: d:Z7e8 d;d< Z9e8 d=d> Z:G d?d@ d@e7ej%Z;G dAdB dBe7ej%Z<G dCdD dDej%Z=e>dEkre?  dS )F    N)permutations)choice)support)proxy	functools
_functools)Zblocked)ZfreshdecimalZ_decimalc          	   c   s0   t j|  }|t j| < z
d V  W d |t j| < X d S )N)sysmodules)nameZreplacementZoriginal_module r   $/usr/lib/python3.7/test_functools.pyreplaced_module   s
    


r   c              O   s   | |fS )Nr   )argskwr   r   r   capture#   s    r   c             C   s   | j | j| j| jfS )N)funcr   keywords__dict__)partr   r   r   	signature(   s    r   c               @   s   e Zd ZdS )MyTupleN)__name__
__module____qualname__r   r   r   r   r   ,   s   r   c               @   s   e Zd Zdd ZdS )BadTuplec             C   s   t | t | S )N)list)selfotherr   r   r   __add__0   s    zBadTuple.__add__N)r   r   r   r   r   r   r   r   r   /   s   r   c               @   s   e Zd ZdS )MyDictN)r   r   r   r   r   r   r   r    3   s   r    c               @   s   e 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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/d0 Zd1d2 Zd3S )4TestPartialc          	   C   s   | j tddddd}| t| | |dddd	d
dtddd	df |  tdd }| t|ddddgdddd	g d S )N      
      )ab         (   )r'   c)r"   r#   r(   r)   )r&   r'   r,   c             S   s   | d S )Nr$   r   )xr   r   r   <lambda>>       z1TestPartial.test_basic_examples.<locals>.<lambda>)partialr   
assertTruecallableassertEqualdictmapr   )r   pr   r   r   test_basic_examples9   s    zTestPartial.test_basic_examplesc             C   sJ   | j tddddd}| |jt | |jd | |jtddd d S )Nr"   r#   r$   r%   )r&   r'   )r"   r#   )r0   r   r3   r   r   r   r4   )r   r6   r   r   r   test_attributesA   s    zTestPartial.test_attributesc             C   sB   |  t| j y| d  W n tk
r2   Y nX | d d S )Nr#   z%First arg not checked for callability)assertRaises	TypeErrorr0   fail)r   r   r   r   test_argument_checkingH   s    z"TestPartial.test_argument_checkingc             C   s`   ddd}ddi}| j |dd}| |f |d | |ddi |d	d
 | |ddi d S )Nr$   r%   c             S   s   | S )Nr   )r&   r'   r   r   r   r   S   s    zBTestPartial.test_protection_of_callers_dict_argument.<locals>.funcr&   r(      )r&      )r'   )r$   r%   )r0   r3   )r   r   dr6   r   r   r   (test_protection_of_callers_dict_argumentQ   s    

z4TestPartial.test_protection_of_callers_dict_argumentc             C   sN   ddi}| j tf|}| | dddif d|d< | | dddif d S )Nr&   r(   r   r=   )r0   r   r3   )r   r?   r6   r   r   r   test_kwargs_copy\   s
    zTestPartial.test_kwargs_copyc             C   sl   |  t}| | di f | |dddi f |  tdd}| | di f | |dddi f d S )Nr   r"   r#   )r"   r#   r(   r)   )r"   r#   r(   r)   )r0   r   r3   )r   r6   r   r   r   test_arg_combinationse   s    
z!TestPartial.test_arg_combinationsc             C   s   |  t}| |ji  | | di f | |dddddif | j tdd}| |jddi | | dddif | |ddddddf | |dddddddf d S )	Nr   r"   )r&   r&   r#   )r'   )r&   r'   r(   )r0   r   r3   r   )r   r6   r   r   r   test_kw_combinationso   s    
z TestPartial.test_kw_combinationsc             C   sL   xFdD ]>}| j tf| }|d }|d\}}| ||ko@|i k qW d S )N)r   )r   )r   r"   )r   r"   r#   )r   r"   r#   r(   )r-   r-   )r0   r   r1   )r   r   r6   expectedgotemptyr   r   r   test_positional}   s
    
zTestPartial.test_positionalc             C   sN   xHdD ]@}| j t|d}|d d}|d d\}}| ||koB|dk qW d S )N)r&   r   Ng      @)r&   )r&   r-   )r-   r   )r0   r   r1   )r   r&   r6   rD   rF   rE   r   r   r   test_keyword   s
    

zTestPartial.test_keywordc             C   sd   | j tddd}|ddd\}}| |dko8|dddk | \}}| |dko\|d	dik d S )
Nr   r"   )r&   r#   )r'   )r   r"   )r&   r'   )r   r&   )r0   r   r1   )r   r6   Zargs1Zkw1Zargs2Zkw2r   r   r   test_no_side_effects   s
    
z TestPartial.test_no_side_effectsc             C   sf   dd }|  t| |dd |  t| |dd |  t| |dd |  t| j|ddd d S )Nc             S   s   | |  d S )Nr   )r-   yr   r   r   f   s    z-TestPartial.test_error_propagation.<locals>.fr"   r   )rJ   )r9   ZeroDivisionErrorr0   )r   rK   r   r   r   test_error_propagation   s
    z"TestPartial.test_error_propagationc             C   s>   | j tdd}t|}| |j|j d }| tt|d d S )N   )baser   )r0   intr   r3   r   r9   ReferenceErrorgetattr)r   rK   r6   r   r   r   test_weakref   s
    zTestPartial.test_weakrefc             C   sP   t tttd}| tjd}| ||d | dj}| ||d d S )Nr$    
0123456789)r   r5   strranger0   joinr3   )r   datarX   r   r   r   #test_with_bound_and_unbound_methods   s
    z/TestPartial.test_with_bound_and_unbound_methodsc             C   sB   | j }|td}||dd}|tddd}| t|t| d S )NasdfT)bar)r0   r   r3   )r   r0   innernestedZflatr   r   r   test_nested_optimization   s
    
z$TestPartial.test_nested_optimizationc             C   s:   | j }dd }||d}||d}d|_| |jd d S )Nc             S   s   | S )Nr   )r\   r   r   r   foo   s    z;TestPartial.test_nested_partial_with_attribute.<locals>.foofirstsecondZspam)r0   Znew_attrr3   )r   r0   r`   r6   Zp2r   r   r   "test_nested_partial_with_attribute   s    

z.TestPartial.test_nested_partial_with_attributec                s  t  t  f}ddd |D  t  t  d}d|d|g}| jtjtjfkrZdn| jj| t}|  dtd	t	| | jtf| }|  dtd  d	t	| | jtf|}| 
t	|fd
d|D  | jtf||}| 
t	| fdd|D  d S )Nz, c             s   s   | ]}t |V  qd S )N)repr).0r&   r   r   r   	<genexpr>   s    z(TestPartial.test_repr.<locals>.<genexpr>)r&   r'   za={a!r}, b={b!r}zb={b!r}, a={a!r}zfunctools.partial()c                s"   g | ]}  d t d| dqS )rg   z, rh   )r   )re   kwargs_repr)r   r   r   
<listcomp>   s   z)TestPartial.test_repr.<locals>.<listcomp>c          
      s(   g | ] } d t d  d| dqS )rg   z, rh   )r   )re   ri   )	args_reprr   r   r   rj      s   )objectrX   
format_mapr0   c_functoolspy_functoolsr   r   r3   rd   assertIn)r   r   kwargsZkwargs_reprsrK   r   )rk   r   r   	test_repr   s(    
"



zTestPartial.test_reprc             C   s  | j tj tj fkrd}n| j j}|  t}||di i f z| t|d|f  W d |tdi i f X |  t}|t|fi i f z| t|d|tf  W d |tdi i f X |  t}|tdd|ii f z| t|d|tf  W d |tdi i f X d S )Nzfunctools.partialr   z%s(...)z%s(%r, ...)r&   z%s(%r, a=...))r0   rn   ro   r   r   __setstate__r3   rd   )r   r   rK   r   r   r   test_recursive_repr   s$    


zTestPartial.test_recursive_reprc          	   C   sp   |   ^ | jtdgdgd}g |_x<ttjd D ]*}tt||}| 	t|t| q4W W d Q R X d S )Nr[   T)r\   r"   )
AllowPickler0   r   attrrW   pickleHIGHEST_PROTOCOLloadsdumpsr3   )r   rK   protof_copyr   r   r   test_pickle   s    
zTestPartial.test_picklec             C   sl   | j tdgdgd}g |_t|}| t|t| | |j|j | |j|j | |j|j d S )Nr[   T)r\   )r0   r   rv   copyr3   assertIsr   r   )r   rK   r|   r   r   r   	test_copy   s    
zTestPartial.test_copyc             C   s   | j tdgdgd}g |_t|}| t|t| | |j|j | |j|j | |jd |jd  | |j|j | |jd |jd  d S )Nr[   T)r\   r   r\   )	r0   r   rv   r~   deepcopyr3   ZassertIsNotr   r   )r   rK   r|   r   r   r   test_deepcopy  s    
zTestPartial.test_deepcopyc          	   C   s  |  t}|tdtddtg df | t|tdtddtg df | |ddddddd	f |tdtddd f | t|tdtddi f | |ddddddd	f |tdd d f | |ddddd
dif | |ddi f | | di f |tdi d f | t|tdi i f | |ddddd
dif | |ddi f | | di f d S )N)r"   r$   )r&   )rv   r#   r%   )r'   )r"   r#   )r&   r'   r'   r   )r#   )r0   r   rs   r   r4   r3   )r   rK   r   r   r   test_setstate  s"    

zTestPartial.test_setstatec          	   C   s   |  t}| t|jtdi f | t|jtdi i d f | t|jtdi d g | t|jd di d f | t|jtd i d f | t|jtg i d f | t|jtdg d f d S )Nr   )r0   r   r9   r:   rs   r   )r   rK   r   r   r   test_setstate_errors)  s    
z TestPartial.test_setstate_errorsc             C   s(  |  t}|ttdtddd f t|}| |tdtddi f | t	|d t
 | t	|d t | }| |dddif | t	|d t
 | t	|d t |ttdi d f t|}| |tdi i f | t	|d t
 |d}| |di f | t	|d t
 d S )	N)r"   r$   )r&   r"   r#   r&   r   )r"   r#   )r0   r   rs   r   r   r    r3   r4   r   typetupler   )r   rK   srr   r   r   test_setstate_subclasses3  s"    
z$TestPartial.test_setstate_subclassesc             C   s  |    | t}||di i f z>x8ttjd D ]&}| t t	|| W d Q R X q:W W d |tdi i f X | t}|t|fi i f zZxTttjd D ]B}t
t	||}z| |jd | W d |tdi i f X qW W d |tdi i f X | t}|tdd|ii f z\xVttjd D ]D}t
t	||}z| |jd | W d |tdi i f X q<W W d |tdi i f X W d Q R X d S )Nr   r"   r   r&   )ru   r0   r   rs   rW   rw   rx   r9   RecursionErrorrz   ry   r   r   r   )r   rK   r{   r|   r   r   r   test_recursive_pickleG  s4    


z!TestPartial.test_recursive_picklec             C   s.   G dd d}|  t}| t|j|  d S )Nc               @   s   e Zd Zdd Zdd ZdS )z7TestPartial.test_setstate_refcount.<locals>.BadSequencec             S   s   dS )Nr)   r   )r   r   r   r   __len__m  s    z?TestPartial.test_setstate_refcount.<locals>.BadSequence.__len__c             S   s4   |dkrt S |dkr ttdS |dkr,i S td S )Nr   r"   i@B )r#   r(   )maxr   rW   
IndexError)r   keyr   r   r   __getitem__o  s    zCTestPartial.test_setstate_refcount.<locals>.BadSequence.__getitem__N)r   r   r   r   r   r   r   r   r   BadSequencel  s   r   )r0   rl   r9   r:   rs   )r   r   rK   r   r   r   test_setstate_refcountk  s    
z"TestPartial.test_setstate_refcountN)r   r   r   r7   r8   r<   r@   rA   rB   rC   rG   rH   rI   rM   rS   rZ   r_   rc   rr   rt   r}   r   r   r   r   r   r   r   r   r   r   r   r!   7   s2   		
	
$r!   z requires the C _functools modulec               @   s<   e Zd ZerejZG dd dZdd Zdd Zdd Zd	S )
TestPartialCc               @   s   e Zd Zdd Zdd ZdS )zTestPartialC.AllowPicklec             C   s   | S )Nr   )r   r   r   r   	__enter__  s    z"TestPartialC.AllowPickle.__enter__c             C   s   dS )NFr   )r   r   valuetbr   r   r   __exit__  s    z!TestPartialC.AllowPickle.__exit__N)r   r   r   r   r   r   r   r   r   ru     s   ru   c          
   C   s   | j tddddd}| tt|dt | tt|dd | tt|d	tddd |  t}y|`W n t	k
rx   Y nX | 
d
 d S )Nr"   r#   r$   r%   )r&   r'   r   r   )r"   r#   r   z-partial object allowed __dict__ to be deleted)r0   r   r9   AttributeErrorsetattrr5   r4   hexr   r:   r;   )r   r6   r   r   r   test_attributes_unwritable  s    
z'TestPartialC.test_attributes_unwritablec          	   C   sT   |  t}d|jd< t|}| d| | d| | t |  W d Q R X d S )Nr   i  Z1234z'value')r0   r   r   rd   rp   r9   r:   )r   r6   r   r   r   r   'test_manually_adding_non_string_keyword  s    

z4TestPartialC.test_manually_adding_non_string_keywordc                sP   |  t G  fdddt}dg j| < t }| d| | d| d S )Nc                   s   e Zd Z fddZdS )z@TestPartialC.test_keystr_replaces_value.<locals>.MutatesYourDictc                s   dg j | < dS )NZsth2astr)r   )r   )r6   r   r   __str__  s    zHTestPartialC.test_keystr_replaces_value.<locals>.MutatesYourDict.__str__N)r   r   r   r   r   )r6   r   r   MutatesYourDict  s   r   Zsthr   z['sth'])r0   r   rl   r   rd   rp   )r   r   r   r   )r6   r   test_keystr_replaces_value  s    
z'TestPartialC.test_keystr_replaces_valueN)	r   r   r   rn   r0   ru   r   r   r   r   r   r   r   r   {  s   
r   c               @   s    e Zd ZejZG dd dZdS )TestPartialPyc               @   s$   e Zd Zdd Zdd Zdd ZdS )zTestPartialPy.AllowPicklec             C   s   t dt| _d S )Nr   )r   ro   _cm)r   r   r   r   __init__  s    z"TestPartialPy.AllowPickle.__init__c             C   s
   | j  S )N)r   r   )r   r   r   r   r     s    z#TestPartialPy.AllowPickle.__enter__c             C   s   | j |||S )N)r   r   )r   r   r   r   r   r   r   r     s    z"TestPartialPy.AllowPickle.__exit__N)r   r   r   r   r   r   r   r   r   r   ru     s   ru   N)r   r   r   ro   r0   ru   r   r   r   r   r     s   r   c               @   s   e Zd ZdS )CPartialSubclassN)r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdS )PyPartialSubclassN)r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd ZereZdZdS )TestPartialCSubclassN)r   r   r   rn   r   r0   r_   r   r   r   r   r     s   r   c               @   s   e Zd ZeZdS )TestPartialPySubclassN)r   r   r   r   r0   r   r   r   r   r     s   r   c               @   sr   e Zd ZG dd deZe 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 )TestPartialMethodc               @   s   e Zd ZeeZeedZejeddZejedddZ	ejedddZ
eedZeejed	d
dZeeedZejeeddZdS )zTestPartialMethod.Ar"   r#   )r&   r(   r)   )r'   )r   r   r=      )r,   r>      	   )r?   N)r   r   r   r   partialmethodr   nothing
positionalr   bothspec_keywordsr^   r0   over_partialstaticmethodstaticclassmethodclsr   r   r   r   A  s   
r   c             C   sz  |  | j | jfi f |  | jd| jdfi f |  | jjdd| jfddif |  | jjddd| jdfddif |  | j | jdfi f |  | jd| jddfi f |  | jjdd| jdfddif |  | jjddd| jddfddif |  | j | jfddif |  | jd| jdfddif |  | jjdd| jfdddf |  | jjddd| jdfdddf |  | j | jd	fd
dif |  | jd| jd	dfd
dif |  | jjdd| jd	fdddf |  | jjddd| jd	dfdddf |  | jj| jddd| jd	dfdddf |  | j | jfdddf d S )Nr=   r   )r,   r,   r"   r&   r#   )r&   r,   r(   r'   r)   )r'   r,   )r   r   )r3   r&   r   r   r   r   r   r   )r   r   r   r   rB     s$    "& $("$( $&*.z'TestPartialMethod.test_arg_combinationsc             C   s   |  | j | jddfi f |  | jd| jdddfi f |  | jjdd| jddfddif |  | jjddd| jdddfddif |  | jj| jddd| jdddfddif d S )Nr"   r=   r   r>   )r?   r?   )r3   r&   r^   r   )r   r   r   r   test_nested  s
    "&*zTestPartialMethod.test_nestedc             C   s   |  | j | jdfddif |  | jd| jddfddif |  | jjdd| jdfdddf |  | jjddd| jddfdddf |  | jj| jddd| jddfdddf d S )Nr>   r,   r   r=   r   )r?   )r,   r?   )r3   r&   r   r   )r   r   r   r   test_over_partial  s
     $&*z#TestPartialMethod.test_over_partialc             C   s`   | j }| |jj| | |jj| | |jj| | |jj| j | | jjj| j d S )N)r&   r   r   __self__r^   r   r   r   )r   objr   r   r   test_bound_method_introspection  s    z1TestPartialMethod.test_bound_method_introspectionc             C   sf   | j }| t|jd | t|jd | t|jd | t|jd | t| jjd d S )Nr   )r   assertFalsehasattrr   r^   r   r   r&   )r   r   r   r   r   test_unbound_method_retrieval  s    z/TestPartialMethod.test_unbound_method_retrievalc          
   C   s  x| j | jgD ]}| j|d | | di f | |ddi f | |jdddddif | |jddddddif | | | j fddif | |d| j dfddif | |jdd	| j fddd
f | |jddd	| j dfddd
f W d Q R X qW d S )N)r   )r   r=   )r   r=   r   )r?   r?   r   )r,   )r,   r?   )r   r&   subTestr3   r   r   )r   r   r   r   r   test_descriptors  s     "z"TestPartialMethod.test_descriptorsc             C   sL   |  | jjdd| jfddif |  | jj| jdd| jfddif d S )Nr(   )r&   r&   )r3   r&   r   r   )r   r   r   r   test_overriding_keywords$  s    "z*TestPartialMethod.test_overriding_keywordsc          	   C   s   |  t G dd dt}W d Q R X |  t G dd d}W d Q R X G dd d}| }| |jddd|dfddd	f d S )
Nc               @   s   e Zd ZeddZdS )z.TestPartialMethod.test_invalid_args.<locals>.BNr"   )r   r   r   r   r   methodr   r   r   r   B*  s   r   c               @   s   e Zd Ze ZdS )z.TestPartialMethod.test_invalid_args.<locals>.BN)r   r   r   r   r   r   r   r   r   r   r   -  s   c               @   s   e Zd ZejeddZdS )z.TestPartialMethod.test_invalid_args.<locals>.Br"   )r   r&   N)r   r   r   r   r   r   r   r   r   r   r   r   /  s   r#   r(   )r-   r"   )r&   r-   )r9   r:   rl   r3   r   )r   r   r'   r   r   r   test_invalid_args(  s    z#TestPartialMethod.test_invalid_argsc             C   s$   |  tt| jd dt d S )Nr   z#functools.partialmethod({}, 3, b=4))r3   rd   varsr   formatr   )r   r   r   r   rr   4  s    zTestPartialMethod.test_reprc             C   sp   G dd dt j}| |jj | |jj x<| jj| jj| jj	| jj
| jjgD ]}| t|dd qRW d S )Nc               @   s&   e Zd Zejdd ZeedZdS )z1TestPartialMethod.test_abstract.<locals>.Abstractc             S   s   d S )Nr   )r   r-   rJ   r   r   r   add;  s    z5TestPartialMethod.test_abstract.<locals>.Abstract.addr=   N)	r   r   r   abcabstractmethodr   r   r   add5r   r   r   r   Abstract9  s   r   __isabstractmethod__F)r   ABCMetar1   r   r   r   r   r   r   r   r^   r   r   rR   )r   r   r   r   r   r   test_abstract8  s
    (zTestPartialMethod.test_abstractN)r   r   r   rl   r   r&   rB   r   r   r   r   r   r   r   rr   r   r   r   r   r   r     s   r   c               @   s   e Zd ZejejfddZdd Zdd Ze	
ejjdkdd	d
 Zdd Zdd Zdd Zeje	
ejjdkddd ZdS )TestUpdateWrapperc       	      C   s   x$|D ]}|  t||t|| qW xT|D ]L}t||}t||}x2|D ]*}|dkr`|dkr`qJ|  || ||  qJW q,W |  |j| d S )Nr   __wrapped__)r   rR   r   )	r   wrapperwrappedassignedupdatedr   Zwrapper_attrZwrapped_attrr   r   r   r   check_wrapperJ  s    




zTestUpdateWrapper.check_wrapperc             C   s<   dddd}d|_ d|_ddd	d
}t|| ||fS )NzThis is a new annotation)r&   c             S   s   d S )Nr   )r&   r   r   r   rK   ^  s    z,TestUpdateWrapper._default_update.<locals>.fzThis is also a testzThis is a bald faced liezThis is the prior annotation)r'   c             S   s   d S )Nr   )r'   r   r   r   r   c  s    z2TestUpdateWrapper._default_update.<locals>.wrapper)rv   r   r   update_wrapper)r   rK   r   r   r   r   _default_update]  s    z!TestUpdateWrapper._default_updatec             C   sv   |   \}}| || | |j| | |jd | |j|j | |jd | |jd d | 	d|j d S )NrK   zThis is also a testr&   zThis is a new annotationr'   )
r   r   r   r   r3   r   r   rv   __annotations__assertNotIn)r   r   rK   r   r   r   test_default_updateh  s    z%TestUpdateWrapper.test_default_updater#   z)Docstrings are omitted with -O2 and abovec             C   s   |   \}}| |jd d S )NzThis is a test)r   r3   __doc__)r   r   rK   r   r   r   test_default_update_docr  s    z)TestUpdateWrapper.test_default_update_docc             C   s   dd }d|_ dd }t||dd | ||dd | |jd | |j|j | |jd  | |j	i  | 
t|d d S )	Nc               S   s   d S )Nr   r   r   r   r   rK   y  s    z+TestUpdateWrapper.test_no_update.<locals>.fzThis is also a testc               S   s   d S )Nr   r   r   r   r   r   }  s    z1TestUpdateWrapper.test_no_update.<locals>.wrapperr   r   rv   )rv   r   r   r   r3   r   assertNotEqualr   r   r   r   r   )r   rK   r   r   r   r   test_no_updatex  s    z TestUpdateWrapper.test_no_updatec             C   s   dd }d|_ tdddd|_dd	 }i |_d
}d}t|||| | |||| | |jd | |j	|j	 | |j
d  | |j d | |j|j d S )Nc               S   s   d S )Nr   r   r   r   r   rK     s    z2TestUpdateWrapper.test_selective_update.<locals>.fzThis is a different testr"   r#   r(   )r&   r'   r,   c               S   s   d S )Nr   r   r   r   r   r     s    z8TestUpdateWrapper.test_selective_update.<locals>.wrapper)rv   )	dict_attrr   )rv   r4   r   r   r   r   r3   r   r   r   r   )r   rK   r   assignupdater   r   r   test_selective_update  s    z'TestUpdateWrapper.test_selective_updatec          	   C   s   dd }dd }i |_ d}d}t|||| | d|j | |j i  |` | t t|||| W d Q R X d|_ | t t|||| W d Q R X d S )	Nc               S   s   d S )Nr   r   r   r   r   rK     s    z4TestUpdateWrapper.test_missing_attributes.<locals>.fc               S   s   d S )Nr   r   r   r   r   r     s    z:TestUpdateWrapper.test_missing_attributes.<locals>.wrapper)rv   )r   rv   r"   )r   r   r   r   r   r3   r9   r   )r   rK   r   r   r   r   r   r   test_missing_attributes  s    z)TestUpdateWrapper.test_missing_attributesc             C   sF   dd }t |t | |jd | |jd | |ji  d S )Nc               S   s   d S )Nr   r   r   r   r   r     s    z6TestUpdateWrapper.test_builtin_update.<locals>.wrapperr   zmax()	r   r   r   r3   r   r1   r   
startswithr   )r   r   r   r   r   test_builtin_update  s
    z%TestUpdateWrapper.test_builtin_updateN)r   r   r   r   WRAPPER_ASSIGNMENTSWRAPPER_UPDATESr   r   r   unittestskipIfr	   flagsoptimizer   r   r   r   r   Zrequires_docstringsr   r   r   r   r   r   H  s   
r   c               @   sH   e Zd Zdd Zdd Zeejj	dkddd Z
d	d
 Zdd ZdS )	TestWrapsc             C   s.   dd }d|_ d|_t|dd }||fS )Nc               S   s   d S )Nr   r   r   r   r   rK     s    z$TestWraps._default_update.<locals>.fzThis is also a testzThis is still a bald faced liec               S   s   d S )Nr   r   r   r   r   r     s    z*TestWraps._default_update.<locals>.wrapper)rv   r   r   wraps)r   rK   r   r   r   r   r     s
    zTestWraps._default_updatec             C   sH   |   \}}| || | |jd | |j|j | |jd d S )NrK   zThis is also a test)r   r   r3   r   r   rv   )r   r   rK   r   r   r   r     s
    zTestWraps.test_default_updater#   z)Docstrings are omitted with -O2 and abovec             C   s   |   \}}| |jd d S )NzThis is a test)r   r3   r   )r   r   _r   r   r   r     s    z!TestWraps.test_default_update_docc             C   st   dd }d|_ t|dddd }| ||dd | |jd | |j|j | |jd  | 	t
|d d S )	Nc               S   s   d S )Nr   r   r   r   r   rK     s    z#TestWraps.test_no_update.<locals>.fzThis is also a testr   c               S   s   d S )Nr   r   r   r   r   r     s    z)TestWraps.test_no_update.<locals>.wrapperr   rv   )rv   r   r   r   r3   r   r   r   r   r   r   )r   rK   r   r   r   r   r     s    zTestWraps.test_no_updatec             C   s   dd }d|_ tdddd|_dd	 }d
}d}t||||dd }| |||| | |jd | |j	|j	 | |j
d  | |j d | |j|j d S )Nc               S   s   d S )Nr   r   r   r   r   rK     s    z*TestWraps.test_selective_update.<locals>.fzThis is a different testr"   r#   r(   )r&   r'   r,   c             S   s
   i | _ | S )N)r   )rK   r   r   r   add_dict_attr  s    z6TestWraps.test_selective_update.<locals>.add_dict_attr)rv   )r   c               S   s   d S )Nr   r   r   r   r   r     s    z0TestWraps.test_selective_update.<locals>.wrapperr   )rv   r4   r   r   r   r   r3   r   r   r   r   )r   rK   r   r   r   r   r   r   r   r     s    zTestWraps.test_selective_updateN)r   r   r   r   r   r   r   r	   r   r   r   r   r   r   r   r   r   r     s   r   c               @   s&   e Zd ZerejZdd Zdd ZdS )
TestReducec          	   C   s  G dd d}dd }|  | |dddgdd	 |  | |ddgg d
dggg ddd
dg |  | dd tdddd |  | dd tdddd |  | ||dd |  | ||ddd |  | ||ddd | t| j | t| jdd | t| jddd |  | ddd |  | dddd | t| jdd | t| j|g  | t| j|d | t| j|d | t| j|t  G dd d}| t| j||  |  | |g d d  |  | |g dd G dd d}| t| jd|  d S ) Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z'TestReduce.test_reduce.<locals>.Squaresc             S   s   || _ g | _d S )N)r   sofar)r   r   r   r   r   r     s    z0TestReduce.test_reduce.<locals>.Squares.__init__c             S   s
   t | jS )N)lenr   )r   r   r   r   r     s    z/TestReduce.test_reduce.<locals>.Squares.__len__c             S   sV   d|  kr| j k sn tt| j}x$||krJ| j||  |d7 }q(W | j| S )Nr   r"   )r   r   r   r   append)r   inr   r   r   r     s     

z3TestReduce.test_reduce.<locals>.Squares.__getitem__N)r   r   r   r   r   r   r   r   r   r   Squares  s   r   c             S   s   | | S )Nr   )r-   rJ   r   r   r   r     s    z#TestReduce.test_reduce.<locals>.addr&   r'   r,   rT   r   r?   wc             S   s   | | S )Nr   )r-   rJ   r   r   r   r.     r/   z(TestReduce.test_reduce.<locals>.<lambda>r#   r   r"   i  c             S   s   | | S )Nr   )r-   rJ   r   r   r   r.     r/      l     h r$   i  r   *   1)r   r   r   c               @   s   e Zd Zdd ZdS )z/TestReduce.test_reduce.<locals>.TestFailingIterc             S   s   t d S )N)RuntimeError)r   r   r   r   __iter__'  s    z8TestReduce.test_reduce.<locals>.TestFailingIter.__iter__N)r   r   r   r   r   r   r   r   TestFailingIter&  s   r   c               @   s   e Zd Zdd ZdS )z&TestReduce.test_reduce.<locals>.BadSeqc             S   s   t d S )N)
ValueError)r   indexr   r   r   r   /  s    z2TestReduce.test_reduce.<locals>.BadSeq.__getitem__N)r   r   r   r   r   r   r   r   BadSeq.  s   r   )r3   r   rW   r9   r:   rl   r   r   )r   r   r   r   r   r   r   r   test_reduce  s:     zTestReduce.test_reducec             C   s   G dd d}ddl m} | | ||dd | | ||ddd | t| j||d | | ||ddd | | ||d	d | | ||d	dd d	d
dd}| | ||d|  d S )Nc               @   s   e Zd Zdd Zdd ZdS )z5TestReduce.test_iterator_usage.<locals>.SequenceClassc             S   s
   || _ d S )N)r   )r   r   r   r   r   r   6  s    z>TestReduce.test_iterator_usage.<locals>.SequenceClass.__init__c             S   s&   d|  kr| j k rn n|S td S )Nr   )r   r   )r   r   r   r   r   r   8  s    zATestReduce.test_iterator_usage.<locals>.SequenceClass.__getitem__N)r   r   r   r   r   r   r   r   r   SequenceClass5  s   r  r   )r   r=   r$   r   4   r"   r#   r(   )ZoneZtwoZthreerT   )operatorr   r3   r   r9   r:   rX   keys)r   r  r   r?   r   r   r   test_iterator_usage4  s    	zTestReduce.test_iterator_usageN)r   r   r   rn   reducer   r  r  r   r   r   r   r     s   8r   c               @   sD   e 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S )TestCmpToKeyc             C   s   dd }|  |}| |d|d | |d|d | |d|d dd }|  |}| |d|d | |d	|d
 | |d	|d
 | |d	|d
 d S )Nc             S   s   | |k| |k  S )Nr   )r-   rJ   r   r   r   cmp1M  s    z*TestCmpToKey.test_cmp_to_key.<locals>.cmp1r(   r"   c             S   s   t | t | S )N)rP   )r-   rJ   r   r   r   cmp2T  s    z*TestCmpToKey.test_cmp_to_key.<locals>.cmp2g      @4r#   Z35)
cmp_to_keyr3   assertGreaterZassertGreaterEqualZ
assertLessassertLessEqualr   )r   r	  r   r
  r   r   r   test_cmp_to_keyL  s    

zTestCmpToKey.test_cmp_to_keyc          	   C   s  dd }| j |d}| |dd|dd | |dd|dd | ttf |ddk W d Q R X | ttf d|dk  W d Q R X | t |   }W d Q R X | t |  |d }W d Q R X |  |}| t |  W d Q R X | t |d d  W d Q R X d S )Nc             S   s   | |k| |k  S )Nr   )r-   rJ   r   r   r   r	  ]  s    z4TestCmpToKey.test_cmp_to_key_arguments.<locals>.cmp1)mycmpr(   )r   r"   )r  r3   r  r9   r:   r   )r   r	  r   r   r   r   test_cmp_to_key_arguments\  s"    
z&TestCmpToKey.test_cmp_to_key_argumentsc          	      s|   dd }|  |}| t |d|dk W d Q R X G dd d  fdd}| t |d|dk W d Q R X d S )Nc             S   s   t d S )N)rL   )r-   rJ   r   r   r   r	  q  s    z'TestCmpToKey.test_bad_cmp.<locals>.cmp1r(   r"   c               @   s   e Zd Zdd ZdS )z)TestCmpToKey.test_bad_cmp.<locals>.BadCmpc             S   s   t d S )N)rL   )r   r   r   r   r   __lt__x  s    z0TestCmpToKey.test_bad_cmp.<locals>.BadCmp.__lt__N)r   r   r   r  r   r   r   r   BadCmpw  s   r  c                s     S )Nr   )r-   rJ   )r  r   r   r	  z  s    )r  r9   rL   )r   r	  r   r   )r  r   test_bad_cmpp  s    
zTestCmpToKey.test_bad_cmpc             C   s*   dd }| j |d}| |djd d S )Nc             S   s   | |k| |k  S )Nr   )r-   rJ   r   r   r   r	    s    z)TestCmpToKey.test_obj_field.<locals>.cmp1)r  2   )r  r3   r   )r   r	  r   r   r   r   test_obj_field  s    zTestCmpToKey.test_obj_fieldc             C   s4   dd }|  ttd| |dddddd	g d S )
Nc             S   s   ||  S )Nr   )r-   rJ   r   r   r   r    s    z)TestCmpToKey.test_sort_int.<locals>.mycmpr=   )r   r)   r(   r#   r"   r   )r3   sortedrW   r  )r   r  r   r   r   test_sort_int  s    zTestCmpToKey.test_sort_intc             C   s\   dd }ddddddd	d
dg	}t || |d}| dd |D dddddd	dddg	 d S )Nc             S   s"   t | t | } }| |k| |k  S )N)rP   )r-   rJ   r   r   r   r    s    z-TestCmpToKey.test_sort_int_str.<locals>.mycmpr=   3r>   r#   0r   r)   Z10r"   )r   c             S   s   g | ]}t |qS r   )rP   )re   r   r   r   r   rj     s    z2TestCmpToKey.test_sort_int_str.<locals>.<listcomp>r   r(   r$   )r  r  r3   )r   r  valuesr   r   r   test_sort_int_str  s
    zTestCmpToKey.test_sort_int_strc             C   s<   dd }|  |}|d}| tt| | |tjj d S )Nc             S   s   ||  S )Nr   )r-   rJ   r   r   r   r    s    z%TestCmpToKey.test_hash.<locals>.mycmpr$   )r  r9   r:   hashZassertNotIsInstancecollectionsr   Hashable)r   r  r   kr   r   r   	test_hash  s
    
zTestCmpToKey.test_hashN)
r   r   r   r  r  r  r  r  r  r!  r   r   r   r   r  J  s   	r  c               @   s   e Zd ZerejZdS )TestCmpToKeyCN)r   r   r   rn   r  r   r   r   r   r"    s   r"  c               @   s   e Zd ZeejZdS )TestCmpToKeyPyN)r   r   r   r   ro   r  r   r   r   r   r#    s   r#  c               @   sL   e 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S )TestTotalOrderingc             C   s   t jG dd d}| |d|dk  | |d|dk | |d|dk | |d|dk | |d|dk | |d|dk | |d|dk d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z3TestTotalOrdering.test_total_ordering_lt.<locals>.Ac             S   s
   || _ d S )N)r   )r   r   r   r   r   r     s    z<TestTotalOrdering.test_total_ordering_lt.<locals>.A.__init__c             S   s   | j |j k S )N)r   )r   r   r   r   r   r    s    z:TestTotalOrdering.test_total_ordering_lt.<locals>.A.__lt__c             S   s   | j |j kS )N)r   )r   r   r   r   r   __eq__  s    z:TestTotalOrdering.test_total_ordering_lt.<locals>.A.__eq__N)r   r   r   r   r  r%  r   r   r   r   r     s   r   r"   r#   )r   total_orderingr1   r   )r   r   r   r   r   test_total_ordering_lt  s    z(TestTotalOrdering.test_total_ordering_ltc             C   s   t jG dd d}| |d|dk  | |d|dk | |d|dk | |d|dk | |d|dk | |d|dk | |d|dk d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z3TestTotalOrdering.test_total_ordering_le.<locals>.Ac             S   s
   || _ d S )N)r   )r   r   r   r   r   r     s    z<TestTotalOrdering.test_total_ordering_le.<locals>.A.__init__c             S   s   | j |j kS )N)r   )r   r   r   r   r   __le__  s    z:TestTotalOrdering.test_total_ordering_le.<locals>.A.__le__c             S   s   | j |j kS )N)r   )r   r   r   r   r   r%    s    z:TestTotalOrdering.test_total_ordering_le.<locals>.A.__eq__N)r   r   r   r   r(  r%  r   r   r   r   r     s   r   r"   r#   )r   r&  r1   r   )r   r   r   r   r   test_total_ordering_le  s    z(TestTotalOrdering.test_total_ordering_lec             C   s   t jG dd d}| |d|dk  | |d|dk | |d|dk | |d|dk | |d|dk | |d|dk | |d|dk  d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z3TestTotalOrdering.test_total_ordering_gt.<locals>.Ac             S   s
   || _ d S )N)r   )r   r   r   r   r   r     s    z<TestTotalOrdering.test_total_ordering_gt.<locals>.A.__init__c             S   s   | j |j kS )N)r   )r   r   r   r   r   __gt__  s    z:TestTotalOrdering.test_total_ordering_gt.<locals>.A.__gt__c             S   s   | j |j kS )N)r   )r   r   r   r   r   r%    s    z:TestTotalOrdering.test_total_ordering_gt.<locals>.A.__eq__N)r   r   r   r   r*  r%  r   r   r   r   r     s   r   r"   r#   )r   r&  r1   r   )r   r   r   r   r   test_total_ordering_gt  s    z(TestTotalOrdering.test_total_ordering_gtc             C   s   t jG dd d}| |d|dk  | |d|dk | |d|dk | |d|dk | |d|dk | |d|dk | |d|dk d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z3TestTotalOrdering.test_total_ordering_ge.<locals>.Ac             S   s
   || _ d S )N)r   )r   r   r   r   r   r     s    z<TestTotalOrdering.test_total_ordering_ge.<locals>.A.__init__c             S   s   | j |j kS )N)r   )r   r   r   r   r   __ge__  s    z:TestTotalOrdering.test_total_ordering_ge.<locals>.A.__ge__c             S   s   | j |j kS )N)r   )r   r   r   r   r   r%    s    z:TestTotalOrdering.test_total_ordering_ge.<locals>.A.__eq__N)r   r   r   r   r,  r%  r   r   r   r   r     s   r   r"   r#   )r   r&  r1   r   )r   r   r   r   r   test_total_ordering_ge  s    z(TestTotalOrdering.test_total_ordering_gec             C   s   t jG dd dt}| |d|dk  | |d|dk | |d|dk | |d|dk | |d|dk | |d|dk d S )Nc               @   s   e Zd ZdS )z=TestTotalOrdering.test_total_ordering_no_overwrite.<locals>.AN)r   r   r   r   r   r   r   r     s   r   r"   r#   )r   r&  rP   r1   )r   r   r   r   r    test_total_ordering_no_overwrite  s    z2TestTotalOrdering.test_total_ordering_no_overwritec          	   C   s.   |  t tjG dd d}W d Q R X d S )Nc               @   s   e Zd ZdS )z7TestTotalOrdering.test_no_operations_defined.<locals>.AN)r   r   r   r   r   r   r   r     s   r   )r9   r   r   r&  )r   r   r   r   r   test_no_operations_defined  s    z,TestTotalOrdering.test_no_operations_definedc          
      s4  t jG fdddt jG fdddt jG fdddt jG fdddt jG  fd	d
d
 | d( | t ddk  W d Q R X W d Q R X | d, | t ddk  W d Q R X W d Q R X | d, | t ddk  W d Q R X W d Q R X | d, | t ddk W d Q R X W d Q R X | d, | t ddk W d Q R X W d Q R X | d, | t ddk W d Q R X W d Q R X | d, | t ddk W d Q R X W d Q R X | d, | t ddk W d Q R X W d Q R X | d, | t ddk W d Q R X W d Q R X | d@  d} d}| || | t ||k W d Q R X W d Q R X | d@  d } d }| || | t ||k W d Q R X W d Q R X d S )!Nc                   s,   e Zd Zdd Z fddZ fddZdS )zRTestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsLessThanc             S   s
   || _ d S )N)r   )r   r   r   r   r   r     s    z[TestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsLessThan.__init__c                s   t | r| j|jkS dS )NF)
isinstancer   )r   r   )ImplementsLessThanr   r   r%    s    
zYTestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsLessThan.__eq__c                s   t | r| j|jk S tS )N)r0  r   NotImplemented)r   r   )r1  r   r   r  
  s    
zYTestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsLessThan.__lt__N)r   r   r   r   r%  r  r   )r1  r   r   r1    s   r1  c                   s,   e Zd Zdd Z fddZ fddZdS )zUTestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsGreaterThanc             S   s
   || _ d S )N)r   )r   r   r   r   r   r     s    z^TestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsGreaterThan.__init__c                s   t | r| j|jkS dS )NF)r0  r   )r   r   )ImplementsGreaterThanr   r   r%    s    
z\TestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsGreaterThan.__eq__c                s   t | r| j|jkS tS )N)r0  r   r2  )r   r   )r3  r   r   r*    s    
z\TestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsGreaterThan.__gt__N)r   r   r   r   r%  r*  r   )r3  r   r   r3    s   r3  c                   s,   e Zd Zdd Z fddZ fddZdS )zYTestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsLessThanEqualToc             S   s
   || _ d S )N)r   )r   r   r   r   r   r     s    zbTestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsLessThanEqualTo.__init__c                s   t | r| j|jkS dS )NF)r0  r   )r   r   )ImplementsLessThanEqualTor   r   r%     s    
z`TestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsLessThanEqualTo.__eq__c                s   t | r| j|jkS tS )N)r0  r   r2  )r   r   )r4  r   r   r(  $  s    
z`TestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsLessThanEqualTo.__le__N)r   r   r   r   r%  r(  r   )r4  r   r   r4    s   r4  c                   s,   e Zd Zdd Z fddZ fddZdS )z\TestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsGreaterThanEqualToc             S   s
   || _ d S )N)r   )r   r   r   r   r   r   +  s    zeTestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsGreaterThanEqualTo.__init__c                s   t | r| j|jkS dS )NF)r0  r   )r   r   )ImplementsGreaterThanEqualTor   r   r%  -  s    
zcTestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsGreaterThanEqualTo.__eq__c                s   t | r| j|jkS tS )N)r0  r   r2  )r   r   )r5  r   r   r,  1  s    
zcTestTotalOrdering.test_type_error_when_not_implemented.<locals>.ImplementsGreaterThanEqualTo.__ge__N)r   r   r   r   r%  r,  r   )r5  r   r   r5  )  s   r5  c                   s(   e Zd Zdd Z fddZdd ZdS )zXTestTotalOrdering.test_type_error_when_not_implemented.<locals>.ComparatorNotImplementedc             S   s
   || _ d S )N)r   )r   r   r   r   r   r   8  s    zaTestTotalOrdering.test_type_error_when_not_implemented.<locals>.ComparatorNotImplemented.__init__c                s   t | r| j|jkS dS )NF)r0  r   )r   r   )ComparatorNotImplementedr   r   r%  :  s    
z_TestTotalOrdering.test_type_error_when_not_implemented.<locals>.ComparatorNotImplemented.__eq__c             S   s   t S )N)r2  )r   r   r   r   r   r  >  s    z_TestTotalOrdering.test_type_error_when_not_implemented.<locals>.ComparatorNotImplemented.__lt__N)r   r   r   r   r%  r  r   )r6  r   r   r6  6  s   r6  zLT < 1r"   zLT < LEr   zLT < GTzLE <= LTr#   zLE <= GEr(   zGT > GEr)   zGT > LTr=   zGE >= GTr   zGE >= LEr>   zGE when equalr   zLE when equalr   )r   r&  r   r9   r:   r3   )r   r&   r'   r   )r6  r3  r5  r1  r4  r   $test_type_error_when_not_implemented  sF     $$$$$$$$z6TestTotalOrdering.test_type_error_when_not_implementedc             C   sl   xft tjd D ]T}xNdD ]F}| j||d. tt|}tt||}| || W d Q R X qW qW d S )Nr"   )r  r*  r(  r,  )r   r{   )	rW   rw   rx   r   rR   Orderable_LTry   rz   r   )r   r{   r   r   Zmethod_copyr   r   r   r}   j  s    

zTestTotalOrdering.test_pickleN)r   r   r   r'  r)  r+  r-  r.  r/  r8  r}   r   r   r   r   r$    s   kr$  c               @   s$   e Zd Zdd Zdd Zdd ZdS )r9  c             C   s
   || _ d S )N)r   )r   r   r   r   r   r   t  s    zOrderable_LT.__init__c             C   s   | j |j k S )N)r   )r   r   r   r   r   r  v  s    zOrderable_LT.__lt__c             C   s   | j |j kS )N)r   )r   r   r   r   r   r%  x  s    zOrderable_LT.__eq__N)r   r   r   r   r  r%  r   r   r   r   r9  r  s   r9  c               @   s   e 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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/d0 Zd1S )2TestLRUc                s^  dd }| j jdd|}| \}}}}| |d | |d | |d | |d td}xBtdD ]6}t|t| }	}
||	|
}||	|
}| || qlW | \}}}}| ||k | || d | |d |  | \}}}}| |d | |d | |d ||	|
 | \}}}}| |d | |d | |d | |j	| |	|	|
 | \}}}}| |d | |d | |d | j d fd	d
}| | j
d d x tdD ]}| | d qW |  d | \}}}}| |d | |d | |d | j d fdd
}| | j
d d x tdD ]}| | d qpW |  d | \}}}}| |d | |d | |d | j d fdd
}| | j
d d x"dD ]}	| ||	|	d  qW |  d | \}}}}| |d | |d | |d d S )Nc             S   s   d|  | S )Nr(   r   )r-   rJ   r   r   r   orig  s    zTestLRU.test_lru.<locals>.origr%   )maxsizer   r=   i  r"   c                  s    d7  dS )Nr"   r%   r   r   )f_cntr   r   rK     s    zTestLRU.test_lru.<locals>.fc                  s    d7  dS )Nr"   r%   r   r   )r=  r   r   rK     s    r)   r#   c                s    d7  | d S )Nr"   r$   r   )r-   )r=  r   r   rK     s    )r>   r   r>   r   r>   r   r   r   r   r   r   r   r   r   r   r>   r$      )module	lru_cache
cache_infor3   rW   r   r1   cache_clearr   r   r<  )r   r;  rK   hitsmissesr<  currsizedomainr   r-   rJ   actualrD   r   )r=  r   test_lru~  s~    



zTestLRU.test_lruc                s   d| j jdd fdd x(tdD ]}|  |d| d q*W |   jd |  dd	 |   jd d S )
NTr$   )r<  c                s(   d|  d}| dkr$r$d | }|S )N.r%   Fr   )r-   rv)rK   oncer   r   rK     s
    z%TestLRU.test_lru_bug_35780.<locals>.f   rI  r%   z.20.)r?  r@  rW   r3   rA  rE  )r   r-   r   )rK   rK  r   test_lru_bug_35780  s    
zTestLRU.test_lru_bug_35780c             C   s:   | j  dd }|d |di  | | jd d S )Nc             S   s   d S )Nr   )r-   r   r   r   rK     s    z%TestLRU.test_lru_bug_36650.<locals>.fr   r"   )r   )r?  r@  r3   rA  rC  )r   rK   r   r   r   test_lru_bug_36650  s    
zTestLRU.test_lru_bug_36650c             C   s  | j jdddd }tj }tjjdd|_tjjdd|_| ||dd | |jjd | |	 d	 | ||dd | |jjd
 | |	 d | |dd
d | |jjd
 | |	 d | ||dd | |jjd | |	 d d S )Nr"   )r<  c             S   s   | d | S )Nr(   r   )r-   rJ   r   r   r   rK     s    z*TestLRU.test_lru_hash_only_once.<locals>.frL  )Zreturn_valuei  rN   )r   r"   r"   r"   r#   )r"   r"   r"   r"   r   r%   )r"   r#   r"   r"   r(   )r"   r(   r"   r"   )
r?  r@  r   ZmockZMock__mul____hash__r3   Z
call_countrA  )r   rK   Zmock_intr   r   r   test_lru_hash_only_once   s     
zTestLRU.test_lru_hash_only_oncec             C   sP   t j}z<| jdtt _x$dD ]}| tdd | | q W W d |t _X d S )Nr)   )r   r   r"   r#   r(   r(   r)   r=   r   r"   r>   r#   r"   Zabcdefghijklmn)builtinsr   r?  r@  r3   )r   Zold_lenr   r   r   r   test_lru_reentrancy_with_len#  s    
 z$TestLRU.test_lru_reentrancy_with_lenc             C   s6   t  dd }| |ddd | |dd d S )Nc              W   s   | S )Nr   )r   r   r   r   rK   1  s    z-TestLRU.test_lru_star_arg_handling.<locals>.fr"   r#   )r"   r#   ))r"   r#   )r   r@  r3   )r   rK   r   r   r   test_lru_star_arg_handling/  s    z"TestLRU.test_lru_star_arg_handlingc          	   C   sh   t jd ddd }t jdddd }| t |g  W d Q R X | t |g  W d Q R X d S )N)r<  c             S   s   d S )Nr   )or   r   r   infinite_cache=  s    z3TestLRU.test_lru_type_error.<locals>.infinite_cacher$   c             S   s   d S )Nr   )rU  r   r   r   limited_cacheA  s    z2TestLRU.test_lru_type_error.<locals>.limited_cache)r   r@  r9   r:   )r   rV  rW  r   r   r   test_lru_type_error8  s    zTestLRU.test_lru_type_errorc                s   | j jd d fdd |  fddtdD dddd	d
dddddddddddg |   | j jddd dd    |   | j jddd dd d S )N)r<  c                s$   | dk r| S  | d  | d  S )Nr#   r"   r   )r   )fibr   r   rY  L  s    z/TestLRU.test_lru_with_maxsize_none.<locals>.fibc                s   g | ]} |qS r   r   )re   r   )rY  r   r   rj   Q  s    z6TestLRU.test_lru_with_maxsize_none.<locals>.<listcomp>rN   r   r"   r#   r(   r=   r      r   "   7   Y         iy  ib     )rC  rD  r<  rE  )r?  r@  r3   rW   rA  
_CacheInforB  )r   r   )rY  r   test_lru_with_maxsize_noneK  s    &

z"TestLRU.test_lru_with_maxsize_nonec          	      sn   | j jdddd  x2dD ]*}|  fddtdD ttd qW |   | j jd	d
d	d	d d S )Ni)r<  c             S   s   | S )Nr   )r   r   r   r   eqZ  s    z2TestLRU.test_lru_with_maxsize_negative.<locals>.eq)r   r"   c                s   g | ]} |qS r   r   )re   r   )rc  r   r   rj   ^  s    z:TestLRU.test_lru_with_maxsize_negative.<locals>.<listcomp>   r   i,  )rC  rD  r<  rE  )r?  r@  r3   rW   r   rA  ra  )r   r   r   )rc  r   test_lru_with_maxsize_negativeY  s
    
*
z&TestLRU.test_lru_with_maxsize_negativec          
   C   s   xzdD ]r}| j |dd }| |dd | t}|d W d Q R X | |jj | t |d W d Q R X qW d S )N)N   c             S   s   d|  S )Nr   r   )r   r   r   r   r   g  s    z.TestLRU.test_lru_with_exceptions.<locals>.funcr   r&   rL  )r?  r@  r3   r9   r   ZassertIsNone	exception__context__)r   r<  r   cmr   r   r   test_lru_with_exceptionsb  s    
z TestLRU.test_lru_with_exceptionsc             C   s   xdD ]}| j j|dddd }| |dd | t|dtd | |dd	 | t|dtd	 | |dd
d | t|dd
td | |dd
d	 | t|dd
td	 | | jd | | jd qW d S )N)Nrf  T)r<  typedc             S   s   | |  S )Nr   )r-   r   r   r   squaret  s    z+TestLRU.test_lru_with_types.<locals>.squarer(   r   g      @g      "@)r-   r)   )r?  r@  r3   r   rA  rC  rD  )r   r<  rl  r   r   r   test_lru_with_typesr  s    
zTestLRU.test_lru_with_typesc                s   | j   fdd |  fddtdD ddddd	d
ddddddddddg |   | j jddddd    |   | j jddddd d S )Nc                s(   | dk r| S  | d d | d d S )Nr#   r"   )r   r   )r   )rY  r   r   rY    s    z/TestLRU.test_lru_with_keyword_args.<locals>.fibc                s   g | ]} |d qS ))r   r   )re   number)rY  r   r   rj     s    z6TestLRU.test_lru_with_keyword_args.<locals>.<listcomp>rN   r   r"   r#   r(   r=   r   rZ  r   r[  r\  r]  r^  r_  iy  ib  r`  rf  )rC  rD  r<  rE  )r?  r@  r3   rW   rA  ra  rB  )r   r   )rY  r   test_lru_with_keyword_args  s    &

z"TestLRU.test_lru_with_keyword_argsc                s   | j jd d fdd |  fddtdD dddd	d
dddddddddddg |   | j jddd dd    |   | j jddd dd d S )N)r<  c                s(   | dk r| S  | d d | d d S )Nr#   r"   )r   r   )r   )rY  r   r   rY    s    z<TestLRU.test_lru_with_keyword_args_maxsize_none.<locals>.fibc                s   g | ]} |d qS ))r   r   )re   rn  )rY  r   r   rj     s    zCTestLRU.test_lru_with_keyword_args_maxsize_none.<locals>.<listcomp>rN   r   r"   r#   r(   r=   r   rZ  r   r[  r\  r]  r^  r_  iy  ib  r`  )rC  rD  r<  rE  )r?  r@  r3   rW   rA  ra  rB  )r   r   )rY  r   'test_lru_with_keyword_args_maxsize_none  s    &

z/TestLRU.test_lru_with_keyword_args_maxsize_nonec          	   C   sj   | j jdddd }| |ddddd	g | |ddd
d	dg | | | j jddddd d S )Nr$   )r<  c              [   s   t |  S )N)r   items)rq   r   r   r   rK     s    z$TestLRU.test_kwargs_order.<locals>.fr"   r#   )r&   r'   )r&   r"   )r'   r#   )r'   r&   r   )rC  rD  r<  rE  )r?  r@  r3   rA  ra  )r   rK   r   r   r   test_kwargs_order  s
    
zTestLRU.test_kwargs_orderc             C   sJ   dddd}| j  |}x(| j jD ]}| t||t|| q&W d S )NZzomg_annotation)zomgc             S   s   dS )Nr   r   )rs  r   r   r   rK     s    z,TestLRU.test_lru_cache_decoration.<locals>.f)r?  r@  r   r3   rR   )r   rK   grv   r   r   r   test_lru_cache_decoration  s    z!TestLRU.test_lru_cache_decorationc       	   	      s  d\}dd j j| d   \}}}}|d t  fdd fdd	}t }t	d
 zfddt
|D }t|   W d Q R X   \}}}}j tkr|| || |  n || || |  || tj|dg}|fddt
|D 7 }  t|   W d Q R X W d t	| X d S )N)r=      c             S   s   d|  | S )Nr(   r   )r-   rJ   r   r   r   r;    s    z-TestLRU.test_lru_cache_threaded.<locals>.orig)r<  r   c                s8    d x(tD ]} | d| d qW d S )Nr$   r   )waitrW   r3   )r   r   )rK   mr;  r   startr   r   full  s    
z-TestLRU.test_lru_cache_threaded.<locals>.fullc                 s,    d xtd D ]}    qW d S )Nr$   r#   )rw  rW   rB  )r   )rK   rx  ry  r   r   clear  s    
z.TestLRU.test_lru_cache_threaded.<locals>.cleargư>c                s   g | ]}t j |gd qS ))targetr   )	threadingThread)re   r   )rz  r   r   rj     s   z3TestLRU.test_lru_cache_threaded.<locals>.<listcomp>)r|  c                s   g | ]}t j |gd qS ))r|  r   )r}  r~  )re   r   )rz  r   r   rj     s   )r?  r@  rA  r3   r}  ZEventr	   getswitchintervalr   setswitchintervalrW   start_threadssetro   r  r~  r{  )	r   r   rC  rD  r<  rE  r{  Zorig_sithreadsr   )rK   rz  rx  r;  r   ry  r   test_lru_cache_threaded  s:    


zTestLRU.test_lru_cache_threadedc          
      s   d\}t |d t |d t |d jj| dfdd   dd| df  fddfd	d
t|D }t|v xntD ]b}	d 
  	d 
  	d 
    d|d | | |d f qW W d Q R X d S )N)r=   r>   r"   )r<  c                s     d d|  S )Nr$   r(   )rw  )r-   )pauser   r   rK     s    
z+TestLRU.test_lru_cache_threaded2.<locals>.fr   c                 s>   x8t D ],} d  | d|   d q
W d S )Nr$   r(   )rW   rw  r3   )r   )rK   rx  r   ry  stopr   r   test  s    
z.TestLRU.test_lru_cache_threaded2.<locals>.testc                s   g | ]}t j d qS ))r|  )r}  r~  )re   r   )r  r   r   rj     s    z4TestLRU.test_lru_cache_threaded2.<locals>.<listcomp>r$   )r}  ZBarrierr?  r@  r3   rA  rW   r   r  rw  reset)r   r   r  r   r   )rK   rx  r  r   ry  r  r  r   test_lru_cache_threaded2  s"    


z TestLRU.test_lru_cache_threaded2c          	      s^   j jdddd   fddfddtd	ddd
dgD }t| W d Q R X d S )Nr#   )r<  c             S   s   t d d|  S )Ng{Gz?r(   )timeZsleep)r-   r   r   r   rK     s    
z+TestLRU.test_lru_cache_threaded3.<locals>.fc          	      s2   j | d  |d| |  W d Q R X d S )N)Zthreadr(   )r   r3   )r   r-   )rK   r   r   r   r    s    z.TestLRU.test_lru_cache_threaded3.<locals>.testc                s"   g | ]\}}t j ||fd qS ))r|  r   )r}  r~  )re   r   v)r  r   r   rj     s   z4TestLRU.test_lru_cache_threaded3.<locals>.<listcomp>r"   r(   )r?  r@  	enumerater   r  )r   r  r   )rK   r   r  r   test_lru_cache_threaded3  s    
z TestLRU.test_lru_cache_threaded3c                s^   | j jdddd G  fddd  d  d |  d d d S )	Nr$   )r<  c             S   s   | S )Nr   )r-   r   r   r   	test_func  s    z.TestLRU.test_need_for_rlock.<locals>.test_funcc                   s*   e Zd Zdd Zdd Z fddZdS )z-TestLRU.test_need_for_rlock.<locals>.DoubleEqc             S   s
   || _ d S )N)r-   )r   r-   r   r   r   r     s    z6TestLRU.test_need_for_rlock.<locals>.DoubleEq.__init__c             S   s   | j S )N)r-   )r   r   r   r   rP    s    z6TestLRU.test_need_for_rlock.<locals>.DoubleEq.__hash__c                s"   | j dkr d | j |j kS )Nr#   r"   )r-   )r   r   )DoubleEqr  r   r   r%    s    
z4TestLRU.test_need_for_rlock.<locals>.DoubleEq.__eq__N)r   r   r   r   rP  r%  r   )r  r  r   r   r    s   r  r"   r#   )r?  r@  r3   )r   r   )r  r  r   test_need_for_rlock
  s    zTestLRU.test_need_for_rlockc          	   C   s(   |  t tjdd }W d Q R X d S )Nc               S   s   d S )Nr   r   r   r   r   rK   %  s    z3TestLRU.test_early_detection_of_bad_call.<locals>.f)r9   r:   r   r@  )r   rK   r   r   r    test_early_detection_of_bad_call"  s    z(TestLRU.test_early_detection_of_bad_callc                s  G  fdddt }|d}|d}|d} |j d x&dD ]} |||d d  qDW  |j|j|jfd  |j d	 x&d
D ]} |||d d  qW  |j|j|jfd  |j d x&dD ]} |||d d  qW  |j|j|jfd  |j d  |j |j   |j |j   |j |j  d S )Nc                   s$   e Zd ZdZ jddd ZdS )z"TestLRU.test_lru_method.<locals>.Xr   r#   c             S   s   |  j d7  _ |d |  S )Nr"   r$   )r=  )r   r-   r   r   r   rK   ,  s    z$TestLRU.test_lru_method.<locals>.X.fN)r   r   r   r=  r?  r@  rK   r   )r   r   r   X*  s   r  r=   r>   )r   r   r#   r   )
r"   r#   r#   r(   r"   r"   r"   r#   r(   r(   r$   )r   r   r   )r)   r   r#   r#   )
r"   r#   r"   r"   r"   r"   r(   r#   r#   r#   )r   r)   r   )r$   r$   r#   r#   )
r#   r"   r"   r"   r"   r#   r"   r(   r#   r"   )r   r)   r=   )rL  rL  r#   r#   )rP   r3   rK   rA  r=  )r   r  r&   r'   r,   r-   r   )r   r   test_lru_method)  s(    


zTestLRU.test_lru_methodc             C   sx   | j }xl|jd |j|jfD ]T}xNttjd D ]<}| j||d$ tt	||}| 
|| W d Q R X q0W qW d S )Nr   r"   )r{   r   )	__class__cached_funccached_methcached_staticmethrW   rw   rx   r   ry   rz   r   )r   r   rK   r{   r|   r   r   r   r}   H  s    zTestLRU.test_picklec          
   C   s~   | j }dd }| j|d}|jd |j|j| jd|f}x:|D ]2}| j|d t|}| 	|| W d Q R X qDW d S )Nc             S   s   d|  | S )Nr(   r   )r-   rJ   r   r   r   r;  R  s    zTestLRU.test_copy.<locals>.origr#   r   )r   )
r  r?  r0   r  r  r  r@  r   r~   r   )r   r   r;  r   funcsrK   r|   r   r   r   r   P  s    

zTestLRU.test_copyc          
   C   s~   | j }dd }| j|d}|jd |j|j| jd|f}x:|D ]2}| j|d t	|}| 
|| W d Q R X qDW d S )Nc             S   s   d|  | S )Nr(   r   )r-   rJ   r   r   r   r;  ^  s    z#TestLRU.test_deepcopy.<locals>.origr#   r   )r   )r  r?  r0   r  r  r  r@  r   r~   r   r   )r   r   r;  r   r  rK   r|   r   r   r   r   \  s    

zTestLRU.test_deepcopyN)r   r   r   rH  rM  rN  rQ  rS  rT  rX  rb  re  rj  rm  ro  rp  rr  ru  r  r  r  r  r  r  r}   r   r   r   r   r   r   r:  |  s0   Y#		
0r:  c             C   s   d|  | S )Nr(   r   )r-   rJ   r   r   r   py_cached_funci  s    r  c             C   s   d|  | S )Nr(   r   )r-   rJ   r   r   r   c_cached_funcm  s    r  c               @   s:   e Zd ZeZefZe dd Ze	e dd Z
dS )	TestLRUPyc             C   s   d| | S )Nr(   r   )r   r-   rJ   r   r   r   r  v  s    zTestLRUPy.cached_methc             C   s   d|  | S )Nr(   r   )r-   rJ   r   r   r   r  z  s    zTestLRUPy.cached_staticmethN)r   r   r   ro   r?  r  r  r@  r  r   r  r   r   r   r   r  r  s
   r  c               @   s:   e Zd ZeZefZe dd Ze	e dd Z
dS )TestLRUCc             C   s   d| | S )Nr(   r   )r   r-   rJ   r   r   r   r    s    zTestLRUC.cached_methc             C   s   d|  | S )Nr(   r   )r-   rJ   r   r   r   r    s    zTestLRUC.cached_staticmethN)r   r   r   rn   r?  r  r  r@  r  r   r  r   r   r   r   r    s
   r  c               @   s   e Zd Zdd Zdd Zdd Zdd Zee	d	e
j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 )TestSingleDispatchc             C   s\   t jdd }dd }|t| | |dd | |dd | |dd	d
gd d S )Nc             S   s   dS )NrO   r   )r   r   r   r   rt    s    z3TestSingleDispatch.test_simple_overloads.<locals>.gc             S   s   dS )Nintegerr   )r   r   r   r   g_int  s    z7TestSingleDispatch.test_simple_overloads.<locals>.g_intrV   rO   r"   r  r#   r(   )r   singledispatchregisterrP   r3   )r   rt  r  r   r   r   test_simple_overloads  s    z(TestSingleDispatch.test_simple_overloadsc             C   s   t jdd }G dd d}G dd d|}G dd d|}G d	d
 d
||}dd }dd }||| ||| | || d | || d | || d | || d d S )Nc             S   s   dS )NrO   r   )r   r   r   r   rt    s    z&TestSingleDispatch.test_mro.<locals>.gc               @   s   e Zd ZdS )z&TestSingleDispatch.test_mro.<locals>.AN)r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdS )z&TestSingleDispatch.test_mro.<locals>.CN)r   r   r   r   r   r   r   C  s   r  c               @   s   e Zd ZdS )z&TestSingleDispatch.test_mro.<locals>.BN)r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdS )z&TestSingleDispatch.test_mro.<locals>.DN)r   r   r   r   r   r   r   D  s   r  c             S   s   dS )Nr   r   )r&   r   r   r   g_A  s    z(TestSingleDispatch.test_mro.<locals>.g_Ac             S   s   dS )Nr   r   )r'   r   r   r   g_B  s    z(TestSingleDispatch.test_mro.<locals>.g_B)r   r  r  r3   )r   rt  r   r  r   r  r  r  r   r   r   test_mro  s    zTestSingleDispatch.test_mroc             C   sn   t jdd }|tdd }| |dd | |dd | |t| | |t|t d S )	Nc             S   s   dS )NrO   r   )r   r   r   r   rt    s    z5TestSingleDispatch.test_register_decorator.<locals>.gc             S   s
   d| f S )Nzint %sr   )r   r   r   r   r    s    z9TestSingleDispatch.test_register_decorator.<locals>.g_intrT   rO   r>  zint 12)	r   r  r  rP   r3   r   dispatchrl   rV   )r   rt  r  r   r   r   test_register_decorator  s    z*TestSingleDispatch.test_register_decoratorc             C   s:   t jdd }| |jd tjjdk r6| |jd d S )Nc             S   s   dS )NZTestr   )r   r   r   r   rt    s    z6TestSingleDispatch.test_wrapping_attributes.<locals>.grt  r#   zSimple test)r   r  r3   r   r	   r   r   r   )r   rt  r   r   r   test_wrapping_attributes  s    z+TestSingleDispatch.test_wrapping_attributeszrequires _decimalc             C   s   t jdd }|tjdd }td}td}| ||d | ||d |tjd	d }| ||d
 | ||d d S )Nc             S   s   dS )NrO   r   )r   r   r   r   rt    s    z,TestSingleDispatch.test_c_classes.<locals>.gc             S   s   | j S )N)r   )r   r   r   r   r     s    z,TestSingleDispatch.test_c_classes.<locals>._zExponent < EminzNumber got rounded)zExponent < Emin)zNumber got roundedc             S   s   dS )NzToo small to care.r   )r   r   r   r   r     s    zToo small to care.)r   r  r  r   ZDecimalExceptionZ	SubnormalZRoundedr3   )r   rt  r   subnZrndr   r   r   test_c_classes  s    

z!TestSingleDispatch.test_c_classesc             C   s
  t j}tj}|j|j|j|jg}xBt|D ]6}|t	|}| 
|t	|j|j|j|j|j|jtg q*W |j|j|jt jg}xFt|D ]:}|t j|}| 
|t j|j|j|j|j|j|jtg qW |j|jtg}xBt|D ]6}|t j|j|jtg}| 
|t jt	|j|jtg qW G dd dt j}|j| |j|jg}xVt|D ]J}|||}| 
|||j|j|jt jt	|j|j|j|j|j|jtg qFW G dd dt j}|j|j|j|jg}xJt|D ]>}|||}| 
|||jt jt	|j|j|j|j|jtg
 qW d S )Nc               @   s   e Zd ZdS )z.TestSingleDispatch.test_compose_mro.<locals>.DN)r   r   r   r   r   r   r   r    s   r  c               @   s   e Zd Zdd ZdS )z.TestSingleDispatch.test_compose_mro.<locals>.Cc             S   s   d S )Nr   )r   r   r   r   __call__  s    z7TestSingleDispatch.test_compose_mro.<locals>.C.__call__N)r   r   r   r  r   r   r   r   r    s   r  )r  r   r   _compose_mroSequenceMutableMappingMappingSetr   r4   r3   
CollectionSizedIterable	Containerrl   OrderedDictChainMaprV   defaultdictMutableSequencer  
ReversibleCallable)r   r,   mrobasesZhaystackrx  r  r  r   r   r   test_compose_mro  sF    


z#TestSingleDispatch.test_compose_mroc             C   s  t j}ddi}dddg}t d h}t|}d}tjdd }| ||d	 | ||d	 | ||d	 | ||d	 | ||d	 ||jd
d  | ||d | ||d | ||d | ||d | ||d ||j	dd  | ||d | ||d | ||d | ||d | ||d |t j
dd  | ||d | ||d | ||d | ||d | ||d ||jdd  | ||d | ||d | ||d | ||d | ||d ||jdd  | ||d | ||d | ||d | ||d | ||d ||jdd  | ||d | ||d | ||d | ||d | ||d ||jdd  | ||d | ||d | ||d | ||d | ||d ||jdd  | ||d | ||d | ||d | ||d | ||d |tdd  | ||d | ||d | ||d | ||d | ||d |tdd  | ||d | ||d | ||d | ||d | ||d |tdd  | ||d | ||d | ||d | ||d | ||d |tdd  | ||d | ||d | ||d | ||d  | ||d |td!d  | ||d | ||d | ||d | ||d  | ||d" d S )#Nr&   r'   r"   r#   r(   )r"   r#   r(   c             S   s   dS )NrO   r   )r   r   r   r   rt    s    z/TestSingleDispatch.test_register_abc.<locals>.grO   c             S   s   dS )Nsizedr   )r   r   r   r   r.      r/   z6TestSingleDispatch.test_register_abc.<locals>.<lambda>r  c             S   s   dS )Nmutablemappingr   )r   r   r   r   r.   &  r/   r  c             S   s   dS )NZchainmapr   )r   r   r   r   r.   ,  r/   c             S   s   dS )Nmutablesequencer   )r   r   r   r   r.   2  r/   r  c             S   s   dS )N
mutablesetr   )r   r   r   r   r.   8  r/   r  c             S   s   dS )Nmappingr   )r   r   r   r   r.   >  r/   c             S   s   dS )Nsequencer   )r   r   r   r   r.   D  r/   r  c             S   s   dS )Nr  r   )r   r   r   r   r.   J  r/   r  c             S   s   dS )Nr4   r   )r   r   r   r   r.   P  r/   r4   c             S   s   dS )Nr   r   )r   r   r   r   r.   V  r/   r   c             S   s   dS )Nzconcrete-setr   )r   r   r   r   r.   \  r/   zconcrete-setc             S   s   dS )Nz
frozen-setr   )r   r   r   r   r.   b  r/   z
frozen-setc             S   s   dS )Nr   r   )r   r   r   r   r.   h  r/   r   )r  r   rl   	frozensetr   r  r3   r  r  r  r  r  
MutableSetr  r  r  r4   r   r  r   )r   r,   r?   lr   rK   trt  r   r   r   test_register_abc  s    

z$TestSingleDispatch.test_register_abcc          	   C   s   t j}tj}G dd dt}G dd d|}|jjG dd dt}G dd dt}G d	d
 d
|||}||j|||j||j|tg	}x0t	|j|j|jgD ]}	| 
|||	d| qW |j|j|j|j|jg}
| 
|||
d| d S )Nc               @   s   e Zd ZdS )z)TestSingleDispatch.test_c3_abc.<locals>.AN)r   r   r   r   r   r   r   r   r  s   r   c               @   s   e Zd Zdd ZdS )z)TestSingleDispatch.test_c3_abc.<locals>.Bc             S   s   dS )Nr   r   )r   r   r   r   r   u  s    z1TestSingleDispatch.test_c3_abc.<locals>.B.__len__N)r   r   r   r   r   r   r   r   r   t  s   r   c               @   s   e Zd ZdS )z)TestSingleDispatch.test_c3_abc.<locals>.CN)r   r   r   r   r   r   r   r  w  s   r  c               @   s   e Zd ZdS )z)TestSingleDispatch.test_c3_abc.<locals>.DN)r   r   r   r   r   r   r   r  z  s   r  c               @   s   e Zd Zdd ZdS )z)TestSingleDispatch.test_c3_abc.<locals>.Xc             S   s   d S )Nr   )r   r   r   r   r  }  s    z2TestSingleDispatch.test_c3_abc.<locals>.X.__call__N)r   r   r   r  r   r   r   r   r  |  s   r  )abcs)r  r   r   _c3_mrorl   r  r  r  r  r   r3   r  r  )r   r,   r  r   r   r  r  r  rD   r  Z	many_abcsr   r   r   test_c3_abco  s    zTestSingleDispatch.test_c3_abcc             C   sl   G dd dt }G dd d|d}G dd d|}tjdd	 }||d
d }| }| ||d d S )Nc               @   s   e Zd Zdd ZdS )z1TestSingleDispatch.test_false_meta.<locals>.MetaAc             S   s   dS )Nr   r   )r   r   r   r   r     s    z9TestSingleDispatch.test_false_meta.<locals>.MetaA.__len__N)r   r   r   r   r   r   r   r   MetaA  s   r  c               @   s   e Zd ZdS )z-TestSingleDispatch.test_false_meta.<locals>.AN)r   r   r   r   r   r   r   r     s   r   )	metaclassc               @   s   e Zd ZdS )z.TestSingleDispatch.test_false_meta.<locals>.AAN)r   r   r   r   r   r   r   AA  s   r  c             S   s   dS )Nzbase Ar   )r&   r   r   r   fun  s    z/TestSingleDispatch.test_false_meta.<locals>.func             S   s   dS )Nzfun Ar   )r&   r   r   r   r     s    z-TestSingleDispatch.test_false_meta.<locals>._zfun A)r   r   r  r  r3   )r   r  r   r  r  r   Zaar   r   r   test_false_meta  s    z"TestSingleDispatch.test_false_metac          	   C   s  t j}tjdd }G dd d|j}| }| ||d ||jdd  ||jdd  ||jd	d  ||j	d
d  | ||d |j| | ||d |j| | ||d |j	| | ||d G dd d}| }| ||d |j| | ||d |j| | 
t}|| W d Q R X | t|jd G dd d|j}| }	| ||	d |j| | ||	d |j	| | ||	d tjdd }
|
|jdd }|
|jdd }| 
t}|
t dd  W d Q R X | t|jd G dd dt j}|j| tjdd }||jdd }||jdd }| }| ||d  G d!d" d"}G d#d$ d$||j}| }| |
|d |j| | |
|d G d%d& d&}| }| |
|d |j| | 
t}|
| W d Q R X | t|jd G d'd( d(|j|}tjd)d* }||d+d }||jd,d }| }| ||d- |j| | ||d. d S )/Nc             S   s   dS )NrO   r   )argr   r   r   rt    s    z0TestSingleDispatch.test_mro_conflicts.<locals>.gc               @   s   e Zd Zdd ZdS )z0TestSingleDispatch.test_mro_conflicts.<locals>.Oc             S   s   dS )Nr   r   )r   r   r   r   r     s    z8TestSingleDispatch.test_mro_conflicts.<locals>.O.__len__N)r   r   r   r   r   r   r   r   O  s   r  rO   c             S   s   dS )Niterabler   )r  r   r   r   r.     r/   z7TestSingleDispatch.test_mro_conflicts.<locals>.<lambda>c             S   s   dS )N	containerr   )r  r   r   r   r.     r/   c             S   s   dS )Nr  r   )r  r   r   r   r.     r/   c             S   s   dS )Nr  r   )r  r   r   r   r.     r/   r  r  c               @   s   e Zd ZdS )z0TestSingleDispatch.test_mro_conflicts.<locals>.PN)r   r   r   r   r   r   r   P  s   r  r  )z]Ambiguous dispatch: <class 'collections.abc.Container'> or <class 'collections.abc.Iterable'>z]Ambiguous dispatch: <class 'collections.abc.Iterable'> or <class 'collections.abc.Container'>c               @   s   e Zd Zdd ZdS )z0TestSingleDispatch.test_mro_conflicts.<locals>.Qc             S   s   dS )Nr   r   )r   r   r   r   r     s    z8TestSingleDispatch.test_mro_conflicts.<locals>.Q.__len__N)r   r   r   r   r   r   r   r   Q  s   r  c             S   s   dS )NrO   r   )r  r   r   r   h  s    z0TestSingleDispatch.test_mro_conflicts.<locals>.hc             S   s   dS )Nr  r   )r  r   r   r   r     s    z0TestSingleDispatch.test_mro_conflicts.<locals>._c             S   s   dS )Nr  r   )r  r   r   r   r     s    c               S   s   dS )Nr   r   r   r   r   r   r.     r/   )zZAmbiguous dispatch: <class 'collections.abc.Container'> or <class 'collections.abc.Sized'>zZAmbiguous dispatch: <class 'collections.abc.Sized'> or <class 'collections.abc.Container'>c               @   s   e Zd ZdS )z0TestSingleDispatch.test_mro_conflicts.<locals>.RN)r   r   r   r   r   r   r   R  s   r  c             S   s   dS )NrO   r   )r  r   r   r   r     s    z0TestSingleDispatch.test_mro_conflicts.<locals>.ic             S   s   dS )Nr  r   )r  r   r   r   r     s    c             S   s   dS )Nr  r   )r  r   r   r   r     s    r  c               @   s   e Zd ZdS )z0TestSingleDispatch.test_mro_conflicts.<locals>.SN)r   r   r   r   r   r   r   S  s   r  c               @   s   e Zd Zdd ZdS )z0TestSingleDispatch.test_mro_conflicts.<locals>.Tc             S   s   dS )Nr   r   )r   r   r   r   r     s    z8TestSingleDispatch.test_mro_conflicts.<locals>.T.__len__N)r   r   r   r   r   r   r   r   T  s   r  c               @   s   e Zd Zdd ZdS )z0TestSingleDispatch.test_mro_conflicts.<locals>.Uc             S   s   dS )Nr   r   )r   r   r   r   r     s    z8TestSingleDispatch.test_mro_conflicts.<locals>.U.__len__N)r   r   r   r   r   r   r   r   U  s   r  c               @   s   e Zd Zdd ZdS )z0TestSingleDispatch.test_mro_conflicts.<locals>.Vc             S   s   dS )Nr   r   )r   r   r   r   r     s    z8TestSingleDispatch.test_mro_conflicts.<locals>.V.__len__N)r   r   r   r   r   r   r   r   V  s   r  c             S   s   dS )NrO   r   )r  r   r   r   j	  s    z0TestSingleDispatch.test_mro_conflicts.<locals>.jc             S   s   dS )Nr   r   )r  r   r   r   r     s    c             S   s   dS )Nr  r   )r  r   r   r   r     s    r   r  )r  r   r   r  r  r3   r  r  r  r  r9   r   rp   rV   rg  r  r  r  )r   r,   rt  r  rU  r  r6   Zre_oner  qr  r   Zre_twor  r   r   r  r  r  r  uZre_threer  r  r  r   r   r   test_mro_conflicts  s    z%TestSingleDispatch.test_mro_conflictsc                sH  ddl m} dd l}G  fddd|   t|dfdd t j}tjdd	 }i }g }| t	d | ||d
 | t	d | j
g  | jtg | jt |jt  | ||d
 | t	d | j
g  | jttg | jt |jt  | jt |jt  | jt jt  | ||d
 | ||d
 | j
ttg | jttg |tdd  | j
ttg | t	d | ||d
 | t	d | j
ttg | jtttg | jt tt|j | ||d | t	d | j
ttg | jttttg | jt tt|j G dd d}|j| | ||d
 | ||d | j
ttttg | jttttg ||jdd  | t	d | ||d | t	d | j
ttttg | jtttttg | ||d | t	d | j
ttttg | jttttttg | ||d | ||d | j
ttttttg | jttttttg |t |t | j
ttttttttg | jttttttg |j| | t	d | ||d | t	d ||jdd  | t	d | ||d | t	d | ||d | t	d |tdd  | ||d | ||d |  | t	d W d Q R X d S )Nr   )UserDictc                   s6   e Zd Z fddZdd Zdd Zdd Z  ZS )	z?TestSingleDispatch.test_cache_invalidation.<locals>.TracingDictc                s"   t  | j|| g | _g | _d S )N)superr   set_opsget_ops)r   r   rq   )TracingDictr  r   r   r     s    zHTestSingleDispatch.test_cache_invalidation.<locals>.TracingDict.__init__c             S   s   | j | }| j| |S )N)rY   r  r   )r   r   resultr   r   r   r   !  s    
zKTestSingleDispatch.test_cache_invalidation.<locals>.TracingDict.__getitem__c             S   s   | j | || j|< d S )N)r  r   rY   )r   r   r   r   r   r   __setitem__%  s    zKTestSingleDispatch.test_cache_invalidation.<locals>.TracingDict.__setitem__c             S   s   | j   d S )N)rY   r{  )r   r   r   r   r{  (  s    zETestSingleDispatch.test_cache_invalidation.<locals>.TracingDict.clear)r   r   r   r   r   r  r{  __classcell__r   )r  )r  r   r    s   r  WeakKeyDictionaryc                  s    S )Nr   r   )tdr   r   r.   ,  r/   z<TestSingleDispatch.test_cache_invalidation.<locals>.<lambda>c             S   s   dS )NrO   r   )r  r   r   r   rt  .  s    z5TestSingleDispatch.test_cache_invalidation.<locals>.grO   r"   r#   c             S   s   dS )Nr   r   )r  r   r   r   r.   D  r/   r   c               @   s   e Zd ZdS )z5TestSingleDispatch.test_cache_invalidation.<locals>.XN)r   r   r   r   r   r   r   r  S  s   r  c             S   s   dS )Nr  r   )r  r   r   r   r.   [  r/   r  c             S   s   dS )Nr  r   )r  r   r   r   r.   r  r/   r  c             S   s   dS )Nr4   r   )r  r   r   r   r.   x  r/   r4   )r  r  weakrefr   Z	swap_attrr   r   r  r3   r   r  r  r4   rY   registryrl   r   r  
_find_implr  r  r  r  _clear_cache)r   r  r  r,   rt  r?   r  r  r   )r  r  r   test_cache_invalidation  s    


z*TestSingleDispatch.test_cache_invalidationc             C   s   t jdd }|jtjjddd}|jdddd}| |d d | |d	d
id | |d
ddgd | |dd | |dd |tG dd d}| |dd d S )Nc             S   s   dS )NrO   r   )r  r   r   r   r     s    z.TestSingleDispatch.test_annotations.<locals>.i)r  c             S   s   dS )Nr  r   )r  r   r   r   r     s    z.TestSingleDispatch.test_annotations.<locals>._zcollections.abc.Sequencec             S   s   dS )Nr  r   )r  r   r   r   r     s    rO   r&   r"   r  r#   r(   r  )r"   r#   r(   rV   c               @   s   e Zd Zdd Zdd ZdS )z.TestSingleDispatch.test_annotations.<locals>._c             S   s
   || _ d S )N)r  )r   r  r   r   r   r     s    z7TestSingleDispatch.test_annotations.<locals>._.__init__c             S   s
   | j |kS )N)r  )r   r   r   r   r   r%    s    z5TestSingleDispatch.test_annotations.<locals>._.__eq__N)r   r   r   r   r%  r   r   r   r   r     s   r   )r   r  r  r  r   r  r3   rV   )r   r   r   r   r   r   test_annotations~  s    z#TestSingleDispatch.test_annotationsc          	   C   s   d}d}t jdd }| t}|ddd }W d Q R X | t|j|d  | t|j	| | t}|jd	d }W d Q R X | t|j|d
  | t|j	| d S Q R X | t|j|d
  | t|j	| d S )Nz(Invalid first argument to `register()`: zS. Use either `@register(some_class)` or plain `@register` on an annotated function.c             S   s   dS )NrO   r   )r  r   r   r   r     s    z8TestSingleDispatch.test_invalid_registrations.<locals>.ir   c             S   s   dS )NzI annotated with a non-typer   )r  r   r   r   r     s    z8TestSingleDispatch.test_invalid_registrations.<locals>._Z42c             S   s   dS )NzI forgot to annotater   )r  r   r   r   r     s    zB<function TestSingleDispatch.test_invalid_registrations.<locals>._)r  c             S   s   dS )Nz%I annotated with a generic collectionr   )r  r   r   r   r     s    )r   r  r9   r:   r  r1   rV   rg  r   endswithtypingr  )r   Z
msg_prefixZ
msg_suffixr   excr   r   r   r   test_invalid_registrations  s&    
  
z-TestSingleDispatch.test_invalid_registrationsc          	   C   s4   t jdd }d}| t| |  W d Q R X d S )Nc              W   s   d S )Nr   )r   r   r   r   rK     s    z>TestSingleDispatch.test_invalid_positional_argument.<locals>.fz)f requires at least 1 positional argument)r   r  ZassertRaisesRegexr:   )r   rK   msgr   r   r    test_invalid_positional_argument  s    z3TestSingleDispatch.test_invalid_positional_argumentN)r   r   r   r  r  r  r  r   
skipUnlessr   r   Zcpython_onlyr  r  r  r  r  r  r  r  r  r  r   r   r   r   r    s    	
6^ f(r  __main__)@r   rR  r  Zcollections.abcr~   	itertoolsr   rw   Zrandomr   r	   r  r   r}  r  r  r   Zunittest.mockr  r   
contextlibr   Zimport_fresh_modulero   rn   r   contextmanagerr   r   r   r   r   r   r4   r    r!   r  ZTestCaser   r   r0   r   r   r   r   r   r   r   r   r  r"  r#  r$  r&  r9  r:  r@  r  r  r  r  r  r   mainr   r   r   r   <module>   s   	  F3|r=
RS L
   p    ?
