diff tests/test_pymonkey.py @ 166:2eaae00d5e30

Added is_exception_pending() and get_pending_exception().
author Atul Varma <varmaa@toolness.com>
date Sun, 30 Aug 2009 20:04:35 -0700
parents 1f9a5982db9c
children
line wrap: on
line diff
--- a/tests/test_pymonkey.py	Sun Aug 30 19:03:46 2009 -0700
+++ b/tests/test_pymonkey.py	Sun Aug 30 20:04:35 2009 -0700
@@ -232,10 +232,16 @@
                                     '(function(){})', '<string>', 1)
         self.assertEqual(cx.get_object_private(jsfunc), None)
 
+    def testGetPendingExceptionReturnsNone(self):
+        cx = pymonkey.Runtime().new_context()
+        self.assertFalse(cx.is_exception_pending())
+        self.assertEqual(cx.get_pending_exception(), None)
+
     def testThrowHookWorks(self):
-        timesCalled = [0]
+        exceptions = []
         def throwhook(cx):
-            timesCalled[0] += 1
+            self.assertTrue(cx.is_exception_pending())
+            exceptions.append(cx.get_pending_exception())
 
         cx = pymonkey.Runtime().new_context()
         cx.set_throw_hook(throwhook)
@@ -246,7 +252,9 @@
             '(function() { throw "hi"; })()',
             '<string>', 1
             )
-        self.assertEqual(timesCalled[0], 2)
+        self.assertEqual(exceptions, ['hi', 'hi'])
+        self.assertFalse(cx.is_exception_pending())
+        self.assertEqual(cx.get_pending_exception(), None)
 
     def testJsWrappedPythonFuncHasPrivate(self):
         def foo(cx, this, args):