mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Convert test_imp over to unittest.
This commit is contained in:
parent
5a9aa4f31c
commit
373d90b365
2 changed files with 35 additions and 29 deletions
|
@ -1,43 +1,47 @@
|
||||||
import imp
|
import imp
|
||||||
from test.test_support import TestFailed, TestSkipped
|
import thread
|
||||||
try:
|
import unittest
|
||||||
import thread
|
from test import test_support
|
||||||
except ImportError:
|
|
||||||
raise TestSkipped("test only valid when thread support is available")
|
|
||||||
|
|
||||||
def verify_lock_state(expected):
|
|
||||||
if imp.lock_held() != expected:
|
|
||||||
raise TestFailed("expected imp.lock_held() to be %r" % expected)
|
|
||||||
|
|
||||||
def testLock():
|
class LockTests(unittest.TestCase):
|
||||||
LOOPS = 50
|
|
||||||
|
|
||||||
# The import lock may already be held, e.g. if the test suite is run
|
"""Very basic test of import lock functions."""
|
||||||
# via "import test.autotest".
|
|
||||||
lock_held_at_start = imp.lock_held()
|
|
||||||
verify_lock_state(lock_held_at_start)
|
|
||||||
|
|
||||||
for i in range(LOOPS):
|
def verify_lock_state(self, expected):
|
||||||
imp.acquire_lock()
|
self.failUnlessEqual(imp.lock_held(), expected,
|
||||||
verify_lock_state(True)
|
"expected imp.lock_held() to be %r" % expected)
|
||||||
|
def testLock(self):
|
||||||
|
LOOPS = 50
|
||||||
|
|
||||||
for i in range(LOOPS):
|
# The import lock may already be held, e.g. if the test suite is run
|
||||||
imp.release_lock()
|
# via "import test.autotest".
|
||||||
|
lock_held_at_start = imp.lock_held()
|
||||||
|
self.verify_lock_state(lock_held_at_start)
|
||||||
|
|
||||||
# The original state should be restored now.
|
for i in range(LOOPS):
|
||||||
verify_lock_state(lock_held_at_start)
|
imp.acquire_lock()
|
||||||
|
self.verify_lock_state(True)
|
||||||
|
|
||||||
if not lock_held_at_start:
|
for i in range(LOOPS):
|
||||||
try:
|
|
||||||
imp.release_lock()
|
imp.release_lock()
|
||||||
except RuntimeError:
|
|
||||||
pass
|
# The original state should be restored now.
|
||||||
else:
|
self.verify_lock_state(lock_held_at_start)
|
||||||
raise TestFailed("release_lock() without lock should raise "
|
|
||||||
"RuntimeError")
|
if not lock_held_at_start:
|
||||||
|
try:
|
||||||
|
imp.release_lock()
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.fail("release_lock() without lock should raise "
|
||||||
|
"RuntimeError")
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
testLock()
|
test_support.run_unittest(
|
||||||
|
LockTests,
|
||||||
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main()
|
test_main()
|
||||||
|
|
|
@ -139,6 +139,8 @@ Extension Modules
|
||||||
Tests
|
Tests
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
- Converted test_imp to use unittest.
|
||||||
|
|
||||||
- Fix bsddb test_basics.test06_Transactions to check the version
|
- Fix bsddb test_basics.test06_Transactions to check the version
|
||||||
number properly.
|
number properly.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue