예제 #1
0
 def test_that_cache_respects_max_size(self):
     timeout = 0.1
     cache = Cache(timeout, max_size=2)
     cache.set("hello", "world")
     self.assertEquals(len(cache), 1)
     cache.set("how", "are")
     self.assertEquals(len(cache), 2)
     cache.set("you", "today?")
     self.assertEquals(len(cache), 2)
     self.assertEquals(cache.get("you"), "today?")
     self.assertEquals(cache.get("how"), "are")
     self.assertRaises(KeyError, cache.get, "hello")
예제 #2
0
 def test_that_cache_items_are_ungettable_once_expired(self):
     timeout = 0.1
     cache = Cache(timeout)
     cache.set("hello", "world")
     self.assertEquals(cache.get("hello"), "world")
     time.sleep(timeout / 2)
     self.assertEquals(cache.get("hello"), "world")
     time.sleep(timeout / 2)
     self.assertRaises(KeyError, cache.get, "hello")
예제 #3
0
 def test_that_you_cant_set_duplicate_cache_keys(self):
     timeout = 0.1
     cache = Cache(timeout)
     cache.set("hello", "world")
     try:
         cache.set("hello", "spamityspam")
     except KeyExistsError, e:
         self.assertEquals(e.key, "hello")
         self.assertEquals(e.value, "world")
예제 #4
0
 def test_that_you_cant_set_duplicate_cache_keys(self):
     timeout = 0.1
     cache = Cache(timeout)
     cache.set("hello", "world")
     try:
         cache.set("hello", "spamityspam")
     except KeyExistsError as e:
         self.assertEquals(e.key, "hello")
         self.assertEquals(e.value, "world")
     else:
         assert False, "KeyExistsError was not raised"  # pragma: nocover