mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-76785: Fixes for test.support.interpreters (gh-112982)
This involves a number of changes for PEP 734.
This commit is contained in:
parent
f26bfe4b25
commit
86a77f4e1a
30 changed files with 2506 additions and 1507 deletions
|
@ -15,6 +15,7 @@ from test.support import script_helper
|
|||
|
||||
|
||||
interpreters = import_helper.import_module('_xxsubinterpreters')
|
||||
from _xxsubinterpreters import InterpreterNotFoundError
|
||||
|
||||
|
||||
##################################
|
||||
|
@ -266,7 +267,7 @@ class GetCurrentTests(TestBase):
|
|||
main = interpreters.get_main()
|
||||
cur = interpreters.get_current()
|
||||
self.assertEqual(cur, main)
|
||||
self.assertIsInstance(cur, interpreters.InterpreterID)
|
||||
self.assertIsInstance(cur, int)
|
||||
|
||||
def test_subinterpreter(self):
|
||||
main = interpreters.get_main()
|
||||
|
@ -275,7 +276,7 @@ class GetCurrentTests(TestBase):
|
|||
import _xxsubinterpreters as _interpreters
|
||||
cur = _interpreters.get_current()
|
||||
print(cur)
|
||||
assert isinstance(cur, _interpreters.InterpreterID)
|
||||
assert isinstance(cur, int)
|
||||
"""))
|
||||
cur = int(out.strip())
|
||||
_, expected = interpreters.list_all()
|
||||
|
@ -289,7 +290,7 @@ class GetMainTests(TestBase):
|
|||
[expected] = interpreters.list_all()
|
||||
main = interpreters.get_main()
|
||||
self.assertEqual(main, expected)
|
||||
self.assertIsInstance(main, interpreters.InterpreterID)
|
||||
self.assertIsInstance(main, int)
|
||||
|
||||
def test_from_subinterpreter(self):
|
||||
[expected] = interpreters.list_all()
|
||||
|
@ -298,7 +299,7 @@ class GetMainTests(TestBase):
|
|||
import _xxsubinterpreters as _interpreters
|
||||
main = _interpreters.get_main()
|
||||
print(main)
|
||||
assert isinstance(main, _interpreters.InterpreterID)
|
||||
assert isinstance(main, int)
|
||||
"""))
|
||||
main = int(out.strip())
|
||||
self.assertEqual(main, expected)
|
||||
|
@ -333,11 +334,11 @@ class IsRunningTests(TestBase):
|
|||
def test_already_destroyed(self):
|
||||
interp = interpreters.create()
|
||||
interpreters.destroy(interp)
|
||||
with self.assertRaises(RuntimeError):
|
||||
with self.assertRaises(InterpreterNotFoundError):
|
||||
interpreters.is_running(interp)
|
||||
|
||||
def test_does_not_exist(self):
|
||||
with self.assertRaises(RuntimeError):
|
||||
with self.assertRaises(InterpreterNotFoundError):
|
||||
interpreters.is_running(1_000_000)
|
||||
|
||||
def test_bad_id(self):
|
||||
|
@ -345,70 +346,11 @@ class IsRunningTests(TestBase):
|
|||
interpreters.is_running(-1)
|
||||
|
||||
|
||||
class InterpreterIDTests(TestBase):
|
||||
|
||||
def test_with_int(self):
|
||||
id = interpreters.InterpreterID(10, force=True)
|
||||
|
||||
self.assertEqual(int(id), 10)
|
||||
|
||||
def test_coerce_id(self):
|
||||
class Int(str):
|
||||
def __index__(self):
|
||||
return 10
|
||||
|
||||
id = interpreters.InterpreterID(Int(), force=True)
|
||||
self.assertEqual(int(id), 10)
|
||||
|
||||
def test_bad_id(self):
|
||||
self.assertRaises(TypeError, interpreters.InterpreterID, object())
|
||||
self.assertRaises(TypeError, interpreters.InterpreterID, 10.0)
|
||||
self.assertRaises(TypeError, interpreters.InterpreterID, '10')
|
||||
self.assertRaises(TypeError, interpreters.InterpreterID, b'10')
|
||||
self.assertRaises(ValueError, interpreters.InterpreterID, -1)
|
||||
self.assertRaises(OverflowError, interpreters.InterpreterID, 2**64)
|
||||
|
||||
def test_does_not_exist(self):
|
||||
id = interpreters.create()
|
||||
with self.assertRaises(RuntimeError):
|
||||
interpreters.InterpreterID(int(id) + 1) # unforced
|
||||
|
||||
def test_str(self):
|
||||
id = interpreters.InterpreterID(10, force=True)
|
||||
self.assertEqual(str(id), '10')
|
||||
|
||||
def test_repr(self):
|
||||
id = interpreters.InterpreterID(10, force=True)
|
||||
self.assertEqual(repr(id), 'InterpreterID(10)')
|
||||
|
||||
def test_equality(self):
|
||||
id1 = interpreters.create()
|
||||
id2 = interpreters.InterpreterID(int(id1))
|
||||
id3 = interpreters.create()
|
||||
|
||||
self.assertTrue(id1 == id1)
|
||||
self.assertTrue(id1 == id2)
|
||||
self.assertTrue(id1 == int(id1))
|
||||
self.assertTrue(int(id1) == id1)
|
||||
self.assertTrue(id1 == float(int(id1)))
|
||||
self.assertTrue(float(int(id1)) == id1)
|
||||
self.assertFalse(id1 == float(int(id1)) + 0.1)
|
||||
self.assertFalse(id1 == str(int(id1)))
|
||||
self.assertFalse(id1 == 2**1000)
|
||||
self.assertFalse(id1 == float('inf'))
|
||||
self.assertFalse(id1 == 'spam')
|
||||
self.assertFalse(id1 == id3)
|
||||
|
||||
self.assertFalse(id1 != id1)
|
||||
self.assertFalse(id1 != id2)
|
||||
self.assertTrue(id1 != id3)
|
||||
|
||||
|
||||
class CreateTests(TestBase):
|
||||
|
||||
def test_in_main(self):
|
||||
id = interpreters.create()
|
||||
self.assertIsInstance(id, interpreters.InterpreterID)
|
||||
self.assertIsInstance(id, int)
|
||||
|
||||
self.assertIn(id, interpreters.list_all())
|
||||
|
||||
|
@ -444,7 +386,7 @@ class CreateTests(TestBase):
|
|||
import _xxsubinterpreters as _interpreters
|
||||
id = _interpreters.create()
|
||||
print(id)
|
||||
assert isinstance(id, _interpreters.InterpreterID)
|
||||
assert isinstance(id, int)
|
||||
"""))
|
||||
id2 = int(out.strip())
|
||||
|
||||
|
@ -536,11 +478,11 @@ class DestroyTests(TestBase):
|
|||
def test_already_destroyed(self):
|
||||
id = interpreters.create()
|
||||
interpreters.destroy(id)
|
||||
with self.assertRaises(RuntimeError):
|
||||
with self.assertRaises(InterpreterNotFoundError):
|
||||
interpreters.destroy(id)
|
||||
|
||||
def test_does_not_exist(self):
|
||||
with self.assertRaises(RuntimeError):
|
||||
with self.assertRaises(InterpreterNotFoundError):
|
||||
interpreters.destroy(1_000_000)
|
||||
|
||||
def test_bad_id(self):
|
||||
|
@ -741,7 +683,7 @@ class RunStringTests(TestBase):
|
|||
id = 0
|
||||
while id in interpreters.list_all():
|
||||
id += 1
|
||||
with self.assertRaises(RuntimeError):
|
||||
with self.assertRaises(InterpreterNotFoundError):
|
||||
interpreters.run_string(id, 'print("spam")')
|
||||
|
||||
def test_error_id(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue