Skip to content
Snippets Groups Projects
Commit f206ca26 authored by Holger's avatar Holger
Browse files

Fix unit test for Object Cache

parent b1c32054
No related branches found
No related tags found
No related merge requests found
......@@ -53,21 +53,25 @@ class Testcases(unittest.TestCase):
# Get
self.assertEqual(cache.get("foo", "New"), "New")
def test_use_del(self):
cache = ObjectCache(default_expiration=1, auto_clean=True, use_del=False)
self.assertEqual(str(cache), "ObjectCache(n=0, default_expiration=1)")
def test_cache2(self):
cache = ObjectCache(default_expiration=3, auto_clean=True)
self.assertEqual(str(cache), "ObjectCache(n=0, default_expiration=3)")
# Data
cache["foo"] = "bar"
self.assertEqual(str(cache), "ObjectCache(n=1, default_expiration=1)")
self.assertEqual(str(cache), "ObjectCache(n=1, default_expiration=3)")
self.assertIn("foo", cache)
self.assertEqual(cache["foo"], "bar")
self.assertEqual(cache.get("foo", "New"), "bar")
time.sleep(1)
cache["foo2"] = "bar2"
time.sleep(1)
cache["foo3"] = "bar3"
self.assertEqual(str(cache), "ObjectCache(n=3, default_expiration=3)")
# Expiration
time.sleep(2)
self.assertNotIn("foo", cache)
self.assertEqual(str(cache), "ObjectCache(n=0, default_expiration=1)")
self.assertEqual(str(cache), "ObjectCache(n=1, default_expiration=3)")
self.assertEqual(len(list(cache)), 1)
# Get
self.assertEqual(cache.get("foo", "New"), "New")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment