Content-Length: 520499 | pFad | http://github.com/python/cpython/pull/117662/commits/7de523dedb759087ab2e77e9b2492bc990767f38

C5 gh-76785: Add More Tests to test_interpreters.test_api by ericsnowcurrently · Pull Request #117662 · python/cpython · GitHub
Skip to content

gh-76785: Add More Tests to test_interpreters.test_api #117662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bdd8d70
InterpreterError inherits from Exception.
ericsnowcurrently Apr 8, 2024
940f24d
Add _PyInterpreterState_GetIDObject().
ericsnowcurrently Apr 5, 2024
528c6e3
Add _PyXI_NewInterpreter() and _PyXI_EndInterpreter().
ericsnowcurrently Apr 5, 2024
0bd2e6b
Add _testinternalcapi.next_interpreter_id().
ericsnowcurrently Apr 1, 2024
76e32cd
Add _testinternalcapi.exec_interpreter().
ericsnowcurrently Apr 8, 2024
9b7bdc4
Sketch out tests.
ericsnowcurrently Mar 22, 2024
fa28f9b
Flesh out the tests.
ericsnowcurrently Mar 27, 2024
5e31f6e
Add PipeEnd.
ericsnowcurrently Mar 28, 2024
9111a83
Refactor _captured_script().
ericsnowcurrently Mar 28, 2024
0c24e5c
Finish the tests.
ericsnowcurrently Mar 28, 2024
611fa31
Add missing tests.
ericsnowcurrently Apr 1, 2024
bdc09f9
Add more capture/exec helpers.
ericsnowcurrently Apr 8, 2024
be85ff5
Fill out the tests.
ericsnowcurrently Apr 8, 2024
51f18f8
Adjust the tests.
ericsnowcurrently Apr 8, 2024
b1f96d2
Fix clean_up_interpreters().
ericsnowcurrently Apr 9, 2024
cd61643
Fix test_capi.test_misc.
ericsnowcurrently Apr 9, 2024
7de523d
external/unmanaged -> from_capi
ericsnowcurrently Apr 9, 2024
11d38ab
Add a missing decorator.
ericsnowcurrently Apr 9, 2024
1cf31b6
Fix other tests.
ericsnowcurrently Apr 9, 2024
4421169
Fix test_capi.
ericsnowcurrently Apr 9, 2024
c75a115
Add _interpreters.capture_exception().
ericsnowcurrently Apr 9, 2024
b00476d
Raise ExecutionFailed when possible.
ericsnowcurrently Apr 9, 2024
6a82a33
Handle OSError in the _running() script.
ericsnowcurrently Apr 9, 2024
11dae3d
Add PyInterpreterState._whence.
ericsnowcurrently Apr 10, 2024
7c9a2b9
Fix up _testinternalcapi.
ericsnowcurrently Apr 10, 2024
e68654c
Add PyInterpreterState.initialized.
ericsnowcurrently Apr 10, 2024
175080c
Add tests for whence.
ericsnowcurrently Apr 10, 2024
9db5a2b
Set interp-_ready on the main interpreter.
ericsnowcurrently Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
external/unmanaged -> from_capi
  • Loading branch information
ericsnowcurrently committed Apr 9, 2024
commit 7de523dedb759087ab2e77e9b2492bc990767f38
60 changes: 30 additions & 30 deletions Lib/test/test_interpreters/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_created_with_capi(self):
for id, *_ in _interpreters.list_all():
last = max(last, id)
expected = _testinternalcapi.next_interpreter_id()
err, text = self.run_temp_external(f"""
err, text = self.run_temp_from_capi(f"""
import {interpreters.__name__} as interpreters
interp = interpreters.get_current()
print(interp.id)
Expand Down Expand Up @@ -236,7 +236,7 @@ def test_created_with_capi(self):
(interpid5,),
]
expected2 = expected[:-2]
err, text = self.run_temp_external(f"""
err, text = self.run_temp_from_capi(f"""
import {interpreters.__name__} as interpreters
interp = interpreters.create()
print(
Expand Down Expand Up @@ -402,38 +402,38 @@ def resolve_results(err, text):
raise Exception(repr(text))

with self.subTest('running __main__ (from self)'):
with self.unmanaged_interpreter() as interpid:
err, text = self.run_external(interpid, script, main=True)
with self.interpreter_from_capi() as interpid:
err, text = self.run_from_capi(interpid, script, main=True)
running = resolve_results(err, text)
self.assertTrue(running)

with self.subTest('running, but not __main__ (from self)'):
err, text = self.run_temp_external(script)
err, text = self.run_temp_from_capi(script)
running = resolve_results(err, text)
self.assertFalse(running)

with self.subTest('running __main__ (from other)'):
with self.unmanaged_interpreter_obj() as (interp, interpid):
with self.interpreter_obj_from_capi() as (interp, interpid):
before = interp.is_running()
with self.running_external(interpid, main=True):
with self.running_from_capi(interpid, main=True):
during = interp.is_running()
after = interp.is_running()
self.assertFalse(before)
self.assertTrue(during)
self.assertFalse(after)

with self.subTest('running, but not __main__ (from other)'):
with self.unmanaged_interpreter_obj() as (interp, interpid):
with self.interpreter_obj_from_capi() as (interp, interpid):
before = interp.is_running()
with self.running_external(interpid, main=False):
with self.running_from_capi(interpid, main=False):
during = interp.is_running()
after = interp.is_running()
self.assertFalse(before)
self.assertFalse(during)
self.assertFalse(after)

with self.subTest('not running (from other)'):
with self.unmanaged_interpreter_obj() as (interp, _):
with self.interpreter_obj_from_capi() as (interp, _):
running = interp.is_running()
self.assertFalse(running)

Expand Down Expand Up @@ -573,17 +573,17 @@ def check_results(err, text):
self.assertEqual(text, '')

with self.subTest('running __main__ (from self)'):
with self.unmanaged_interpreter() as interpid:
err, text = self.run_external(interpid, script, main=True)
with self.interpreter_from_capi() as interpid:
err, text = self.run_from_capi(interpid, script, main=True)
check_results(err, text)

with self.subTest('running, but not __main__ (from self)'):
err, text = self.run_temp_external(script)
err, text = self.run_temp_from_capi(script)
check_results(err, text)

with self.subTest('running __main__ (from other)'):
with self.unmanaged_interpreter_obj() as (interp, interpid):
with self.running_external(interpid, main=True):
with self.interpreter_obj_from_capi() as (interp, interpid):
with self.running_from_capi(interpid, main=True):
with self.assertRaisesRegex(InterpreterError, 'running'):
interp.close()
# Make sure it wssn't closed.
Expand All @@ -595,15 +595,15 @@ def check_results(err, text):
return

with self.subTest('running, but not __main__ (from other)'):
with self.unmanaged_interpreter_obj() as (interp, interpid):
with self.running_external(interpid, main=False):
with self.interpreter_obj_from_capi() as (interp, interpid):
with self.running_from_capi(interpid, main=False):
with self.assertRaisesRegex(InterpreterError, 'not managed'):
interp.close()
# Make sure it wssn't closed.
self.assertFalse(interp.is_running())

with self.subTest('not running (from other)'):
with self.unmanaged_interpreter_obj() as (interp, _):
with self.interpreter_obj_from_capi() as (interp, _):
with self.assertRaisesRegex(InterpreterError, 'not managed'):
interp.close()
# Make sure it wssn't closed.
Expand Down Expand Up @@ -676,7 +676,7 @@ def test_running(self):

@requires__testinternalcapi
def test_created_with_capi(self):
with self.unmanaged_interpreter() as interpid:
with self.interpreter_from_capi() as interpid:
interp = interpreters.Interpreter(interpid)
interp.prepare_main({'spam': True})
rc = _testinternalcapi.exec_interpreter(interpid,
Expand Down Expand Up @@ -835,7 +835,7 @@ def task():
self.assertEqual(os.read(r_interp, 1), FINISHED)

def test_created_with_capi(self):
with self.unmanaged_interpreter_obj() as (interp, _):
with self.interpreter_obj_from_capi() as (interp, _):
with self.assertRaisesRegex(ExecutionFailed, 'it worked'):
interp.exec('raise Exception("it worked!")')

Expand Down Expand Up @@ -1278,7 +1278,7 @@ def parse_stdout(text):
for id, *_ in _interpreters.list_all():
last = max(last, id)
expected = last + 1
err, text = self.run_temp_external(script)
err, text = self.run_temp_from_capi(script)
assert err is None, err
interpid, = parse_stdout(text)
self.assertEqual(interpid, expected)
Expand Down Expand Up @@ -1319,7 +1319,7 @@ def test_list_all(self):
expected3 = expected + [
(interpid5,),
]
err, text = self.run_temp_external(f"""
err, text = self.run_temp_from_capi(f"""
import {_interpreters.__name__} as _interpreters
_interpreters.create()
print(
Expand Down Expand Up @@ -1438,7 +1438,7 @@ def test_get_config(self):

with self.subTest('from C-API'):
orig = _interpreters.new_config('isolated')
with self.unmanaged_interpreter(orig) as interpid:
with self.interpreter_from_capi(orig) as interpid:
config = _interpreters.get_config(interpid)
self.assert_ns_equal(config, orig)

Expand All @@ -1460,19 +1460,19 @@ def test_is_running(self):
self.assertFalse(running)

with self.subTest('from C-API (running __main__)'):
with self.unmanaged_interpreter() as interpid:
with self.running_external(interpid, main=True):
with self.interpreter_from_capi() as interpid:
with self.running_from_capi(interpid, main=True):
running = _interpreters.is_running(interpid)
self.assertTrue(running)

with self.subTest('from C-API (running, but not __main__)'):
with self.unmanaged_interpreter() as interpid:
with self.running_external(interpid, main=False):
with self.interpreter_from_capi() as interpid:
with self.running_from_capi(interpid, main=False):
running = _interpreters.is_running(interpid)
self.assertFalse(running)

with self.subTest('from C-API (not running)'):
with self.unmanaged_interpreter() as interpid:
with self.interpreter_from_capi() as interpid:
running = _interpreters.is_running(interpid)
self.assertFalse(running)

Expand Down Expand Up @@ -1509,7 +1509,7 @@ def test_exec(self):
))

with self.subTest('from C-API'):
with self.unmanaged_interpreter() as interpid:
with self.interpreter_from_capi() as interpid:
exc = _interpreters.exec(interpid, 'raise Exception("it worked!")')
self.assertIsNot(exc, None)
self.assertEqual(exc.msg, 'it worked!')
Expand Down Expand Up @@ -1555,7 +1555,7 @@ def test_set___main___attrs(self):
self.assertEqual(after3.type.__name__, 'AssertionError')

with self.subTest('from C-API'):
with self.unmanaged_interpreter() as interpid:
with self.interpreter_from_capi() as interpid:
_interpreters.set___main___attrs(interpid, {'spam': True})
exc = _interpreters.exec(interpid, 'assert spam is True')
self.assertIsNone(exc)
Expand Down
14 changes: 7 additions & 7 deletions Lib/test/test_interpreters/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def run_and_capture(self, interp, script):

@requires__testinternalcapi
@contextlib.contextmanager
def unmanaged_interpreter(self, config='legacy'):
def interpreter_from_capi(self, config='legacy'):
if isinstance(config, str):
config = _interpreters.new_config(config)
interpid = _testinternalcapi.create_interpreter()
Expand All @@ -510,8 +510,8 @@ def unmanaged_interpreter(self, config='legacy'):
pass

@contextlib.contextmanager
def unmanaged_interpreter_obj(self, config='legacy'):
with self.unmanaged_interpreter(config) as interpid:
def interpreter_obj_from_capi(self, config='legacy'):
with self.interpreter_from_capi(config) as interpid:
yield interpreters.Interpreter(interpid), interpid

@contextlib.contextmanager
Expand All @@ -522,7 +522,7 @@ def capturing(self, script):
yield wrapped, capturing.final(force=True)

@requires__testinternalcapi
def run_external(self, interpid, script, *, main=False):
def run_from_capi(self, interpid, script, *, main=False):
with self.capturing(script) as (wrapped, results):
rc = _testinternalcapi.exec_interpreter(interpid, wrapped, main=main)
assert rc == 0, rc
Expand Down Expand Up @@ -602,9 +602,9 @@ def exec_interp(script):

@requires__testinternalcapi
@contextlib.contextmanager
def running_external(self, interpid, *, main=False):
def running_from_capi(self, interpid, *, main=False):
def run_interp(script):
err, text = self.run_external(interpid, script, main=main)
err, text = self.run_from_capi(interpid, script, main=main)
assert err is None, err
assert text == '', repr(text)
def exec_interp(script):
Expand All @@ -614,7 +614,7 @@ def exec_interp(script):
yield

@requires__testinternalcapi
def run_temp_external(self, script, config='legacy'):
def run_temp_from_capi(self, script, config='legacy'):
if isinstance(config, str):
config = _interpreters.new_config(config)
with self.capturing(script) as (wrapped, results):
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/cpython/pull/117662/commits/7de523dedb759087ab2e77e9b2492bc990767f38

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy