From 4b1c2eec3b40adfa7b27647a32958b2603666102 Mon Sep 17 00:00:00 2001 From: hpk Date: Thu, 2 Oct 2008 18:19:04 +0200 Subject: [PATCH] [svn r58576] * fix test to not rely on time.time() resolution * strike some superflous __init__ code --HG-- branch : trunk --- py/misc/cache.py | 3 --- py/misc/testing/test_cache.py | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/py/misc/cache.py b/py/misc/cache.py index 51e345d52..12970e6d7 100644 --- a/py/misc/cache.py +++ b/py/misc/cache.py @@ -107,9 +107,6 @@ class BuildcostAccessCache(BasicCache): # time function to use for measuring build-times _time = gettime - def __init__(self, maxentries=64): - super(BuildcostAccessCache, self).__init__(maxentries) - def build(self, key, builder, *args, **kwargs): start = self._time() val = builder(*args, **kwargs) diff --git a/py/misc/testing/test_cache.py b/py/misc/testing/test_cache.py index c4c8f5df2..be4e3406b 100644 --- a/py/misc/testing/test_cache.py +++ b/py/misc/testing/test_cache.py @@ -27,6 +27,12 @@ class TestBuildcostAccess(BasicCacheAPITest): def test_cache_works_somewhat_simple(self): cache = BuildcostAccessCache() + # the default ._time() call used by + # BuildcostAccessCache.build can + # result into time()-time() == 0 which makes the below + # test fail randomly. Let's rather use incrementing + # numbers instead. + cache._time = py.std.itertools.count().next for x in range(cache.maxentries): y = cache.getorbuild(x, lambda: x) assert x == y