예제 #1
0
 def run_with_api(self, code):
     """Run code with didyoumean post mortem."""
     # A bit of an ugly way to proceed, in real life scenario
     # the sys.last_<something> members are set automatically.
     for a in ('last_type', 'last_value', 'last_traceback'):
         if hasattr(sys, a):
             delattr(sys, a)
     try:
         no_exception(code)
     except:
         sys.last_type, sys.last_value, sys.last_traceback = sys.exc_info()
     ret = didyoumean_postmortem()
     if ret is not None:
         raise ret
예제 #2
0
 def run_with_api(self, code):
     """Run code with didyoumean after enabling didyoumean hook."""
     prev_hook = sys.excepthook
     self.assertEqual(prev_hook, sys.excepthook)
     didyoumean_enablehook()
     self.assertNotEqual(prev_hook, sys.excepthook)
     try:
         no_exception(code)
     except:
         last_type, last_value, last_traceback = sys.exc_info()
         sys.excepthook(last_type, last_value, last_traceback)
         raise
     finally:
         self.assertNotEqual(prev_hook, sys.excepthook)
         didyoumean_disablehook()
         self.assertEqual(prev_hook, sys.excepthook)
예제 #3
0
 def run_with_api(self, code):
     """Run code with didyoumean after enabling didyoumean hook."""
     prev_handler = None
     shell = DummyShell()
     module = sys.modules['didyoumean_api']
     shell.set(module)
     self.assertEqual(shell.handler, prev_handler)
     didyoumean_enablehook()
     self.assertNotEqual(shell.handler, prev_handler)
     try:
         no_exception(code)
     except:
         shell.showtraceback(sys.exc_info())
         raise
     finally:
         self.assertNotEqual(shell.handler, prev_handler)
         didyoumean_disablehook()
         self.assertEqual(shell.handler, prev_handler)
         shell.remove(module)
         shell = None
예제 #4
0
 def test_api_no_exception(self):
     """Check the case with no exception."""
     code = 'babar = 0\nbabar'
     no_exception(code)
     self.run_with_api(code)
예제 #5
0
 def run_with_api(self, code):
     """Run code with didyoumean context manager."""
     with didyoumean_contextmanager():
         no_exception(code)
예제 #6
0
 def my_func():
     no_exception(code)
예제 #7
0
 def set_sys_last_attr_from_exc(self, code):
     """Set attributes 'last_<xxx>' from exception thrown by code if any."""
     try:
         no_exception(code)
     except:
         sys.last_type, sys.last_value, sys.last_traceback = sys.exc_info()