diff options
| author | Honza Kral <honza.kral@gmail.com> | 2013-02-23 23:32:09 +0100 |
|---|---|---|
| committer | Honza Kral <honza.kral@gmail.com> | 2013-02-23 23:32:09 +0100 |
| commit | ef1e6ef1eb5495b168f9fc642eca235e71e51dde (patch) | |
| tree | 482a380aeed837426bfa54d3c7fbf315d12f108f /tests | |
| parent | 2b48fcc607010065c0f8107baf669dd41b164f3c (diff) | |
| parent | b88abd684041ffa66bfe445e1ac26164e803d488 (diff) | |
Merge branch 'ticket19872' of https://github.com/oinopion/django
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/utils/functional.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/regressiontests/utils/functional.py b/tests/regressiontests/utils/functional.py index 90a6f08630..3bb50007c6 100644 --- a/tests/regressiontests/utils/functional.py +++ b/tests/regressiontests/utils/functional.py @@ -1,5 +1,5 @@ from django.utils import unittest -from django.utils.functional import lazy, lazy_property +from django.utils.functional import lazy, lazy_property, cached_property class FunctionalTestCase(unittest.TestCase): @@ -37,3 +37,30 @@ class FunctionalTestCase(unittest.TestCase): self.assertRaises(NotImplementedError, lambda: A().do) self.assertEqual(B().do, 'DO IT') + + def test_cached_property(self): + """ + Test that cached_property caches its value, + and that it behaves like a property + """ + + class A(object): + + @cached_property + def value(self): + return 1, object() + + a = A() + + # check that it is cached + self.assertEqual(a.value, a.value) + + # check that it returns the right thing + self.assertEqual(a.value[0], 1) + + # check that state isn't shared between instances + a2 = A() + self.assertNotEqual(a.value, a2.value) + + # check that it behaves like a property when there's no instance + self.assertIsInstance(A.value, cached_property) |
