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

Fred L. Drake fdrake@users.sourceforge.net
Mon, 24 Sep 2001 11:44:13 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv22027

Modified Files:
	test_profilehooks.py 
Log Message:
Add more tests showing the relationship between exceptions raised & caught
and the information provided to the profiler.  This stuff is a mess!


Index: test_profilehooks.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_profilehooks.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** test_profilehooks.py	2001/09/22 04:28:19	1.1
--- test_profilehooks.py	2001/09/24 18:44:11	1.2
***************
*** 29,36 ****
      def get_events(self):
          """Remove calls to add_event()."""
!         add_event = self.add_event.im_func.func_code
!         disallowed = (add_event.co_firstlineno, add_event.co_name)
  
!         return [item for item in self.events if item[2] != disallowed]
  
  
--- 29,36 ----
      def get_events(self):
          """Remove calls to add_event()."""
!         disallowed = [ident(self.add_event.im_func), ident(ident)]
!         self.frames = None
  
!         return [item for item in self.events if item[2] not in disallowed]
  
  
***************
*** 53,60 ****
      def test_exception(self):
          def f(p):
!             try:
!                 1/0
!             except:
!                 pass
          f_ident = ident(f)
          self.check_events(f, [(0, 'call', f_ident),
--- 53,58 ----
      def test_exception(self):
          def f(p):
!             try: 1/0
!             except: pass
          f_ident = ident(f)
          self.check_events(f, [(0, 'call', f_ident),
***************
*** 63,74 ****
                                ])
  
      def test_nested_exception(self):
          def f(p):
              1/0
          def g(p):
              try:
                  f(p)
              except:
!                 pass
          f_ident = ident(f)
          g_ident = ident(g)
--- 61,106 ----
                                ])
  
+     def test_caught_nested_exception(self):
+         def f(p):
+             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),
+                               ])
+ 
      def test_nested_exception(self):
          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),
+                               ])
+ 
+     def test_exception_in_except_clause(self):
+         def f(p):
+             1/0
+         def g(p):
              try:
                  f(p)
              except:
!                 try: f(p)
!                 except: pass
          f_ident = ident(f)
          g_ident = ident(g)
***************
*** 76,84 ****
                                (1, 'call', f_ident),
                                (1, 'exception', f_ident),
-                               # This isn't what I expected:
                                (0, 'exception', g_ident),
                                (0, 'return', g_ident),
                                ])
  
  
  def ident(function):
--- 108,139 ----
                                (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),
                                ])
  
+     def test_exception_propogation(self):
+         def f(p):
+             1/0
+         def g(p):
+             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):