[Python-checkins] CVS: python/dist/src/Lib/test test_profilehooks.py,1.4,1.5

Fred L. Drake fdrake@users.sourceforge.net
2001年10月03日 14:15:34 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv3395/test
Modified Files:
	test_profilehooks.py 
Log Message:
Add some more test cases to be sure we do the right thing in various cases.
Index: test_profilehooks.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_profilehooks.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** test_profilehooks.py	2001年09月26日 21:00:33	1.4
--- test_profilehooks.py	2001年10月03日 21:15:32	1.5
***************
*** 1,2 ****
--- 1,4 ----
+ from __future__ import generators
+ 
 import pprint
 import sys
***************
*** 41,44 ****
--- 43,47 ----
 
 def callback(self, frame, event, arg):
+ # Callback registered with sys.setprofile()/sys.settrace()
 self.dispatch[event](self, frame)
 
***************
*** 56,59 ****
--- 59,64 ----
 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)
 
***************
*** 193,197 ****
--- 198,275 ----
 ])
 
+ 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):
***************
*** 213,216 ****
--- 291,333 ----
 (1, 'ignore', f_ident),
 (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),
 ])
 

AltStyle によって変換されたページ (->オリジナル) /