summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_functools.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-12-01 03:45:41 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-12-01 03:45:41 (GMT)
commitc79fb0e52d297e0599a37be2652e75e3abc35690 (patch)
tree512f5b891c76f0035c2eb7d672ba19385e6eb2c6 /Lib/test/test_functools.py
parented3a7d2d601ce1e65b0bacf24676440631158ec8 (diff)
downloadcpython-c79fb0e52d297e0599a37be2652e75e3abc35690.zip
cpython-c79fb0e52d297e0599a37be2652e75e3abc35690.tar.gz
cpython-c79fb0e52d297e0599a37be2652e75e3abc35690.tar.bz2
Issue 10593: Adopt Nick's suggestion for an lru_cache with maxsize=None.
Diffstat (limited to 'Lib/test/test_functools.py')
-rw-r--r--Lib/test/test_functools.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index 8f48e9e..e5921a7 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -586,6 +586,20 @@ class TestLRU(unittest.TestCase):
self.assertEqual(misses, 4)
self.assertEqual(currsize, 2)
+ def test_lru_with_maxsize_none(self):
+ @functools.lru_cache(maxsize=None)
+ def fib(n):
+ if n < 2:
+ return n
+ return fib(n-1) + fib(n-2)
+ self.assertEqual([fib(n) for n in range(16)],
+ [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610])
+ self.assertEqual(fib.cache_info(),
+ functools._CacheInfo(hits=28, misses=16, maxsize=None, currsize=16))
+ fib.cache_clear()
+ self.assertEqual(fib.cache_info(),
+ functools._CacheInfo(hits=0, misses=0, maxsize=None, currsize=0))
+
def test_main(verbose=None):
test_classes = (
TestPartial,