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
9e3d27b5
Kaydet (Commit)
9e3d27b5
authored
Agu 05, 2013
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Followup to 862ab99ab570: I forgot to add the magnificent test_frame.py.
üst
58720d61
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
113 additions
and
0 deletions
+113
-0
test_frame.py
Lib/test/test_frame.py
+113
-0
No files found.
Lib/test/test_frame.py
0 → 100644
Dosyayı görüntüle @
9e3d27b5
import
gc
import
sys
import
unittest
import
weakref
from
test
import
support
class
ClearTest
(
unittest
.
TestCase
):
"""
Tests for frame.clear().
"""
def
inner
(
self
,
x
=
5
,
**
kwargs
):
1
/
0
def
outer
(
self
,
**
kwargs
):
try
:
self
.
inner
(
**
kwargs
)
except
ZeroDivisionError
as
e
:
exc
=
e
return
exc
def
clear_traceback_frames
(
self
,
tb
):
"""
Clear all frames in a traceback.
"""
while
tb
is
not
None
:
tb
.
tb_frame
.
clear
()
tb
=
tb
.
tb_next
def
test_clear_locals
(
self
):
class
C
:
pass
c
=
C
()
wr
=
weakref
.
ref
(
c
)
exc
=
self
.
outer
(
c
=
c
)
del
c
support
.
gc_collect
()
# A reference to c is held through the frames
self
.
assertIsNot
(
None
,
wr
())
self
.
clear_traceback_frames
(
exc
.
__traceback__
)
support
.
gc_collect
()
# The reference was released by .clear()
self
.
assertIs
(
None
,
wr
())
def
test_clear_generator
(
self
):
endly
=
False
def
g
():
nonlocal
endly
try
:
yield
inner
()
finally
:
endly
=
True
gen
=
g
()
next
(
gen
)
self
.
assertFalse
(
endly
)
# Clearing the frame closes the generator
gen
.
gi_frame
.
clear
()
self
.
assertTrue
(
endly
)
def
test_clear_executing
(
self
):
# Attempting to clear an executing frame is forbidden.
try
:
1
/
0
except
ZeroDivisionError
as
e
:
f
=
e
.
__traceback__
.
tb_frame
with
self
.
assertRaises
(
RuntimeError
):
f
.
clear
()
with
self
.
assertRaises
(
RuntimeError
):
f
.
f_back
.
clear
()
def
test_clear_executing_generator
(
self
):
# Attempting to clear an executing generator frame is forbidden.
endly
=
False
def
g
():
nonlocal
endly
try
:
1
/
0
except
ZeroDivisionError
as
e
:
f
=
e
.
__traceback__
.
tb_frame
with
self
.
assertRaises
(
RuntimeError
):
f
.
clear
()
with
self
.
assertRaises
(
RuntimeError
):
f
.
f_back
.
clear
()
yield
f
finally
:
endly
=
True
gen
=
g
()
f
=
next
(
gen
)
self
.
assertFalse
(
endly
)
@support.cpython_only
def
test_clear_refcycles
(
self
):
# .clear() doesn't leave any refcycle behin
with
support
.
disable_gc
():
class
C
:
pass
c
=
C
()
wr
=
weakref
.
ref
(
c
)
exc
=
self
.
outer
(
c
=
c
)
del
c
self
.
assertIsNot
(
None
,
wr
())
self
.
clear_traceback_frames
(
exc
.
__traceback__
)
self
.
assertIs
(
None
,
wr
())
def
test_main
():
support
.
run_unittest
(
__name__
)
if
__name__
==
"__main__"
:
test_main
()
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