Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
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
cpython
Commits
0e540c39
Kaydet (Commit)
0e540c39
authored
May 02, 2001
tarafından
Fred Drake
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added tests for Weak*Dictionary iterator support.
Refactored some object initialization to be more reusable.
üst
101209d4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
10 deletions
+54
-10
test_weakref.py
Lib/test/test_weakref.py
+54
-10
No files found.
Lib/test/test_weakref.py
Dosyayı görüntüle @
0e540c39
...
...
@@ -229,11 +229,10 @@ class MappingTestCase(TestBase):
COUNT
=
10
def
test_weak_values
(
self
):
dict
=
weakref
.
WeakValueDictionary
()
objects
=
map
(
Object
,
range
(
self
.
COUNT
))
for
o
in
objects
:
dict
[
o
.
arg
]
=
o
#
# This exercises d.copy(), d.items(), d[], del d[], len(d).
#
dict
,
objects
=
self
.
make_weak_valued_dict
()
for
o
in
objects
:
self
.
assert_
(
weakref
.
getweakrefcount
(
o
)
==
1
,
"wrong number of weak references to
%
r!"
%
o
)
...
...
@@ -255,11 +254,11 @@ class MappingTestCase(TestBase):
"deleting the values did not clear the dictionary"
)
def
test_weak_keys
(
self
):
dict
=
weakref
.
WeakKeyDictionary
()
objects
=
map
(
Object
,
range
(
self
.
COUNT
))
for
o
in
objects
:
dict
[
o
]
=
o
.
arg
#
# This exercises d.copy(), d.items(), d[] = v, d[], del d[],
# len(d).
#
dict
,
objects
=
self
.
make_weak_keyed_dict
()
for
o
in
objects
:
self
.
assert_
(
weakref
.
getweakrefcount
(
o
)
==
1
,
"wrong number of weak references to
%
r!"
%
o
)
...
...
@@ -280,7 +279,52 @@ class MappingTestCase(TestBase):
self
.
assert_
(
len
(
dict
)
==
0
,
"deleting the keys did not clear the dictionary"
)
def
test_weak_keyed_iters
(
self
):
dict
,
objects
=
self
.
make_weak_keyed_dict
()
self
.
check_iters
(
dict
)
def
test_weak_valued_iters
(
self
):
dict
,
objects
=
self
.
make_weak_valued_dict
()
self
.
check_iters
(
dict
)
def
check_iters
(
self
,
dict
):
# item iterator:
items
=
dict
.
items
()
for
item
in
dict
.
iteritems
():
items
.
remove
(
item
)
self
.
assert_
(
len
(
items
)
==
0
,
"iterator did not touch all items"
)
# key iterator:
keys
=
dict
.
keys
()
for
k
in
dict
:
keys
.
remove
(
k
)
self
.
assert_
(
len
(
keys
)
==
0
,
"iterator did not touch all keys"
)
# value iterator:
values
=
dict
.
values
()
for
v
in
dict
.
itervalues
():
values
.
remove
(
v
)
self
.
assert_
(
len
(
values
)
==
0
,
"iterator did not touch all values"
)
def
make_weak_keyed_dict
(
self
):
dict
=
weakref
.
WeakKeyDictionary
()
objects
=
map
(
Object
,
range
(
self
.
COUNT
))
for
o
in
objects
:
dict
[
o
]
=
o
.
arg
return
dict
,
objects
def
make_weak_valued_dict
(
self
):
dict
=
weakref
.
WeakValueDictionary
()
objects
=
map
(
Object
,
range
(
self
.
COUNT
))
for
o
in
objects
:
dict
[
o
.
arg
]
=
o
return
dict
,
objects
def
check_update
(
self
,
klass
,
dict
):
#
# This exercises d.update(), len(d), d.keys(), d.has_key(),
# d.get(), d[].
#
weakdict
=
klass
()
weakdict
.
update
(
dict
)
self
.
assert_
(
len
(
weakdict
)
==
len
(
dict
))
...
...
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