MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / async_fn

Function async_fn

tests/python/test_pythonmonkey_eval.py:183–198  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

181def test_eval_exceptions_preserve_promise_rejection():
182 # Tests for https://github.com/Distributive-Network/PythonMonkey/blob/d9a8ebe/src/PromiseType.cc#L46-L48
183 async def async_fn():
184 try:
185 await pm.eval("Promise.reject(Number(123))", {'mutedErrors': True})
186 # The mutedErrors option is required to avoid sending this to uncaughtExceptionHandler prematurely
187 except Exception as py_err:
188 assert type(py_err) is pm.SpiderMonkeyError
189 assert repr(py_err) == "SpiderMonkeyError(123.0)"
190 assert pm.eval("(e) => e instanceof Number")(py_err)
191 assert pm.eval("(e) => e == 123")(py_err)
192 try:
193 await pm.eval("Promise.reject(new TypeError('Promise rejection'))", {'mutedErrors': True})
194 except Exception as py_err:
195 assert type(py_err) is pm.SpiderMonkeyError
196 assert pm.eval("(e) => e instanceof TypeError")(py_err)
197 assert pm.eval("(e) => e.message == 'Promise rejection'")(py_err)
198 return True
199 assert asyncio.run(async_fn())
200
201

Calls

no outgoing calls

Tested by

no test coverage detected