summaryrefslogtreecommitdiff
path: root/Lib/test/test_trace.py
diff options
context:
space:
mode:
authorMichael W. Hudson <mwh@python.net>2002-11-08 13:08:46 +0000
committerMichael W. Hudson <mwh@python.net>2002-11-08 13:08:46 +0000
commit9dceef1b6b515faf3883f7de9be59fb8ea033c9f (patch)
tree78e3c04e086e9e2b323497c8210ec801b5ea979d /Lib/test/test_trace.py
parent01f43f48c2145b6b51955004fa6f166a3b3360ad (diff)
downloadcpython-9dceef1b6b515faf3883f7de9be59fb8ea033c9f.tar.gz
This is Richie Hindle's patch:
[ 631276 ] Exceptions raised by line trace function It conflicted with the patches from Armin I just checked it, so I had to so some bits by hand.
Diffstat (limited to 'Lib/test/test_trace.py')
-rw-r--r--Lib/test/test_trace.py37
1 files changed, 31 insertions, 6 deletions
diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py
index 91112e8b21..d5fb0e504d 100644
--- a/Lib/test/test_trace.py
+++ b/Lib/test/test_trace.py
@@ -178,23 +178,48 @@ class TraceTestCase(unittest.TestCase):
self.run_test2(settrace_and_raise)
class RaisingTraceFuncTestCase(unittest.TestCase):
- def test_it(self):
- def tr(frame, event, arg):
+ def trace(self, frame, event, arg):
+ """A trace function that raises an exception in response to a
+ specific trace event."""
+ if event == self.raiseOnEvent:
raise ValueError # just something that isn't RuntimeError
- def f():
+ else:
+ return self.trace
+
+ def f(self):
+ """The function to trace; raises an exception if that's the case
+ we're testing, so that the 'exception' trace event fires."""
+ if self.raiseOnEvent == 'exception':
+ x = 0
+ y = 1/x
+ else:
return 1
+
+ def run_test_for_event(self, event):
+ """Tests that an exception raised in response to the given event is
+ handled OK."""
+ self.raiseOnEvent = event
try:
for i in xrange(sys.getrecursionlimit() + 1):
- sys.settrace(tr)
+ sys.settrace(self.trace)
try:
- f()
+ self.f()
except ValueError:
pass
else:
self.fail("exception not thrown!")
except RuntimeError:
self.fail("recursion counter not reset")
-
+
+ # Test the handling of exceptions raised by each kind of trace event.
+ def test_call(self):
+ self.run_test_for_event('call')
+ def test_line(self):
+ self.run_test_for_event('line')
+ def test_return(self):
+ self.run_test_for_event('return')
+ def test_exception(self):
+ self.run_test_for_event('exception')
def test_main():
test_support.run_unittest(TraceTestCase)