diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2021-11-05 19:52:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-05 19:52:46 (GMT) |
commit | 60b5333fa936a7e7f078a82e0fa3752cc9b6c5fb (patch) | |
tree | eb7924c3f370ed55f5d24a3dbc84d3354ca3524f /Lib | |
parent | 3d42cd9461e60c7427f3793f640cd975fbd99289 (diff) | |
download | cpython-60b5333fa936a7e7f078a82e0fa3752cc9b6c5fb.zip cpython-60b5333fa936a7e7f078a82e0fa3752cc9b6c5fb.tar.gz cpython-60b5333fa936a7e7f078a82e0fa3752cc9b6c5fb.tar.bz2 |
bpo-45679: add `tuple` tests with `lru_cache` to `test_functools` (GH-29339)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_functools.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 7bc355f..08cf457 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -1495,6 +1495,33 @@ class TestLRU: self.assertEqual(square.cache_info().hits, 4) self.assertEqual(square.cache_info().misses, 4) + def test_lru_cache_typed_is_not_recursive(self): + cached = self.module.lru_cache(typed=True)(repr) + + self.assertEqual(cached(1), '1') + self.assertEqual(cached(True), 'True') + self.assertEqual(cached(1.0), '1.0') + self.assertEqual(cached(0), '0') + self.assertEqual(cached(False), 'False') + self.assertEqual(cached(0.0), '0.0') + + self.assertEqual(cached((1,)), '(1,)') + self.assertEqual(cached((True,)), '(1,)') + self.assertEqual(cached((1.0,)), '(1,)') + self.assertEqual(cached((0,)), '(0,)') + self.assertEqual(cached((False,)), '(0,)') + self.assertEqual(cached((0.0,)), '(0,)') + + class T(tuple): + pass + + self.assertEqual(cached(T((1,))), '(1,)') + self.assertEqual(cached(T((True,))), '(1,)') + self.assertEqual(cached(T((1.0,))), '(1,)') + self.assertEqual(cached(T((0,))), '(0,)') + self.assertEqual(cached(T((False,))), '(0,)') + self.assertEqual(cached(T((0.0,))), '(0,)') + def test_lru_with_keyword_args(self): @self.module.lru_cache() def fib(n): |