summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_trace.py
diff options
context:
space:
mode:
authorMichael W. Hudson <mwh@python.net>2002-11-08 13:08:46 (GMT)
committerMichael W. Hudson <mwh@python.net>2002-11-08 13:08:46 (GMT)
commit006c75265fe815fefadd119d6c7f322b1105c9bb (patch)
treeb68ed1d8d49737841c6e1a42a1408a7e0934a9e0 /Lib/test/test_trace.py
parent019a78e76d3542d4d56a08015e6980f8c8aeaba1 (diff)
downloadcpython-006c75265fe815fefadd119d6c7f322b1105c9bb.zip
cpython-006c75265fe815fefadd119d6c7f322b1105c9bb.tar.gz
cpython-006c75265fe815fefadd119d6c7f322b1105c9bb.tar.bz2
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 91112e8..d5fb0e5 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)