Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_sys_settrace.RaisingTraceFuncTestCase Class Reference

List of all members.

Public Member Functions

def trace
def f
def run_test_for_event
def test_call
def test_line
def test_return
def test_exception
def test_trash_stack

Public Attributes

 raiseOnEvent

Detailed Description

Definition at line 391 of file test_sys_settrace.py.


Member Function Documentation

The function to trace; raises an exception if that's the case
we're testing, so that the 'exception' trace event fires.

Definition at line 400 of file test_sys_settrace.py.

00400 
00401     def f(self):
00402         """The function to trace; raises an exception if that's the case
00403         we're testing, so that the 'exception' trace event fires."""
00404         if self.raiseOnEvent == 'exception':
00405             x = 0
00406             y = 1/x
00407         else:
00408             return 1

Here is the caller graph for this function:

Tests that an exception raised in response to the given event is
handled OK.

Definition at line 409 of file test_sys_settrace.py.

00409 
00410     def run_test_for_event(self, event):
00411         """Tests that an exception raised in response to the given event is
00412         handled OK."""
00413         self.raiseOnEvent = event
00414         try:
00415             for i in range(sys.getrecursionlimit() + 1):
00416                 sys.settrace(self.trace)
00417                 try:
00418                     self.f()
00419                 except ValueError:
00420                     pass
00421                 else:
00422                     self.fail("exception not thrown!")
00423         except RuntimeError:
00424             self.fail("recursion counter not reset")

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 426 of file test_sys_settrace.py.

00426 
00427     def test_call(self):
        self.run_test_for_event('call')

Here is the call graph for this function:

Definition at line 432 of file test_sys_settrace.py.

00432 
00433     def test_exception(self):
00434         self.run_test_for_event('exception')

Here is the call graph for this function:

Definition at line 428 of file test_sys_settrace.py.

00428 
00429     def test_line(self):
        self.run_test_for_event('line')

Here is the call graph for this function:

Definition at line 430 of file test_sys_settrace.py.

00430 
00431     def test_return(self):
        self.run_test_for_event('return')

Here is the call graph for this function:

Definition at line 435 of file test_sys_settrace.py.

00435 
00436     def test_trash_stack(self):
00437         def f():
00438             for i in range(5):
00439                 print(i)  # line tracing will raise an exception at this line
00440 
00441         def g(frame, why, extra):
00442             if (why == 'line' and
00443                 frame.f_lineno == f.__code__.co_firstlineno + 2):
00444                 raise RuntimeError("i am crashing")
00445             return g
00446 
00447         sys.settrace(g)
00448         try:
00449             f()
00450         except RuntimeError:
00451             # the test is really that this doesn't segfault:
00452             import gc
00453             gc.collect()
00454         else:
00455             self.fail("exception not propagated")
00456 
00457 
00458 # 'Jump' tests: assigning to frame.f_lineno within a trace function
00459 # moves the execution position - it's how debuggers implement a Jump
00460 # command (aka. "Set next statement").

Here is the call graph for this function:

def test.test_sys_settrace.RaisingTraceFuncTestCase.trace (   self,
  frame,
  event,
  arg 
)
A trace function that raises an exception in response to a
specific trace event.

Definition at line 392 of file test_sys_settrace.py.

00392 
00393     def trace(self, frame, event, arg):
00394         """A trace function that raises an exception in response to a
00395         specific trace event."""
00396         if event == self.raiseOnEvent:
00397             raise ValueError # just something that isn't RuntimeError
00398         else:
00399             return self.trace

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 403 of file test_sys_settrace.py.


The documentation for this class was generated from the following file: