diff options
author | Bouke Haarsma <bouke@webatoom.nl> | 2013-11-01 21:15:41 +0100 |
---|---|---|
committer | Baptiste Mispelon <bmispelon@gmail.com> | 2013-11-11 08:53:09 +0100 |
commit | 9b7455e918a437c3db91e88dcbf6d9c93fef96f8 (patch) | |
tree | 4cda7466ec20e5255633e7447eaa03ad5450bf24 /tests/deprecation | |
parent | 6c5f5b9a414b8bdfafc45db5710acf200cca9885 (diff) | |
download | django-9b7455e918a437c3db91e88dcbf6d9c93fef96f8.tar.gz |
Fixed #21351 -- Replaced memoize with Python's lru_cache.
Replaced the custom, untested memoize with a similar decorator from Python's
3.2 stdlib. Although some minor performance degradation (see ticket), it is
expected that in the long run lru_cache will outperform memoize once it is
implemented in C.
Thanks to EvilDMP for the report and Baptiste Mispelon for the idea of
replacing memoize with lru_cache.
Diffstat (limited to 'tests/deprecation')
-rw-r--r-- | tests/deprecation/tests.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/deprecation/tests.py b/tests/deprecation/tests.py index 7d9ed16636..2a0922a0a8 100644 --- a/tests/deprecation/tests.py +++ b/tests/deprecation/tests.py @@ -4,6 +4,7 @@ import warnings from django.test import SimpleTestCase, RequestFactory, override_settings from django.utils import six, translation from django.utils.deprecation import RenameMethodsBase +from django.utils.functional import memoize class RenameManagerMethods(RenameMethodsBase): @@ -205,3 +206,18 @@ class DeprecatedChineseLanguageCodes(SimpleTestCase): "The use of the language code 'zh-tw' is deprecated. " "Please use the 'zh-hant' translation instead.", ]) + + +class DeprecatingMemoizeTest(SimpleTestCase): + def test_deprecated_memoize(self): + """ + Ensure the correct warning is raised when memoize is used. + """ + warnings.simplefilter('always') + + with warnings.catch_warnings(record=True) as recorded: + memoize(lambda x: x, {}, 1) + msg = str(recorded.pop().message) + self.assertEqual(msg, + 'memoize wrapper is deprecated and will be removed in Django ' + '1.9. Use django.utils.lru_cache instead.') |