[Python-checkins] r52123 - in python/trunk: Lib/test/test_imp.py Misc/NEWS
brett.cannon
python-checkins at python.org
Wed Oct 4 01:23:15 CEST 2006
Author: brett.cannon
Date: Wed Oct 4 01:23:14 2006
New Revision: 52123
Modified:
python/trunk/Lib/test/test_imp.py
python/trunk/Misc/NEWS
Log:
Convert test_imp over to unittest.
Modified: python/trunk/Lib/test/test_imp.py
==============================================================================
--- python/trunk/Lib/test/test_imp.py (original)
+++ python/trunk/Lib/test/test_imp.py Wed Oct 4 01:23:14 2006
@@ -1,43 +1,47 @@
import imp
-from test.test_support import TestFailed, TestSkipped
-try:
- import thread
-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():
- LOOPS = 50
-
- # The import lock may already be held, e.g. if the test suite is run
- # via "import test.autotest".
- lock_held_at_start = imp.lock_held()
- verify_lock_state(lock_held_at_start)
-
- for i in range(LOOPS):
- imp.acquire_lock()
- verify_lock_state(True)
+import thread
+import unittest
+from test import test_support
- for i in range(LOOPS):
- imp.release_lock()
- # The original state should be restored now.
- verify_lock_state(lock_held_at_start)
+class LockTests(unittest.TestCase):
- if not lock_held_at_start:
- try:
+ """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
+
+ # The import lock may already be held, e.g. if the test suite is run
+ # via "import test.autotest".
+ lock_held_at_start = imp.lock_held()
+ self.verify_lock_state(lock_held_at_start)
+
+ for i in range(LOOPS):
+ imp.acquire_lock()
+ self.verify_lock_state(True)
+
+ for i in range(LOOPS):
imp.release_lock()
- except RuntimeError:
- pass
- else:
- raise TestFailed("release_lock() without lock should raise "
- "RuntimeError")
+
+ # The original state should be restored now.
+ self.verify_lock_state(lock_held_at_start)
+
+ 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():
- testLock()
+ test_support.run_unittest(
+ LockTests,
+ )
if __name__ == "__main__":
test_main()
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Wed Oct 4 01:23:14 2006
@@ -139,6 +139,8 @@
Tests
-----
+- Converted test_imp to use unittest.
+
- Fix bsddb test_basics.test06_Transactions to check the version
number properly.
More information about the Python-checkins
mailing list