Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Nov 1, 2023
1 parent 59e0e0f commit 5443e2c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
12 changes: 6 additions & 6 deletions Lib/test/test__xxinterpchannels.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,16 +1017,16 @@ def test_close_multiple_users(self):
_channels.recv({cid})
"""))
channels.close(cid)
with self.assertRaises(interpreters.RunFailedError) as cm:
interpreters.run_string(id1, dedent(f"""

excsnap = interpreters.run_string(id1, dedent(f"""
_channels.send({cid}, b'spam')
"""))
self.assertIn('ChannelClosedError', str(cm.exception))
with self.assertRaises(interpreters.RunFailedError) as cm:
interpreters.run_string(id2, dedent(f"""
self.assertIn('ChannelClosedError', excsnap.type)

excsnap = interpreters.run_string(id2, dedent(f"""
_channels.send({cid}, b'spam')
"""))
self.assertIn('ChannelClosedError', str(cm.exception))
self.assertIn('ChannelClosedError', excsnap.type)

def test_close_multiple_times(self):
cid = channels.create()
Expand Down
10 changes: 6 additions & 4 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1968,10 +1968,12 @@ def test_disallowed_reimport(self):
print(_testsinglephase)
''')
interpid = _interpreters.create()
with self.assertRaises(_interpreters.RunFailedError):
_interpreters.run_string(interpid, script)
with self.assertRaises(_interpreters.RunFailedError):
_interpreters.run_string(interpid, script)

excsnap = _interpreters.run_string(interpid, script)
self.assertIsNot(excsnap, None)

excsnap = _interpreters.run_string(interpid, script)
self.assertIsNot(excsnap, None)


class TestSinglePhaseSnapshot(ModuleSnapshot):
Expand Down
22 changes: 8 additions & 14 deletions Lib/test/test_importlib/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,25 +655,19 @@ def test_magic_number(self):
@unittest.skipIf(_interpreters is None, 'subinterpreters required')
class IncompatibleExtensionModuleRestrictionsTests(unittest.TestCase):

ERROR = re.compile("^ImportError: module (.*) does not support loading in subinterpreters")

def run_with_own_gil(self, script):
interpid = _interpreters.create(isolated=True)
try:
_interpreters.run_string(interpid, script)
except _interpreters.RunFailedError as exc:
if m := self.ERROR.match(str(exc)):
modname, = m.groups()
raise ImportError(modname)
excsnap = _interpreters.run_string(interpid, script)
if excsnap is not None:
if excsnap.type == 'ImportError':
raise ImportError(excsnap.msg)

def run_with_shared_gil(self, script):
interpid = _interpreters.create(isolated=False)
try:
_interpreters.run_string(interpid, script)
except _interpreters.RunFailedError as exc:
if m := self.ERROR.match(str(exc)):
modname, = m.groups()
raise ImportError(modname)
excsnap = _interpreters.run_string(interpid, script)
if excsnap is not None:
if excsnap.type == 'ImportError':
raise ImportError(excsnap.msg)

@unittest.skipIf(_testsinglephase is None, "test requires _testsinglephase module")
def test_single_phase_init_module(self):
Expand Down

0 comments on commit 5443e2c

Please sign in to comment.