summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_functools.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-08-14 23:52:08 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-08-14 23:52:08 (GMT)
commit0f56e90f0582a4171a9e3e1e2ffde2781be4bffd (patch)
tree32bc9fd46a929f5ac2115b8591d54efad1ec9efa /Lib/test/test_functools.py
parenta893927491ef3bc7a4c3c9aa548be7d8ff677c38 (diff)
downloadcpython-0f56e90f0582a4171a9e3e1e2ffde2781be4bffd.zip
cpython-0f56e90f0582a4171a9e3e1e2ffde2781be4bffd.tar.gz
cpython-0f56e90f0582a4171a9e3e1e2ffde2781be4bffd.tar.bz2
Support cache sizes.
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r--Lib/test/test_functools.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index 70a8ad6..4dd6fab 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -482,6 +482,30 @@ class TestLRU(unittest.TestCase):
self.assertEqual(f.hits, 0)
self.assertEqual(f.misses, 1)
+ # test size zero (which means "never-cache")
+ f_cnt = 0
+ @functools.lru_cache(0)
+ def f():
+ nonlocal f_cnt
+ f_cnt += 1
+ return 20
+ self.assertEqual(f(), 20)
+ self.assertEqual(f(), 20)
+ self.assertEqual(f(), 20)
+ self.assertEqual(f_cnt, 3)
+
+ # test size one
+ f_cnt = 0
+ @functools.lru_cache(1)
+ def f():
+ nonlocal f_cnt
+ f_cnt += 1
+ return 20
+ self.assertEqual(f(), 20)
+ self.assertEqual(f(), 20)
+ self.assertEqual(f(), 20)
+ self.assertEqual(f_cnt, 1)
+
def test_lfu(self):
def orig(x, y):
return 3*x+y
@@ -503,6 +527,30 @@ class TestLRU(unittest.TestCase):
self.assertEqual(f.hits, 0)
self.assertEqual(f.misses, 1)
+ # test size zero (which means "never-cache")
+ f_cnt = 0
+ @functools.lfu_cache(0)
+ def f():
+ nonlocal f_cnt
+ f_cnt += 1
+ return 20
+ self.assertEqual(f(), 20)
+ self.assertEqual(f(), 20)
+ self.assertEqual(f(), 20)
+ self.assertEqual(f_cnt, 3)
+
+ # test size one
+ f_cnt = 0
+ @functools.lfu_cache(1)
+ def f():
+ nonlocal f_cnt
+ f_cnt += 1
+ return 20
+ self.assertEqual(f(), 20)
+ self.assertEqual(f(), 20)
+ self.assertEqual(f(), 20)
+ self.assertEqual(f_cnt, 1)
+
def test_main(verbose=None):
test_classes = (
TestPartial,