mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Issue #21503: Use test_both() consistently in test_importlib.
This commit is contained in:
parent
d50cee2045
commit
3497c0bf95
30 changed files with 526 additions and 428 deletions
|
@ -1,7 +1,6 @@
|
|||
from . import util
|
||||
frozen_init, source_init = util.import_importlib('importlib')
|
||||
frozen_bootstrap = frozen_init._bootstrap
|
||||
source_bootstrap = source_init._bootstrap
|
||||
from . import util as test_util
|
||||
|
||||
init = test_util.import_importlib('importlib')
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
@ -33,13 +32,16 @@ if threading is not None:
|
|||
# _release_save() unsupported
|
||||
test_release_save_unacquired = None
|
||||
|
||||
class Frozen_ModuleLockAsRLockTests(ModuleLockAsRLockTests, lock_tests.RLockTests):
|
||||
LockType = frozen_bootstrap._ModuleLock
|
||||
|
||||
class Source_ModuleLockAsRLockTests(ModuleLockAsRLockTests, lock_tests.RLockTests):
|
||||
LockType = source_bootstrap._ModuleLock
|
||||
LOCK_TYPES = {kind: splitinit._bootstrap._ModuleLock
|
||||
for kind, splitinit in init.items()}
|
||||
|
||||
(Frozen_ModuleLockAsRLockTests,
|
||||
Source_ModuleLockAsRLockTests
|
||||
) = test_util.test_both(ModuleLockAsRLockTests, lock_tests.RLockTests,
|
||||
LockType=LOCK_TYPES)
|
||||
else:
|
||||
LOCK_TYPES = {}
|
||||
|
||||
class Frozen_ModuleLockAsRLockTests(unittest.TestCase):
|
||||
pass
|
||||
|
||||
|
@ -47,6 +49,7 @@ else:
|
|||
pass
|
||||
|
||||
|
||||
@unittest.skipUnless(threading, "threads needed for this test")
|
||||
class DeadlockAvoidanceTests:
|
||||
|
||||
def setUp(self):
|
||||
|
@ -106,19 +109,22 @@ class DeadlockAvoidanceTests:
|
|||
self.assertEqual(results.count((True, False)), 0)
|
||||
self.assertEqual(results.count((True, True)), len(results))
|
||||
|
||||
@unittest.skipUnless(threading, "threads needed for this test")
|
||||
class Frozen_DeadlockAvoidanceTests(DeadlockAvoidanceTests, unittest.TestCase):
|
||||
LockType = frozen_bootstrap._ModuleLock
|
||||
DeadlockError = frozen_bootstrap._DeadlockError
|
||||
|
||||
@unittest.skipUnless(threading, "threads needed for this test")
|
||||
class Source_DeadlockAvoidanceTests(DeadlockAvoidanceTests, unittest.TestCase):
|
||||
LockType = source_bootstrap._ModuleLock
|
||||
DeadlockError = source_bootstrap._DeadlockError
|
||||
DEADLOCK_ERRORS = {kind: splitinit._bootstrap._DeadlockError
|
||||
for kind, splitinit in init.items()}
|
||||
|
||||
(Frozen_DeadlockAvoidanceTests,
|
||||
Source_DeadlockAvoidanceTests
|
||||
) = test_util.test_both(DeadlockAvoidanceTests,
|
||||
LockType=LOCK_TYPES, DeadlockError=DEADLOCK_ERRORS)
|
||||
|
||||
|
||||
class LifetimeTests:
|
||||
|
||||
@property
|
||||
def bootstrap(self):
|
||||
return self.init._bootstrap
|
||||
|
||||
def test_lock_lifetime(self):
|
||||
name = "xyzzy"
|
||||
self.assertNotIn(name, self.bootstrap._module_locks)
|
||||
|
@ -135,11 +141,10 @@ class LifetimeTests:
|
|||
self.assertEqual(0, len(self.bootstrap._module_locks),
|
||||
self.bootstrap._module_locks)
|
||||
|
||||
class Frozen_LifetimeTests(LifetimeTests, unittest.TestCase):
|
||||
bootstrap = frozen_bootstrap
|
||||
|
||||
class Source_LifetimeTests(LifetimeTests, unittest.TestCase):
|
||||
bootstrap = source_bootstrap
|
||||
(Frozen_LifetimeTests,
|
||||
Source_LifetimeTests
|
||||
) = test_util.test_both(LifetimeTests, init=init)
|
||||
|
||||
|
||||
@support.reap_threads
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue