Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0099ba73
Commit
0099ba73
authored
Oct 03, 2001
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some more test cases to be sure we do the right thing in various cases.
parent
a0bc9993
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
0 deletions
+117
-0
Lib/test/test_profilehooks.py
Lib/test/test_profilehooks.py
+117
-0
No files found.
Lib/test/test_profilehooks.py
View file @
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