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
d11f76f8
Kaydet (Commit)
d11f76f8
authored
Nis 04, 2011
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #11761: make tests for gc.get_count() less fragile
üst
c800af41
e9b2a4cb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
16 deletions
+27
-16
test_gc.py
Lib/test/test_gc.py
+27
-16
No files found.
Lib/test/test_gc.py
Dosyayı görüntüle @
d11f76f8
...
@@ -241,32 +241,43 @@ class GCTests(unittest.TestCase):
...
@@ -241,32 +241,43 @@ class GCTests(unittest.TestCase):
# The following two tests are fragile:
# The following two tests are fragile:
# They precisely count the number of allocations,
# They precisely count the number of allocations,
# which is highly implementation-dependent.
# which is highly implementation-dependent.
# For example
:
# For example
, disposed tuples are not freed, but reused.
#
- disposed tuples are not freed, but reused
#
To minimize variations, though, we first store the get_count() results
#
- the call to assertEqual somehow avoids building its args tuple
#
and check them at the end.
@refcount_test
@refcount_test
def
test_get_count
(
self
):
def
test_get_count
(
self
):
# Avoid future allocation of method object
assertEqual
=
self
.
_baseAssertEqual
gc
.
collect
()
gc
.
collect
()
assertEqual
(
gc
.
get_count
(),
(
0
,
0
,
0
))
a
,
b
,
c
=
gc
.
get_count
()
a
=
dict
()
x
=
[]
# since gc.collect(), we created two objects:
d
,
e
,
f
=
gc
.
get_count
()
# the dict, and the tuple returned by get_count()
self
.
assertEqual
((
b
,
c
),
(
0
,
0
))
assertEqual
(
gc
.
get_count
(),
(
2
,
0
,
0
))
self
.
assertEqual
((
e
,
f
),
(
0
,
0
))
# This is less fragile than asserting that a equals 0.
self
.
assertLess
(
a
,
5
)
# Between the two calls to get_count(), at least one object was
# created (the list).
self
.
assertGreater
(
d
,
a
)
@refcount_test
@refcount_test
def
test_collect_generations
(
self
):
def
test_collect_generations
(
self
):
# Avoid future allocation of method object
assertEqual
=
self
.
assertEqual
gc
.
collect
()
gc
.
collect
()
a
=
dict
()
# This object will "trickle" into generation N + 1 after
# each call to collect(N)
x
=
[]
gc
.
collect
(
0
)
gc
.
collect
(
0
)
assertEqual
(
gc
.
get_count
(),
(
0
,
1
,
0
))
# x is now in gen 1
a
,
b
,
c
=
gc
.
get_count
()
gc
.
collect
(
1
)
gc
.
collect
(
1
)
assertEqual
(
gc
.
get_count
(),
(
0
,
0
,
1
))
# x is now in gen 2
d
,
e
,
f
=
gc
.
get_count
()
gc
.
collect
(
2
)
gc
.
collect
(
2
)
assertEqual
(
gc
.
get_count
(),
(
0
,
0
,
0
))
# x is now in gen 3
g
,
h
,
i
=
gc
.
get_count
()
# We don't check a, d, g since their exact values depends on
# internal implementation details of the interpreter.
self
.
assertEqual
((
b
,
c
),
(
1
,
0
))
self
.
assertEqual
((
e
,
f
),
(
0
,
1
))
self
.
assertEqual
((
h
,
i
),
(
0
,
0
))
def
test_trashcan
(
self
):
def
test_trashcan
(
self
):
class
Ouch
:
class
Ouch
:
...
...
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