
                              d dl Z d dlZd dlZ G d d      Z G d d      Z G d de j
                  e      Z G d d	e j
                  e      Z G d
 de j
                        Zy)    Nc                       e Zd Zd Zd Zd Zy)CountedLockc                     d| _         y Nr   countselfs    ;platform/gsutil/third_party/cachetools/tests/test_cached.py__init__zCountedLock.__init__   s	    
    c                 .    | xj                   dz  c_         y )N   r   r	   s    r   	__enter__zCountedLock.__enter__   s    

a
r   c                      y N )r
   excs     r   __exit__zCountedLock.__exit__   s    r   N)__name__
__module____qualname__r   r   r   r   r   r   r   r      s    r   r   c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)DecoratorTestMixinc                     t         r   )NotImplementedErrorr
   minsizes     r   cachezDecoratorTestMixin.cache   s    !!r   c                     t        | d      r!| xj                  dz  c_        | j                  S d| _        | j                  S )Nr   r   r   )hasattrr   r
   argskwargss      r   funczDecoratorTestMixin.func   s8    4!JJ!OJ zz DJzzr   c                    | j                  d      } t        j                  |      | j                        }| j	                  t        |      d       | j	                   |d      d       | j	                  t        |      d       | j                  t        j                  j                  d      |       | j                  t        j                  j                  d      |       | j                  t        j                  j                  d      |       | j	                   |d      d       | j	                  t        |      d       | j                  t        j                  j                  d      |       | j                  t        j                  j                  d      |       | j                  t        j                  j                  d      |       | j	                   |d      d       | j	                  t        |      d       | j	                   |d      d       | j	                  t        |      d       | j	                   |d      d       | j	                  t        |      d       y )N   r   r         ?)
r   
cachetoolscachedr%   assertEquallenassertInkeyshashkeyassertNotInr
   r   wrappers      r   test_decoratorz!DecoratorTestMixin.test_decorator   s   

1**##E*4995UQ'Q'UQ'joo--a0%8003U;005u=Q'UQ'joo--a0%8joo--a0%8joo--c2E:Q'UQ'q)UQ'q)UQ'r   c                 *   | j                  d      }t        j                  j                  } t        j                  ||      | j
                        }| j                  t        |      d       | j                   |d      d       | j                  t        |      d       | j                  t        j                  j                  d      |       | j                  t        j                  j                  d      |       | j                  t        j                  j                  d      |       | j                   |d      d       | j                  t        |      d       | j                  t        j                  j                  d      |       | j                  t        j                  j                  d      |       | j                  t        j                  j                  d      |       | j                   |d      d       | j                  t        |      d       | j                   |d      d       | j                  t        |      d       | j                  t        j                  j                  d      |       | j                  t        j                  j                  d      |       | j                  t        j                  j                  d      |       | j                   |d      d       | j                  t        |      d       y )N   )keyr   r   r(   r'   )
r   r)   r.   typedkeyr*   r%   r+   r,   r-   r0   )r
   r   r6   r2   s       r   test_decorator_typedz'DecoratorTestMixin.test_decorator_typed7   s"   

1oo&&3*##Es3DII>UQ'Q'UQ'joo..q15911!4e<11#6>Q'UQ'joo..q159joo..q15911#6>Q'UQ'q)UQ'joo..q159joo..q159joo..s3U;q)UQ'r   c                    | j                  d      }t               } t        j                  ||      | j                        }| j                  t        |      d       | j                   |d      d       | j                  |j                  d       | j                   |d      d       | j                  |j                  d       | j                   |d      d       | j                  |j                  d       y )Nr'   lockr   r         r   r   r)   r*   r%   r+   r,   r   r
   r   r;   r2   s       r   test_decorator_lockz&DecoratorTestMixin.test_decorator_lockU   s    

1}5*##E5dii@UQ'Q'Q'Q'Q'Q'Q'r   c                 6   | j                  d      } t        j                  |      | j                        }| j	                  |j
                  | j                         | j	                  t        |      d       | j	                  |j                  d      d       | j	                  t        |      d       | j	                   |d      d       | j	                  t        |      d       | j	                   |d      d       | j	                  t        |      d       y Nr'   r   r   )r   r)   r*   r%   r+   __wrapped__r,   r1   s      r   test_decorator_wrappedz)DecoratorTestMixin.test_decorator_wrappedb   s    

1**##E*4995,,dii8UQ',,Q/3UQ'Q'UQ'Q'UQ'r   c                 H   | j                  d      } t        j                  |      | j                        }| j	                  |j                   |       | j	                  |j
                  t        j                  j                         | j	                  |j                  d        y )Nr'   )	r   r)   r*   r%   assertIs	cache_keyr.   r/   
cache_lockr1   s      r   test_decorator_attributesz,DecoratorTestMixin.test_decorator_attributesp   sn    

1**##E*4995gmmU+g'')@)@Ag(($/r   c                 `   | j                  d      }t               } t        j                  ||      | j                        }| j                  |j                   |       | j                  |j                  t        j                  j                         | j                  |j                  |       y )Nr'   r:   )
r   r   r)   r*   r%   rF   rG   r.   r/   rH   r?   s       r   test_decorator_attributes_lockz1DecoratorTestMixin.test_decorator_attributes_lockx   sw    

1}5*##E5dii@gmmU+g'')@)@Ag(($/r   c                 ,   | j                  d      } t        j                  |      | j                        }| j	                   |d      d       | j	                  t        |      d       |j                          | j	                  t        |      d       y rB   )r   r)   r*   r%   r+   r,   cache_clearr1   s      r   test_decorator_clearz'DecoratorTestMixin.test_decorator_clear   sr    

1**##E*4995Q'UQ'UQ'r   c                    | j                  d      }t               } t        j                  ||      | j                        }| j                   |d      d       | j                  t        |      d       | j                  |j                  d       |j                          | j                  t        |      d       | j                  |j                  d       y )Nr'   r:   r   r   r5   )	r   r   r)   r*   r%   r+   r,   r   rM   r?   s       r   test_decorator_clear_lockz,DecoratorTestMixin.test_decorator_clear_lock   s    

1}5*##E5dii@Q'UQ'Q'UQ'Q'r   N)r   r   r   r   r%   r3   r8   r@   rD   rI   rK   rN   rP   r   r   r   r   r      s4    "(4(<((00(	(r   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)CacheWrapperTestc                 .    t        j                  |      S )N)maxsize)r)   Cacher   s     r   r   zCacheWrapperTest.cache   s    00r   c                    | j                  d      } t        j                  |d      | j                        }| j	                  |j                         d       | j	                   |d      d       | j	                  |j                         d       | j	                   |d      d       | j	                  |j                         d       | j	                   |d      d       | j	                  |j                         d	       |j                          | j	                  t        |      d       | j	                  |j                         d       y )
Nr'   Tinfo)r   r   r'   r   r   )r   r   r'   r   r   )r   r'   r'   r'   )r   r'   r'   r'   r   r)   r*   r%   r+   
cache_inforM   r,   r1   s      r   test_decorator_infoz$CacheWrapperTest.test_decorator_info   s   

15*##E5dii@++-|<Q'++-|<Q'++-|<Q'++-|<UQ'++-|<r   c                    | j                  d      } t        j                  |      | j                        }| j	                  t        |      d       | j	                   |d      d       | j	                  t        |      d       y r   )r   r)   r*   r%   r+   r,   r1   s      r   test_zero_size_cache_decoratorz/CacheWrapperTest.test_zero_size_cache_decorator   sf    

1**##E*4995UQ'Q'UQ'r   c                 \   | j                  d      }t               } t        j                  ||      | j                        }| j                  t        |      d       | j                   |d      d       | j                  t        |      d       | j                  |j                  d       y )Nr   r:   r'   r>   r?   s       r   #test_zero_size_cache_decorator_lockz4CacheWrapperTest.test_zero_size_cache_decorator_lock   s    

1}5*##E5dii@UQ'Q'UQ'Q'r   c                 $   | j                  d      } t        j                  |d      | j                        }| j	                  |j                         d       | j	                   |d      d       | j	                  |j                         d       y )Nr   TrW   r   r   r   r   r   r   r   r   )r   r)   r*   r%   r+   rZ   r1   s      r   #test_zero_size_cache_decorator_infoz4CacheWrapperTest.test_zero_size_cache_decorator_info   sr    

15*##E5dii@++-|<Q'++-|<r   N)r   r   r   r   r[   r]   r_   rc   r   r   r   rR   rR      s    1=((=r   rR   c                       e Zd Zd Zd Zy)DictWrapperTestc                     t               S r   )dictr   s     r   r   zDictWrapperTest.cache   s	    vr   c                    | j                  d      } t        j                  |d      | j                        }| j	                  |j                         d       | j	                   |d      d       | j	                  |j                         d       | j	                   |d      d       | j	                  |j                         d       | j	                   |d      d       | j	                  |j                         d	       |j                          | j	                  t        |      d       | j	                  |j                         d       y )
Nr'   TrW   )r   r   Nr   r   )r   r   Nr   r   )r   r'   Nr'   )r   r'   Nr'   rY   r1   s      r   r[   z#DictWrapperTest.test_decorator_info   s   

15*##E5dii@++-?Q'++-?Q'++-?Q'++-?UQ'++-?r   N)r   r   r   r   r[   r   r   r   re   re      s    @r   re   c                   *    e Zd Zd Zd Zd Zd Zd Zy)NoneWrapperTestc                 :    |t        |j                               z   S r   )tupleitemsr"   s      r   r%   zNoneWrapperTest.func   s    eFLLN+++r   c                      t        j                  d       | j                        }| j                   |d      d       | j                   |d      d       | j                   |dd      d       y )Nr   r   r   r   bar)foo)r   )rr   rq   )r)   r*   r%   r+   r
   r2   s     r   r3   zNoneWrapperTest.test_decorator   s]    )*##D)$))4T*T*.0CDr   c                 &    t        j                  d       | j                        }| j                  |j                  d        | j                  |j
                  t         j                  j                         | j                  |j                  d        y r   )	r)   r*   r%   rF   r   rG   r.   r/   rH   rs   s     r   rI   z)NoneWrapperTest.test_decorator_attributes   sa    )*##D)$))4gmmT*g'')@)@Ag(($/r   c                 n     t        j                  d       | j                        }|j                          y r   )r)   r*   r%   rM   rs   s     r   rN   z$NoneWrapperTest.test_decorator_clear   s)    )*##D)$))4r   c                     t        j                  d d      | j                        }| j                  |j	                         d       | j                   |d      d       | j                  |j	                         d       | j                   |d      d       | j                  |j	                         d	       |j                          | j                  |j	                         d       y )
NTrW   ra   r   ro   rb   r   rp   )r   r'   r   r   )r)   r*   r%   r+   rZ   rM   rs   s     r   r[   z#NoneWrapperTest.test_decorator_info   s    4*##Dt4TYY?++-|<T*++-|<T*++-|<++-|<r   N)r   r   r   r%   r3   rI   rN   r[   r   r   r   rj   rj      s    ,E0
	=r   rj   )	unittestr)   cachetools.keysr   r   TestCaserR   re   rj   r   r   r   <module>rz      sd       @( @(F*=x((*< *=Z@h''); @& =h''  =r   