Commit 39acb8c1 authored by Nicolas Delaby's avatar Nicolas Delaby

code cleaning

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29119 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 83551a7f
...@@ -64,36 +64,36 @@ class TestRamCache(unittest.TestCase): ...@@ -64,36 +64,36 @@ class TestRamCache(unittest.TestCase):
for i in range(0, iterations): for i in range(0, iterations):
test_scopes.append("my_scope_%s" %i) test_scopes.append("my_scope_%s" %i)
test_scopes.sort() test_scopes.sort()
## remove DistributedRamCache since it's a flat storage ## remove DistributedRamCache since it's a flat storage
filtered_cache_plugins = filter( filtered_cache_plugins = filter(
lambda x: not isinstance(x, DistributedRamCache), self.cache_plugins) lambda x: not isinstance(x, DistributedRamCache), self.cache_plugins)
for cache_plugin in filtered_cache_plugins: for cache_plugin in filtered_cache_plugins:
if not self.quiet: if not self.quiet:
print "TESTING (scope): ", cache_plugin print "TESTING (scope): ", cache_plugin
## clear cache for this plugin ## clear cache for this plugin
cache_plugin.clearCache() cache_plugin.clearCache()
## should exists no scopes in cache ## should exists no scopes in cache
self.assertEqual([], cache_plugin.getScopeList()) self.assertEqual([], cache_plugin.getScopeList())
## set some sample values ## set some sample values
for scope in test_scopes: for scope in test_scopes:
cache_id = '%s_cache_id' %scope cache_id = '%s_cache_id' %scope
cache_plugin.set(cache_id, scope, scope*10) cache_plugin.set(cache_id, scope, scope*10)
## we set ONLY one value per scope -> check if we get the same cache_id ## we set ONLY one value per scope -> check if we get the same cache_id
self.assertEqual([cache_id], cache_plugin.getScopeKeyList(scope)) self.assertEqual([cache_id], cache_plugin.getScopeKeyList(scope))
if not self.quiet: if not self.quiet:
print "\t", cache_id, scope, "\t\tOK" print "\t", cache_id, scope, "\t\tOK"
## get list of scopes which must be the same as test_scopes since we clear cache initially ## get list of scopes which must be the same as test_scopes since we clear cache initially
scopes_from_cache = cache_plugin.getScopeList() scopes_from_cache = cache_plugin.getScopeList()
scopes_from_cache.sort() scopes_from_cache.sort()
self.assertEqual(test_scopes, scopes_from_cache) self.assertEqual(test_scopes, scopes_from_cache)
## remove scope one by one ## remove scope one by one
count = 1 count = 1
for scope in test_scopes: for scope in test_scopes:
...@@ -102,24 +102,22 @@ class TestRamCache(unittest.TestCase): ...@@ -102,24 +102,22 @@ class TestRamCache(unittest.TestCase):
scopes_from_cache = cache_plugin.getScopeList() scopes_from_cache = cache_plugin.getScopeList()
self.assertEqual(iterations - count, len(scopes_from_cache)) self.assertEqual(iterations - count, len(scopes_from_cache))
count = count + 1 count = count + 1
## .. we shouldn't have any cache scopes ## .. we shouldn't have any cache scopes
scopes_from_cache = cache_plugin.getScopeList() scopes_from_cache = cache_plugin.getScopeList()
self.assertEqual([], scopes_from_cache) self.assertEqual([], scopes_from_cache)
def testSetGet(self): def testSetGet(self):
""" set value to cache and then get it back """ """ set value to cache and then get it back """
for cache_plugin in self.cache_plugins: for cache_plugin in self.cache_plugins:
self.generaltestSetGet(cache_plugin, 100) self.generaltestSetGet(cache_plugin, 100)
def testExpire(self): def testExpire(self):
""" Check expired by setting a key, wit for its timeout and check if in """ Check expired by setting a key, wit for its timeout and check if in
cache""" cache"""
for cache_plugin in self.cache_plugins: for cache_plugin in self.cache_plugins:
self.generalExpire(cache_plugin, 2) self.generalExpire(cache_plugin, 2)
def generalExpire(self, cache_plugin, iterations): def generalExpire(self, cache_plugin, iterations):
if not self.quiet: if not self.quiet:
print "TESTING (expire): ", cache_plugin print "TESTING (expire): ", cache_plugin
...@@ -136,18 +134,18 @@ class TestRamCache(unittest.TestCase): ...@@ -136,18 +134,18 @@ class TestRamCache(unittest.TestCase):
## set to cache ## set to cache
cache_plugin.set(cache_id, scope, value, cache_timeout) cache_plugin.set(cache_id, scope, value, cache_timeout)
## sleep for timeout +1 ## sleep for timeout +1
time.sleep(cache_timeout + 1) time.sleep(cache_timeout + 1)
## should remove from cache expired cache entries ## should remove from cache expired cache entries
cache_plugin.expireOldCacheEntries(forceCheck=True) cache_plugin.expireOldCacheEntries(forceCheck=True)
## check it, we MUST NOT have this key any more in cache ## check it, we MUST NOT have this key any more in cache
self.assertEqual(False, cache_plugin.has_key(cache_id, scope)) self.assertEqual(False, cache_plugin.has_key(cache_id, scope))
if not self.quiet: if not self.quiet:
print "\t\tOK" print "\t\tOK"
def generaltestSetGet(self, cache_plugin, iterations): def generaltestSetGet(self, cache_plugin, iterations):
if not self.quiet: if not self.quiet:
print "TESTING (set/get/has/del): ", cache_plugin print "TESTING (set/get/has/del): ", cache_plugin
...@@ -158,15 +156,15 @@ class TestRamCache(unittest.TestCase): ...@@ -158,15 +156,15 @@ class TestRamCache(unittest.TestCase):
for value in values: for value in values:
count = count +1 count = count +1
cache_id = "mycache_id_to_set_get_has_del_%s" %(count) cache_id = "mycache_id_to_set_get_has_del_%s" %(count)
## set to cache ## set to cache
cache_plugin.set(cache_id, scope, value, cache_duration) cache_plugin.set(cache_id, scope, value, cache_duration)
if not self.quiet: if not self.quiet:
print "\t", cache_id, print "\t", cache_id,
## check has_key() ## check has_key()
self.assertEqual(True, cache_plugin.has_key(cache_id, scope)) self.assertEqual(True, cache_plugin.has_key(cache_id, scope))
## check get() ## check get()
cache_entry = cache_plugin.get(cache_id, scope) cache_entry = cache_plugin.get(cache_id, scope)
if isinstance(value, Foo): if isinstance(value, Foo):
...@@ -176,20 +174,20 @@ class TestRamCache(unittest.TestCase): ...@@ -176,20 +174,20 @@ class TestRamCache(unittest.TestCase):
else: else:
## primitive types, direct comparision ## primitive types, direct comparision
self.assertEqual(value, cache_entry.getValue()) self.assertEqual(value, cache_entry.getValue())
## is returned result proper cache entry? ## is returned result proper cache entry?
self.assertEqual(True, isinstance(cache_entry, CacheEntry)) self.assertEqual(True, isinstance(cache_entry, CacheEntry))
## is returned result proper type? ## is returned result proper type?
self.assertEqual(type(value), type(cache_entry.getValue())) self.assertEqual(type(value), type(cache_entry.getValue()))
## check delete(), key should be removed from there ## check delete(), key should be removed from there
cache_plugin.delete(cache_id, scope) cache_plugin.delete(cache_id, scope)
self.assertEqual(False, cache_plugin.has_key(cache_id, scope)) self.assertEqual(False, cache_plugin.has_key(cache_id, scope))
if not self.quiet: if not self.quiet:
print "\t\tOK" print "\t\tOK"
def prepareValues(self, iterations): def prepareValues(self, iterations):
""" generate a big list of values """ """ generate a big list of values """
values = [] values = []
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment