Mercurial > pymonkey
comparison test_pymonkey.py @ 47:3f4982759e55
Converting JS exceptions into Python exceptions is now doable, albeit not yet implemented, thanks to the discovery of JSOPTION_DONT_REPORT_UNCAUGHT. Also, JS warnings are now converted into Python warnings.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 06 Jul 2009 08:13:45 -0700 |
parents | a0f677cfc679 |
children | 427b01954b22 |
comparison
equal
deleted
inserted
replaced
46:a0f677cfc679 | 47:3f4982759e55 |
---|---|
55 raise Exception("hello") | 55 raise Exception("hello") |
56 self.assertRaises(pymonkey.error, | 56 self.assertRaises(pymonkey.error, |
57 self._evalJsWrappedPyFunc, | 57 self._evalJsWrappedPyFunc, |
58 hai2u, 'hai2u()') | 58 hai2u, 'hai2u()') |
59 self.assertEqual(self.last_exception.message, | 59 self.assertEqual(self.last_exception.message, |
60 "uncaught exception: hello") | 60 "hello") |
61 | 61 |
62 def testJsWrappedPythonFunctionReturnsNone(self): | 62 def testJsWrappedPythonFunctionReturnsNone(self): |
63 def hai2u(cx): | 63 def hai2u(cx): |
64 pass | 64 pass |
65 self.assertEqual(self._evalJsWrappedPyFunc(hai2u, 'hai2u()'), | 65 self.assertEqual(self._evalJsWrappedPyFunc(hai2u, 'hai2u()'), |
125 | 125 |
126 def testObjectIsIdentityPreserving(self): | 126 def testObjectIsIdentityPreserving(self): |
127 cx = pymonkey.Runtime().new_context() | 127 cx = pymonkey.Runtime().new_context() |
128 obj = cx.new_object() | 128 obj = cx.new_object() |
129 cx.init_standard_classes(obj) | 129 cx.init_standard_classes(obj) |
130 cx.evaluate_script(obj, 'foo = {bar: 1}', '<string>', 1) | 130 cx.evaluate_script(obj, 'var foo = {bar: 1}', '<string>', 1) |
131 self.assertTrue(isinstance(cx.get_property(obj, u"foo"), | 131 self.assertTrue(isinstance(cx.get_property(obj, u"foo"), |
132 pymonkey.Object)) | 132 pymonkey.Object)) |
133 self.assertTrue(cx.get_property(obj, u"foo") is | 133 self.assertTrue(cx.get_property(obj, u"foo") is |
134 cx.get_property(obj, u"foo")) | 134 cx.get_property(obj, u"foo")) |
135 | 135 |
136 def testObjectGetattrWorks(self): | 136 def testObjectGetattrWorks(self): |
137 cx = pymonkey.Runtime().new_context() | 137 cx = pymonkey.Runtime().new_context() |
138 obj = cx.new_object() | 138 obj = cx.new_object() |
139 cx.init_standard_classes(obj) | 139 cx.init_standard_classes(obj) |
140 cx.evaluate_script(obj, 'boop = 5', '<string>', 1) | 140 cx.evaluate_script(obj, 'var boop = 5', '<string>', 1) |
141 cx.evaluate_script(obj, 'this["blarg\u2026"] = 5', '<string>', 1) | 141 cx.evaluate_script(obj, 'this["blarg\u2026"] = 5', '<string>', 1) |
142 self.assertEqual(cx.get_property(obj, u"beans"), | 142 self.assertEqual(cx.get_property(obj, u"beans"), |
143 pymonkey.undefined) | 143 pymonkey.undefined) |
144 self.assertEqual(cx.get_property(obj, u"blarg\u2026"), 5) | 144 self.assertEqual(cx.get_property(obj, u"blarg\u2026"), 5) |
145 self.assertEqual(cx.get_property(obj, u"boop"), 5) | 145 self.assertEqual(cx.get_property(obj, u"boop"), 5) |
179 | 179 |
180 def testEvaluateThrowsException(self): | 180 def testEvaluateThrowsException(self): |
181 self.assertRaises(pymonkey.error, | 181 self.assertRaises(pymonkey.error, |
182 self._evaljs, 'hai2u()') | 182 self._evaljs, 'hai2u()') |
183 self.assertEqual(self.last_exception.message, | 183 self.assertEqual(self.last_exception.message, |
184 'File "<string>", line 1: ReferenceError: ' | 184 'ReferenceError: hai2u is not defined') |
185 'hai2u is not defined') | |
186 | 185 |
187 def testEvaluateReturnsUndefined(self): | 186 def testEvaluateReturnsUndefined(self): |
188 retval = self._evaljs("") | 187 retval = self._evaljs("") |
189 self.assertTrue(retval is pymonkey.undefined) | 188 self.assertTrue(retval is pymonkey.undefined) |
190 | 189 |
241 ) | 240 ) |
242 self.assertRaises(pymonkey.error, | 241 self.assertRaises(pymonkey.error, |
243 cx.call_function, | 242 cx.call_function, |
244 obj, obj, (1,)) | 243 obj, obj, (1,)) |
245 self.assertEqual(self.last_exception.message, | 244 self.assertEqual(self.last_exception.message, |
246 'File "<string>", line 1: ReferenceError: ' | 245 'ReferenceError: blarg is not defined') |
247 'blarg is not defined') | |
248 | 246 |
249 def testCallFunctionWorks(self): | 247 def testCallFunctionWorks(self): |
250 cx = pymonkey.Runtime().new_context() | 248 cx = pymonkey.Runtime().new_context() |
251 obj = cx.new_object() | 249 obj = cx.new_object() |
252 thisArg = cx.new_object() | 250 thisArg = cx.new_object() |