Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
ef1e6ef1
Kaydet (Commit)
ef1e6ef1
authored
Şub 23, 2013
tarafından
Honza Kral
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge branch 'ticket19872' of
https://github.com/oinopion/django
üst
2b48fcc6
b88abd68
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
+31
-2
functional.py
django/utils/functional.py
+3
-1
functional.py
tests/regressiontests/utils/functional.py
+28
-1
No files found.
django/utils/functional.py
Dosyayı görüntüle @
ef1e6ef1
...
...
@@ -39,7 +39,9 @@ class cached_property(object):
def
__init__
(
self
,
func
):
self
.
func
=
func
def
__get__
(
self
,
instance
,
type
):
def
__get__
(
self
,
instance
,
type
=
None
):
if
instance
is
None
:
return
self
res
=
instance
.
__dict__
[
self
.
func
.
__name__
]
=
self
.
func
(
instance
)
return
res
...
...
tests/regressiontests/utils/functional.py
Dosyayı görüntüle @
ef1e6ef1
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment