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

Fred L. Drake fdrake@users.sourceforge.net
2001年9月25日 13:48:16 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv12588
Modified Files:
	test_profilehooks.py 
Log Message:
Factor out the protect-from-exceptions helpers and make capture_events()
use it. This simplifies the individual tests a little.
Added some new tests related to exception handling.
Index: test_profilehooks.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_profilehooks.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** test_profilehooks.py	2001年09月24日 18:44:11	1.2
--- test_profilehooks.py	2001年09月25日 20:48:14	1.3
***************
*** 47,62 ****
 pass
 f_ident = ident(f)
! self.check_events(f, [(0, 'call', f_ident),
! (0, 'return', f_ident),
 ])
 
 def test_exception(self):
 def f(p):
 try: 1/0
 except: pass
 f_ident = ident(f)
! self.check_events(f, [(0, 'call', f_ident),
! (0, 'exception', f_ident),
! (0, 'return', f_ident),
 ])
 
--- 47,71 ----
 pass
 f_ident = ident(f)
! self.check_events(f, [(1, 'call', f_ident),
! (1, 'return', f_ident),
 ])
 
 def test_exception(self):
 def f(p):
+ 1/0
+ f_ident = ident(f)
+ self.check_events(f, [(1, 'call', f_ident),
+ (1, 'exception', f_ident),
+ (0, 'exception', protect_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, 'exception', f_ident),
! (1, 'return', f_ident),
 ])
 
***************
*** 65,77 ****
 try: 1/0
 except: pass
- def g(p):
- f(p)
 f_ident = ident(f)
! g_ident = ident(g)
! self.check_events(g, [(0, 'call', g_ident),
! (1, 'call', f_ident),
 (1, 'exception', f_ident),
 (1, 'return', f_ident),
- (0, 'return', g_ident),
 ])
 
--- 74,81 ----
 try: 1/0
 except: pass
 f_ident = ident(f)
! self.check_events(f, [(1, 'call', f_ident),
 (1, 'exception', f_ident),
 (1, 'return', f_ident),
 ])
 
***************
*** 79,95 ****
 def f(p):
 1/0
- def g(p):
- try: f(p)
- except: pass
 f_ident = ident(f)
! g_ident = ident(g)
! self.check_events(g, [(0, 'call', g_ident),
! (1, 'call', f_ident),
 (1, 'exception', f_ident),
 # This isn't what I expected:
! (0, 'exception', g_ident),
 # I expected this again:
 # (1, 'exception', f_ident),
- (0, 'return', g_ident),
 ])
 
--- 83,93 ----
 def f(p):
 1/0
 f_ident = ident(f)
! self.check_events(f, [(1, 'call', f_ident),
 (1, 'exception', f_ident),
 # This isn't what I expected:
! (0, 'exception', protect_ident),
 # I expected this again:
 # (1, 'exception', f_ident),
 ])
 
***************
*** 105,116 ****
 f_ident = ident(f)
 g_ident = ident(g)
! self.check_events(g, [(0, 'call', g_ident),
! (1, 'call', f_ident),
! (1, 'exception', f_ident),
! (0, 'exception', g_ident),
 (2, 'call', f_ident),
 (2, 'exception', f_ident),
! (0, 'exception', g_ident),
! (0, 'return', g_ident),
 ])
 
--- 103,114 ----
 f_ident = ident(f)
 g_ident = ident(g)
! self.check_events(g, [(1, 'call', g_ident),
 (2, 'call', f_ident),
 (2, 'exception', f_ident),
! (1, 'exception', g_ident),
! (3, 'call', f_ident),
! (3, 'exception', f_ident),
! (1, 'exception', g_ident),
! (1, 'return', g_ident),
 ])
 
***************
*** 121,140 ****
 try: f(p)
 finally: p.add_event("falling through")
- def h(p):
- try: g(p)
- except: pass
 f_ident = ident(f)
 g_ident = ident(g)
! h_ident = ident(h)
! self.check_events(h, [(0, 'call', h_ident),
! (1, 'call', g_ident),
 (2, 'call', f_ident),
 (2, 'exception', f_ident),
 (1, 'exception', g_ident),
 (1, 'falling through', g_ident),
! (0, 'exception', h_ident),
! (0, 'return', h_ident),
 ])
 
 def ident(function):
 if hasattr(function, "f_code"):
--- 119,163 ----
 try: f(p)
 finally: p.add_event("falling through")
 f_ident = ident(f)
 g_ident = ident(g)
! self.check_events(g, [(1, 'call', g_ident),
 (2, 'call', f_ident),
 (2, 'exception', f_ident),
 (1, 'exception', g_ident),
 (1, 'falling through', g_ident),
! (0, 'exception', protect_ident),
! ])
! 
! def test_raise_twice(self):
! def f(p):
! try: 1/0
! except: 1/0
! f_ident = ident(f)
! self.check_events(f, [(1, 'call', f_ident),
! (1, 'exception', f_ident),
! (1, 'exception', f_ident),
! (0, 'exception', protect_ident)
! ])
! 
! def test_raise_reraise(self):
! def f(p):
! try: 1/0
! except: raise
! f_ident = ident(f)
! self.check_events(f, [(1, 'call', f_ident),
! (1, 'exception', f_ident),
! (0, 'exception', protect_ident)
! ])
! 
! def test_raise(self):
! def f(p):
! raise Exception()
! f_ident = ident(f)
! self.check_events(f, [(1, 'call', f_ident),
! (1, 'exception', f_ident),
! (0, 'exception', protect_ident)
 ])
 
+ 
 def ident(function):
 if hasattr(function, "f_code"):
***************
*** 145,154 ****
 
 
 def capture_events(callable):
 p = HookWatcher()
 sys.setprofile(p.callback)
! callable(p)
 sys.setprofile(None)
! return p.get_events()
 
 
--- 168,184 ----
 
 
+ def protect(f, p):
+ try: f(p)
+ except: pass
+ 
+ protect_ident = ident(protect)
+ 
+ 
 def capture_events(callable):
 p = HookWatcher()
 sys.setprofile(p.callback)
! protect(callable, p)
 sys.setprofile(None)
! return p.get_events()[1:-1]
 
 

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