mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-76785: Add Interpreter.prepare_main() (gh-113021)
This is one of the last pieces to get test.support.interpreters in sync with PEP 734.
This commit is contained in:
parent
a49b427b02
commit
9898e61041
6 changed files with 146 additions and 17 deletions
|
@ -452,6 +452,63 @@ class TestInterpreterClose(TestBase):
|
|||
self.assertEqual(os.read(r_interp, 1), FINISHED)
|
||||
|
||||
|
||||
class TestInterpreterPrepareMain(TestBase):
|
||||
|
||||
def test_empty(self):
|
||||
interp = interpreters.create()
|
||||
with self.assertRaises(ValueError):
|
||||
interp.prepare_main()
|
||||
|
||||
def test_dict(self):
|
||||
values = {'spam': 42, 'eggs': 'ham'}
|
||||
interp = interpreters.create()
|
||||
interp.prepare_main(values)
|
||||
out = _run_output(interp, dedent("""
|
||||
print(spam, eggs)
|
||||
"""))
|
||||
self.assertEqual(out.strip(), '42 ham')
|
||||
|
||||
def test_tuple(self):
|
||||
values = {'spam': 42, 'eggs': 'ham'}
|
||||
values = tuple(values.items())
|
||||
interp = interpreters.create()
|
||||
interp.prepare_main(values)
|
||||
out = _run_output(interp, dedent("""
|
||||
print(spam, eggs)
|
||||
"""))
|
||||
self.assertEqual(out.strip(), '42 ham')
|
||||
|
||||
def test_kwargs(self):
|
||||
values = {'spam': 42, 'eggs': 'ham'}
|
||||
interp = interpreters.create()
|
||||
interp.prepare_main(**values)
|
||||
out = _run_output(interp, dedent("""
|
||||
print(spam, eggs)
|
||||
"""))
|
||||
self.assertEqual(out.strip(), '42 ham')
|
||||
|
||||
def test_dict_and_kwargs(self):
|
||||
values = {'spam': 42, 'eggs': 'ham'}
|
||||
interp = interpreters.create()
|
||||
interp.prepare_main(values, foo='bar')
|
||||
out = _run_output(interp, dedent("""
|
||||
print(spam, eggs, foo)
|
||||
"""))
|
||||
self.assertEqual(out.strip(), '42 ham bar')
|
||||
|
||||
def test_not_shareable(self):
|
||||
interp = interpreters.create()
|
||||
# XXX TypeError?
|
||||
with self.assertRaises(ValueError):
|
||||
interp.prepare_main(spam={'spam': 'eggs', 'foo': 'bar'})
|
||||
|
||||
# Make sure neither was actually bound.
|
||||
with self.assertRaises(interpreters.ExecFailure):
|
||||
interp.exec_sync('print(foo)')
|
||||
with self.assertRaises(interpreters.ExecFailure):
|
||||
interp.exec_sync('print(spam)')
|
||||
|
||||
|
||||
class TestInterpreterExecSync(TestBase):
|
||||
|
||||
def test_success(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue