
:W                 @   s   d  d l  Z d  d l j j Z d  d l Z d  d l m Z Gd d   d  Z	 Gd d   d e	  Z
 Gd d   d e	  Z d	 d
   Z d S)    N)	cacheutilc               @   sR   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d S)BasicCacheAPITestNc             C   s  |  j  j d d d    } d } | | k } | s t j d | f d | | f  d d t j   k su t j |  r t j |  n d d t j |  i } d d | i } t t j	 |    d  } } |  j  j d d d    } d } | | k } | st j d | f d | | f  d d t j   k sAt j |  rPt j |  n d d t j |  i } d d | i } t t j	 |    d  } } d  S)N*   c               S   s   d S)Nr    r   r   r   A/home/ronny/Projects/pytest-dev/py/testing/path/test_cacheutil.py<lambda>   s    z3BasicCacheAPITest.test_getorbuild.<locals>.<lambda>==%(py0)s == %(py3)spy0valpy3 assert %(py5)spy5c               S   s   d S)N   r   r   r   r   r   r   	   s    i)r   )r	   r   i)r   )r	   r   )
cache
getorbuild
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanation)selfr   @py_assert2@py_assert1@py_format4@py_format6r   r   r   test_getorbuild   s        j   
   j   z!BasicCacheAPITest.test_getorbuildc             C   s   t  j j t d  d  S)Nzself.cache._getentry(-23))pytestraisesKeyError)r   r   r   r   test_cache_get_key_error   s    z*BasicCacheAPITest.test_cache_get_key_errorc             C   sB   |  j  j d d d    } |  j  j d  t j j t d  d  S)Nd   c               S   s   d S)Nr&   r   r   r   r   r   r      s    z=BasicCacheAPITest.test_delentry_non_raising.<locals>.<lambda>zself.cache._getentry(100))r   r   delentryr!   r"   r#   r$   )r   r   r   r   r   test_delentry_non_raising   s    z+BasicCacheAPITest.test_delentry_non_raisingc             C   sB   |  j  j d d d    } |  j  j d  t j j t d  d  S)Nr&   c               S   s   d S)Nr&   r   r   r   r   r   r      s    z9BasicCacheAPITest.test_delentry_raising.<locals>.<lambda>z&self.cache.delentry(100, raising=True))r   r   r'   r!   r"   r#   r$   )r   r   r   r   r   test_delentry_raising   s    z'BasicCacheAPITest.test_delentry_raisingc             C   s   |  j  j   d  S)N)r   clear)r   r   r   r   
test_clear   s    zBasicCacheAPITest.test_clear)	__name__
__module____qualname__r   r    r%   r(   r)   r+   r   r   r   r   r      s   r   c               @   s.   e  Z d  Z e j d d  Z d d   Z d S)TestBuildcostAccess
maxentries   c                s 	  t  j   } d g     f d d   } | j t  d |  xt | j  D]  | j   f d d    }  | k } | s6t j d# | f d$  | f  d	 d
 t j	   k s t j
   r t j   n d
 d d t j	   k s t j
 |  rt j |  n d i } d% d | i } t t j |    d  } qJ Wxrt | j  D]a | j } d  } |  |  }	 |	  k }
 |
 st j d& |
 f d' |	  f  d d
 t j	   k st j
   rt j   n d
 d	 d t j	   k st j
 |  rt j |  n d d d
 t j	   k s4t j
   rCt j   n d
 d t j |	  d t j |  d t j |  i } d( d | i } t t j |    d  } } }	 }
 qPWt | j d  } xt |  D] | j } d  } |  |  }	 |	  k }
 |
 s$t j d) |
 f d* |	  f  d d
 t j	   k sMt j
   r\t j   n d
 d	 d t j	   k st j
 |  rt j |  n d d d
 t j	   k st j
   rt j   n d
 d t j |	  d t j |  d t j |  i } d+ d | i } t t j |    d  } } }	 }
 | j } d  } |  |  }	 |	  k }
 |
 st j d, |
 f d- |	  f  d d
 t j	   k st j
   rt j   n d
 d	 d t j	   k st j
 |  rt j |  n d d d
 t j	   k st j
   r#t j   n d
 d t j |	  d t j |  d t j |  i } d. d | i } t t j |    d  } } }	 }
 qW| j d/ d d    } d } | | k } | sTt j d0 | f d1 | | f  d	 d t j	   k st j
 |  rt j |  n d d t j |  i } d2 d | i } t t j |    d  } } xot |  D]a | j } d  } |  |  }	 |	  k }
 |
 st j d3 |
 f d4 |	  f  d d
 t j	   k st j
   rt j   n d
 d	 d t j	   k st j
 |  r(t j |  n d d d
 t j	   k sOt j
   r^t j   n d
 d t j |	  d t j |  d t j |  i } d5 d | i } t t j |    d  } } }	 }
 qkW| j } d } | } d  }	 | | |	  }
 d } |
 | k } | st j d6 | f d7 |
 | f  d t j |
  d  t j |  d	 d t j	   k sst j
 |  rt j |  n d d t j |  d t j |  d t j |	  i } d8 d" | i } t t j |    d  } } } }	 }
 } } d  S)9Nr   c                  s     d d   d <  d S)Nr      r   r   )lr   r   counter'   s    zETestBuildcostAccess.test_cache_works_somewhat_simple.<locals>.counterZgettimec                  s     S)Nr   r   )xr   r   r   ,   s    zFTestBuildcostAccess.test_cache_works_somewhat_simple.<locals>.<lambda>r   %(py0)s == %(py2)sr
   r5   py2yr   assert %(py4)spy4Y%(py7)s
{%(py7)s = %(py2)s
{%(py2)s = %(py0)s.getorbuild
}(%(py3)s, %(py5)s)
} == %(py9)spy9r   r   py7r   assert %(py11)spy11   r2   c               S   s   d S)Nr   r   r   r   r   r   r   5   s    r   %(py0)s == %(py3)sr   assert %(py5)s[%(py9)s
{%(py9)s = %(py2)s
{%(py2)s = %(py0)s.getorbuild
}(-%(py4)s, %(py7)s)
} == %(py12)spy12assert %(py14)spy14)r   )r6   r9   )r   )r;   r>   )r   )r;   r>   )r   )r;   r>   )r   )rA   rB   )r   )r;   r>   )r   )rC   rE   )r   BuildcostAccessCachesetattrranger0   r   r   r   r   r   r   r   r   r   int)r   monkeypatchr   r4   r8   r   @py_format3@py_format5@py_assert4@py_assert6@py_assert8@py_format10@py_format12Zhalfentriesr   r   r   r   @py_assert3@py_assert5@py_assert11@py_assert10@py_format13@py_format15r   )r3   r5   r    test_cache_works_somewhat_simple   s    	     
	        	        	           j   
	        	           z4TestBuildcostAccess.test_cache_works_somewhat_simpleN)r,   r-   r.   r   rH   r   rZ   r   r   r   r   r/      s   r/   c               @   s:   e  Z d  Z d Z e j d d d e  Z d d   Z d S)	TestAgingg?r0   r1   
maxsecondsc             C   s   |  j  j d d d    t j j j   |  j d } xp t j j j   | k  r y |  j  j d  Wn t k
 rz PYn Xt j j j |  j d  q9 Wt j	 j
 d  d  S)N   c               S   s   d S)Nr]   r   r   r   r   r   r   C   s    z/TestAging.test_cache_eviction.<locals>.<lambda>
   g333333?z!waiting for cache eviction failed)r   r   r!   stdtimemaxsecsZ	_getentryr$   sleepr"   fail)r   endtimer   r   r   test_cache_evictionB   s    zTestAging.test_cache_evictionN)r,   r-   r.   ra   r   
AgingCacher   re   r   r   r   r   r[   >   s   r[   c                 s   d }  t  j d d d |   } x3 t | j  D]"   | j     f d d    q. Wt j j j |  d  | j | j d d	 d    d  S)
Ng?r0   r^   r\   c                  s     S)Nr   r   )r5   r   r   r   R   s    z)test_prune_lowestweight.<locals>.<lambda>g?r2   c               S   s   d S)Nr   r   r   r   r   r   r   T   s    )	r   rf   rJ   r0   r   r!   r_   r`   rb   )ra   r   r   )r5   r   test_prune_lowestweightN   s     rg   )builtinsr   _pytest.assertion.rewrite	assertionrewriter   r!   Zpy._pathr   r   r/   r[   rg   r   r   r   r   <module>   s     "