comparison 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
comparison
equal deleted inserted replaced
165:1f9a5982db9c 166:2eaae00d5e30
230 cx = pymonkey.Runtime().new_context() 230 cx = pymonkey.Runtime().new_context()
231 jsfunc = cx.evaluate_script(cx.new_object(), 231 jsfunc = cx.evaluate_script(cx.new_object(),
232 '(function(){})', '<string>', 1) 232 '(function(){})', '<string>', 1)
233 self.assertEqual(cx.get_object_private(jsfunc), None) 233 self.assertEqual(cx.get_object_private(jsfunc), None)
234 234
235 def testGetPendingExceptionReturnsNone(self):
236 cx = pymonkey.Runtime().new_context()
237 self.assertFalse(cx.is_exception_pending())
238 self.assertEqual(cx.get_pending_exception(), None)
239
235 def testThrowHookWorks(self): 240 def testThrowHookWorks(self):
236 timesCalled = [0] 241 exceptions = []
237 def throwhook(cx): 242 def throwhook(cx):
238 timesCalled[0] += 1 243 self.assertTrue(cx.is_exception_pending())
244 exceptions.append(cx.get_pending_exception())
239 245
240 cx = pymonkey.Runtime().new_context() 246 cx = pymonkey.Runtime().new_context()
241 cx.set_throw_hook(throwhook) 247 cx.set_throw_hook(throwhook)
242 self.assertRaises( 248 self.assertRaises(
243 pymonkey.error, 249 pymonkey.error,
244 cx.evaluate_script, 250 cx.evaluate_script,
245 cx.new_object(), 251 cx.new_object(),
246 '(function() { throw "hi"; })()', 252 '(function() { throw "hi"; })()',
247 '<string>', 1 253 '<string>', 1
248 ) 254 )
249 self.assertEqual(timesCalled[0], 2) 255 self.assertEqual(exceptions, ['hi', 'hi'])
256 self.assertFalse(cx.is_exception_pending())
257 self.assertEqual(cx.get_pending_exception(), None)
250 258
251 def testJsWrappedPythonFuncHasPrivate(self): 259 def testJsWrappedPythonFuncHasPrivate(self):
252 def foo(cx, this, args): 260 def foo(cx, this, args):
253 pass 261 pass
254 262