diff options
author | mgaligniana <marcelogaligniana@gmail.com> | 2021-12-15 01:15:41 -0300 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-12-16 18:52:27 +0100 |
commit | 068b2c072b0d28cbd5ea63811779629cdaad8638 (patch) | |
tree | 9e0a5b82e996babb7094e31081c17ac699929777 /tests/utils_tests | |
parent | bf7afe9c4e21f5fe5090c47b2b6ffc5a03a85815 (diff) | |
download | django-068b2c072b0d28cbd5ea63811779629cdaad8638.tar.gz |
Fixed #30127 -- Deprecated name argument of cached_property().
Diffstat (limited to 'tests/utils_tests')
-rw-r--r-- | tests/utils_tests/test_functional.py | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/tests/utils_tests/test_functional.py b/tests/utils_tests/test_functional.py index b870f98ea2..f720ffac3d 100644 --- a/tests/utils_tests/test_functional.py +++ b/tests/utils_tests/test_functional.py @@ -1,6 +1,8 @@ from unittest import mock from django.test import SimpleTestCase +from django.test.utils import ignore_warnings +from django.utils.deprecation import RemovedInDjango50Warning from django.utils.functional import cached_property, classproperty, lazy @@ -97,12 +99,36 @@ class FunctionalTests(SimpleTestCase): """Here is the docstring...""" return 1, object() - other = cached_property(other_value, name='other') + other = cached_property(other_value) attrs = ['value', 'other', '__foo__'] for attr in attrs: self.assertCachedPropertyWorks(attr, Class) + @ignore_warnings(category=RemovedInDjango50Warning) + def test_cached_property_name(self): + class Class: + def other_value(self): + """Here is the docstring...""" + return 1, object() + + other = cached_property(other_value, name='other') + other2 = cached_property(other_value, name='different_name') + + self.assertCachedPropertyWorks('other', Class) + # An explicit name is ignored. + obj = Class() + obj.other2 + self.assertFalse(hasattr(obj, 'different_name')) + + def test_cached_property_name_deprecation_warning(self): + def value(self): + return 1 + + msg = "The name argument is deprecated as it's unnecessary as of Python 3.6." + with self.assertWarnsMessage(RemovedInDjango50Warning, msg): + cached_property(value, name='other_name') + def test_cached_property_auto_name(self): """ cached_property caches its value and behaves like a property @@ -119,17 +145,11 @@ class FunctionalTests(SimpleTestCase): return 1, object() other = cached_property(other_value) - other2 = cached_property(other_value, name='different_name') attrs = ['_Class__value', 'other'] for attr in attrs: self.assertCachedPropertyWorks(attr, Class) - # An explicit name is ignored. - obj = Class() - obj.other2 - self.assertFalse(hasattr(obj, 'different_name')) - def test_cached_property_reuse_different_names(self): """Disallow this case because the decorated function wouldn't be cached.""" with self.assertRaises(RuntimeError) as ctx: |