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
0099ba73
Kaydet (Commit)
0099ba73
authored
Eki 03, 2001
tarafından
Fred Drake
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add some more test cases to be sure we do the right thing in various cases.
üst
a0bc9993
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
0 deletions
+117
-0
test_profilehooks.py
Lib/test/test_profilehooks.py
+117
-0
No files found.
Lib/test/test_profilehooks.py
Dosyayı görüntüle @
0099ba73
from
__future__
import
generators
import
pprint
import
sys
import
unittest
...
...
@@ -40,6 +42,7 @@ class ProfileSimulator(HookWatcher):
HookWatcher
.
__init__
(
self
)
def
callback
(
self
,
frame
,
event
,
arg
):
# Callback registered with sys.setprofile()/sys.settrace()
self
.
dispatch
[
event
](
self
,
frame
)
def
trace_call
(
self
,
frame
):
...
...
@@ -55,6 +58,8 @@ class ProfileSimulator(HookWatcher):
self
.
add_event
(
'propogate-from'
,
self
.
stack
[
-
1
])
self
.
stack
.
pop
()
else
:
# Either an exception was raised in Python or a C function
# raised an exception; this does not represent propogation.
self
.
add_event
(
'ignore'
,
frame
)
dispatch
=
{
...
...
@@ -192,6 +197,79 @@ class ProfileHookTestCase(TestCaseBase):
(
0
,
'exception'
,
protect_ident
)
])
def
test_distant_exception
(
self
):
def
f
():
1
/
0
def
g
():
f
()
def
h
():
g
()
def
i
():
h
()
def
j
(
p
):
i
()
f_ident
=
ident
(
f
)
g_ident
=
ident
(
g
)
h_ident
=
ident
(
h
)
i_ident
=
ident
(
i
)
j_ident
=
ident
(
j
)
self
.
check_events
(
j
,
[(
1
,
'call'
,
j_ident
),
(
2
,
'call'
,
i_ident
),
(
3
,
'call'
,
h_ident
),
(
4
,
'call'
,
g_ident
),
(
5
,
'call'
,
f_ident
),
(
5
,
'exception'
,
f_ident
),
(
4
,
'exception'
,
g_ident
),
(
3
,
'exception'
,
h_ident
),
(
2
,
'exception'
,
i_ident
),
(
1
,
'exception'
,
j_ident
),
(
0
,
'exception'
,
protect_ident
),
])
def
test_generator
(
self
):
def
f
():
for
i
in
range
(
2
):
yield
i
def
g
(
p
):
for
i
in
f
():
pass
f_ident
=
ident
(
f
)
g_ident
=
ident
(
g
)
self
.
check_events
(
g
,
[(
1
,
'call'
,
g_ident
),
# call the iterator twice to generate values
(
2
,
'call'
,
f_ident
),
(
2
,
'return'
,
f_ident
),
(
2
,
'call'
,
f_ident
),
(
2
,
'return'
,
f_ident
),
# once more; returns end-of-iteration with
# actually raising an exception
(
2
,
'call'
,
f_ident
),
(
2
,
'return'
,
f_ident
),
(
1
,
'return'
,
g_ident
),
])
def
test_stop_iteration
(
self
):
def
f
():
for
i
in
range
(
2
):
yield
i
raise
StopIteration
def
g
(
p
):
for
i
in
f
():
pass
f_ident
=
ident
(
f
)
g_ident
=
ident
(
g
)
self
.
check_events
(
g
,
[(
1
,
'call'
,
g_ident
),
# call the iterator twice to generate values
(
2
,
'call'
,
f_ident
),
(
2
,
'return'
,
f_ident
),
(
2
,
'call'
,
f_ident
),
(
2
,
'return'
,
f_ident
),
# once more to hit the raise:
(
2
,
'call'
,
f_ident
),
(
2
,
'exception'
,
f_ident
),
(
1
,
'return'
,
g_ident
),
])
class
ProfileSimulatorTestCase
(
TestCaseBase
):
def
new_watcher
(
self
):
...
...
@@ -214,6 +292,45 @@ class ProfileSimulatorTestCase(TestCaseBase):
(
1
,
'propogate-from'
,
f_ident
),
])
def
test_caught_exception
(
self
):
def
f
(
p
):
try
:
1
/
0
except
:
pass
f_ident
=
ident
(
f
)
self
.
check_events
(
f
,
[(
1
,
'call'
,
f_ident
),
(
1
,
'ignore'
,
f_ident
),
(
1
,
'return'
,
f_ident
),
])
def
test_distant_exception
(
self
):
def
f
():
1
/
0
def
g
():
f
()
def
h
():
g
()
def
i
():
h
()
def
j
(
p
):
i
()
f_ident
=
ident
(
f
)
g_ident
=
ident
(
g
)
h_ident
=
ident
(
h
)
i_ident
=
ident
(
i
)
j_ident
=
ident
(
j
)
self
.
check_events
(
j
,
[(
1
,
'call'
,
j_ident
),
(
2
,
'call'
,
i_ident
),
(
3
,
'call'
,
h_ident
),
(
4
,
'call'
,
g_ident
),
(
5
,
'call'
,
f_ident
),
(
5
,
'ignore'
,
f_ident
),
(
5
,
'propogate-from'
,
f_ident
),
(
4
,
'propogate-from'
,
g_ident
),
(
3
,
'propogate-from'
,
h_ident
),
(
2
,
'propogate-from'
,
i_ident
),
(
1
,
'propogate-from'
,
j_ident
),
])
def
ident
(
function
):
if
hasattr
(
function
,
"f_code"
):
...
...
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