comparison test_pymonkey.py @ 74:e06376295170

JS exceptions thrown out to Python now include the wrapped original exception. This fixes a TODO.
author Atul Varma <varmaa@toolness.com>
date Wed, 29 Jul 2009 20:43:46 -0700
parents efa0cfe6fc03
children 4b1149d818e8
comparison
equal deleted inserted replaced
73:efa0cfe6fc03 74:e06376295170
309 309
310 def testUndefinedCannotBeInstantiated(self): 310 def testUndefinedCannotBeInstantiated(self):
311 self.assertRaises(TypeError, pymonkey.undefined) 311 self.assertRaises(TypeError, pymonkey.undefined)
312 312
313 def testEvaluateThrowsException(self): 313 def testEvaluateThrowsException(self):
314 cx = pymonkey.Runtime().new_context()
315 obj = cx.new_object()
314 self.assertRaises(pymonkey.error, 316 self.assertRaises(pymonkey.error,
315 self._evaljs, 'hai2u()') 317 cx.evaluate_script,
316 self.assertEqual(self.last_exception.message, 318 obj, 'hai2u()', '<string>', 1)
319 self.assertEqual(self._tostring(cx,
320 self.last_exception.message),
317 'ReferenceError: hai2u is not defined') 321 'ReferenceError: hai2u is not defined')
318 322
319 def testEvaluateReturnsUndefined(self): 323 def testEvaluateReturnsUndefined(self):
320 retval = self._evaljs("") 324 retval = self._evaljs("")
321 self.assertTrue(retval is pymonkey.undefined) 325 self.assertTrue(retval is pymonkey.undefined)
361 NotImplementedError, 365 NotImplementedError,
362 cx.call_function, 366 cx.call_function,
363 obj, obj, (1, self) 367 obj, obj, (1, self)
364 ) 368 )
365 369
370 def _tostring(self, cx, obj):
371 return cx.call_function(obj,
372 cx.get_property(obj, u"toString"),
373 ())
374
366 def testCallFunctionRaisesErrorFromJS(self): 375 def testCallFunctionRaisesErrorFromJS(self):
367 cx = pymonkey.Runtime().new_context() 376 cx = pymonkey.Runtime().new_context()
368 obj = cx.new_object() 377 obj = cx.new_object()
369 obj = cx.evaluate_script( 378 obj = cx.evaluate_script(
370 obj, 379 obj,
372 '<string>', 1 381 '<string>', 1
373 ) 382 )
374 self.assertRaises(pymonkey.error, 383 self.assertRaises(pymonkey.error,
375 cx.call_function, 384 cx.call_function,
376 obj, obj, (1,)) 385 obj, obj, (1,))
377 self.assertEqual(self.last_exception.message, 386 self.assertEqual(self._tostring(cx,
387 self.last_exception.message),
378 'ReferenceError: blarg is not defined') 388 'ReferenceError: blarg is not defined')
379 389
380 def testCallFunctionWorks(self): 390 def testCallFunctionWorks(self):
381 cx = pymonkey.Runtime().new_context() 391 cx = pymonkey.Runtime().new_context()
382 obj = cx.new_object() 392 obj = cx.new_object()