Kaydet (Commit) 373d90b3 authored tarafından Brett Cannon's avatar Brett Cannon

Convert test_imp over to unittest.

üst 5a9aa4f3
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):
"""Very basic test of import lock functions."""
def verify_lock_state(self, expected):
self.failUnlessEqual(imp.lock_held(), expected,
"expected imp.lock_held() to be %r" % expected)
def testLock(self):
LOOPS = 50 LOOPS = 50
# The import lock may already be held, e.g. if the test suite is run # The import lock may already be held, e.g. if the test suite is run
# via "import test.autotest". # via "import test.autotest".
lock_held_at_start = imp.lock_held() lock_held_at_start = imp.lock_held()
verify_lock_state(lock_held_at_start) self.verify_lock_state(lock_held_at_start)
for i in range(LOOPS): for i in range(LOOPS):
imp.acquire_lock() imp.acquire_lock()
verify_lock_state(True) self.verify_lock_state(True)
for i in range(LOOPS): for i in range(LOOPS):
imp.release_lock() imp.release_lock()
# The original state should be restored now. # The original state should be restored now.
verify_lock_state(lock_held_at_start) self.verify_lock_state(lock_held_at_start)
if not lock_held_at_start: if not lock_held_at_start:
try: try:
...@@ -33,11 +35,13 @@ def testLock(): ...@@ -33,11 +35,13 @@ def testLock():
except RuntimeError: except RuntimeError:
pass pass
else: else:
raise TestFailed("release_lock() without lock should raise " self.fail("release_lock() without lock should raise "
"RuntimeError") "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 ...@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment