B
    SV              
   @   s   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Zd dl	Z	d dl
Z
yd dl
mZ W n( ek
r   eddddd	gZY nX G d
d dejZdS )    N)permutations)choice)
_CacheInfo	CacheInfohitsmissesmaxsizecurrsizec               @   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 )TestLRUc                sr  dd }t jdd|}| \}}}}| |d | |d | |d | |d td}xBtdD ]6}t|t| }	}
||	|
}||	|
}| || qjW | \}}}}| ||k | || d | |d |  | \}}}}| |d | |d | |d ||	|
 | \}}}}| |d | |d | |d t| d	rr| 	|j
| |
|	|
 | \}}}}| |d | |d | |d t d fd
d}| | jd dg x tdD ]}| | d qW |  dg | \}}}}| |d | |d | |d t d fdd}| | jd d d< x tdD ]}| | d q~W |  dg | \}}}}| |d | |d | |d t d fdd}| | jd d d< x"dD ]}	| ||	|	d  qW |  dg | \}}}}| |d | |d | |d d S )Nc             S   s   d|  | S )N    )xyr   r   =lib/python3.7/site-packages/fastcache/tests/test_functools.pyorig   s    zTestLRU.test_lru.<locals>.orig   )r   r      i     assertIsc                  s    d  d7  < dS )Nr   r   r   r   r   )f_cntr   r   f?   s    zTestLRU.test_lru.<locals>.fc                  s    d  d7  < dS )Nr   r   r   r   r   )r   r   r   r   O   s          c                s    d  d7  < | d S )Nr   r   
   r   )r   )r   r   r   r   _   s    )   	   r   r   r   r      r   r   r   r   r   r   r   r   r   r      )	fastcache
clru_cache
cache_infoassertEqualranger   Z
assertTruecache_clearhasattrr   __wrapped__r   )selfr   r   r   r   r   r	   Zdomainir   r   ZactualZexpectedr   )r   r   test_lru   s    



zTestLRU.test_lruc                s   t 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 |   tddd dd    |   tddd dd d S )N)r   c                s$   | dk r| S  | d  | d  S )Nr   r   r   )n)fibr   r   r*   p   s    z/TestLRU.test_lru_with_maxsize_none.<locals>.fibc                s   g | ]} |qS r   r   ).0r)   )r*   r   r   
<listcomp>u   s    z6TestLRU.test_lru_with_maxsize_none.<locals>.<listcomp>   r   r   r   r   r   r         "   7   Y         iy  ib     )r   r   r   r	   )r   r   r!   r"   r    r   r#   )r&   r   )r*   r   test_lru_with_maxsize_noneo   s    &

z"TestLRU.test_lru_with_maxsize_nonec          
   C   s   xdD ]}t |dd }| |dd yZ| t}|d W d Q R X t|jdrf| |jj | t |d W d Q R X W q t	k
r   t
jd d d	kr n Y qX qW d S )
N)N   c             S   s   d|  S )Nabcr   )r'   r   r   r   func   s    z.TestLRU.test_lru_with_exceptions.<locals>.funcr   a   __context__r   )r      )r   r   r!   ZassertRaises
IndexErrorr$   Z	exceptionZassertIsNoner<   	TypeErrorsysversion_info)r&   r   r9   cmr   r   r   test_lru_with_exceptions}   s    
z TestLRU.test_lru_with_exceptionsc             C   s   xdD ]}t 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)Nr7   T)r   typedc             S   s   | |  S )Nr   )r   r   r   r   square   s    z+TestLRU.test_lru_with_types.<locals>.squarer   r   g      @g      "@)r   r   )r   r   r!   typer    r   r   )r&   r   rE   r   r   r   test_lru_with_types   s    
zTestLRU.test_lru_with_typesc                s   t   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 |   tddddd    |   tddddd d S )Nc                s(   | dk r| S  | d d | d d S )Nr   r   )r)   r   )r)   )r*   r   r   r*      s    z/TestLRU.test_lru_with_keyword_args.<locals>.fibc                s   g | ]} |d qS ))r)   r   )r+   number)r*   r   r   r,      s    z6TestLRU.test_lru_with_keyword_args.<locals>.<listcomp>r-   r   r   r   r   r   r   r.   r/   r0   r1   r2   r3   r4   iy  ib  r5   r7   )r   r   r   r	   )r   r   r!   r"   r    r   r#   )r&   r   )r*   r   test_lru_with_keyword_args   s    &

z"TestLRU.test_lru_with_keyword_argsc                s   t 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 |   tddd dd    |   t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)   )r*   r   r   r*      s    z<TestLRU.test_lru_with_keyword_args_maxsize_none.<locals>.fibc                s   g | ]} |d qS ))r)   r   )r+   rH   )r*   r   r   r,      s    zCTestLRU.test_lru_with_keyword_args_maxsize_none.<locals>.<listcomp>r-   r   r   r   r   r   r   r.   r/   r0   r1   r2   r3   r4   iy  ib  r5   )r   r   r   r	   )r   r   r!   r"   r    r   r#   )r&   r   )r*   r   'test_lru_with_keyword_args_maxsize_none   s    &

z/TestLRU.test_lru_with_keyword_args_maxsize_nonec                s\   t jdddd G  fddd  d  d |  d d d S )	Nr   )r   c             S   s   | S )zEUsed to demonstrate a reentrant lru_cache call within a single threadr   )r   r   r   r   	test_func   s    z.TestLRU.test_need_for_rlock.<locals>.test_funcc                   s.   e Zd ZdZdd Zdd Z fddZdS )	z-TestLRU.test_need_for_rlock.<locals>.DoubleEqz=Demonstrate a reentrant lru_cache call within a single threadc             S   s
   || _ d S )N)r   )r&   r   r   r   r   __init__   s    z6TestLRU.test_need_for_rlock.<locals>.DoubleEq.__init__c             S   s   | j S )N)r   )r&   r   r   r   __hash__   s    z6TestLRU.test_need_for_rlock.<locals>.DoubleEq.__hash__c                s"   | j dkr d | j |j kS )Nr   r   )r   )r&   other)DoubleEqrK   r   r   __eq__   s    
z4TestLRU.test_need_for_rlock.<locals>.DoubleEq.__eq__N)__name__
__module____qualname____doc__rL   rM   rP   r   )rO   rK   r   r   rO      s   rO   r   r   )r   r   r!   )r&   r   )rO   rK   r   test_need_for_rlock   s    zTestLRU.test_need_for_rlockN)
rQ   rR   rS   r(   r6   rC   rG   rI   rJ   rU   r   r   r   r   r
      s   Zr
   )r8   collections	itertoolsr   pickleZrandomr   r@   Zunittestr   	functoolsr   ImportError
namedtupleZTestCaser
   r   r   r   r   <module>   s   