Skip to content

Commit

Permalink
Add test case for decorator lock count.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Kemmer committed Feb 20, 2025
1 parent 2041c6f commit dd69193
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/test_cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,34 @@ def test_decorator_info(self):
self.assertEqual(len(cache), 0)
self.assertEqual(wrapper.cache_info(), (0, 0, 2, 0))

def test_decorator_lock_info(self):
# hit: lock.count += 1
# miss: lock.count += 3 (get, update missed, set)
# info: lock.count += 1
# clear: lock.count += 1
cache = self.cache(2)
lock = CountedLock()
wrapper = cachetools.cached(cache, lock=lock, info=True)(self.func)
self.assertEqual(wrapper.cache_info(), (0, 0, 2, 0))
self.assertEqual(lock.count, 1)
self.assertEqual(wrapper(0), 0)
self.assertEqual(lock.count, 4)
self.assertEqual(wrapper.cache_info(), (0, 1, 2, 1))
self.assertEqual(lock.count, 5)
self.assertEqual(wrapper(1), 1)
self.assertEqual(lock.count, 8)
self.assertEqual(wrapper.cache_info(), (0, 2, 2, 2))
self.assertEqual(lock.count, 9)
self.assertEqual(wrapper(0), 0)
self.assertEqual(lock.count, 10)
self.assertEqual(wrapper.cache_info(), (1, 2, 2, 2))
self.assertEqual(lock.count, 11)
wrapper.cache_clear()
self.assertEqual(lock.count, 12)
self.assertEqual(len(cache), 0)
self.assertEqual(wrapper.cache_info(), (0, 0, 2, 0))
self.assertEqual(lock.count, 13)

def test_zero_size_cache_decorator(self):
cache = self.cache(0)
wrapper = cachetools.cached(cache)(self.func)
Expand Down

0 comments on commit dd69193

Please sign in to comment.