(self)
| 2364 | check(interpid, False) |
| 2365 | |
| 2366 | def test_exec(self): |
| 2367 | with self.subTest('run script'): |
| 2368 | interpid = _interpreters.create() |
| 2369 | script, results = _captured_script('print("it worked!", end="")') |
| 2370 | with results: |
| 2371 | exc = _interpreters.exec(interpid, script) |
| 2372 | results = results.final() |
| 2373 | results.raise_if_failed() |
| 2374 | out = results.stdout |
| 2375 | self.assertEqual(out, 'it worked!') |
| 2376 | |
| 2377 | with self.subTest('uncaught exception'): |
| 2378 | interpid = _interpreters.create() |
| 2379 | script, results = _captured_script(""" |
| 2380 | raise Exception('uh-oh!') |
| 2381 | print("it worked!", end="") |
| 2382 | """) |
| 2383 | with results: |
| 2384 | exc = _interpreters.exec(interpid, script) |
| 2385 | out = results.stdout() |
| 2386 | expected = build_excinfo( |
| 2387 | Exception, 'uh-oh!', |
| 2388 | # We check these in other tests. |
| 2389 | formatted=exc.formatted, |
| 2390 | errdisplay=exc.errdisplay, |
| 2391 | ) |
| 2392 | self.assertEqual(out, '') |
| 2393 | self.assert_ns_equal(exc, expected) |
| 2394 | |
| 2395 | with self.subTest('from C-API'): |
| 2396 | with self.interpreter_from_capi() as interpid: |
| 2397 | with self.assertRaisesRegex(InterpreterError, 'unrecognized'): |
| 2398 | _interpreters.exec(interpid, 'raise Exception("it worked!")', |
| 2399 | restrict=True) |
| 2400 | exc = _interpreters.exec(interpid, 'raise Exception("it worked!")') |
| 2401 | self.assertIsNot(exc, None) |
| 2402 | self.assertEqual(exc.msg, 'it worked!') |
| 2403 | |
| 2404 | def test_call(self): |
| 2405 | interpid = _interpreters.create() |
nothing calls this directly
no test coverage detected