summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2006-10-03 23:23:14 (GMT)
committerBrett Cannon <bcannon@gmail.com>2006-10-03 23:23:14 (GMT)
commit373d90b365bb49e399329753fb8e6eee5d3d3713 (patch)
tree60b718dc9d3ad1079a82389f7d7860684a14677c
parent5a9aa4f31ce54a0dee6549480c13e3a2c117933e (diff)
downloadcpython-373d90b365bb49e399329753fb8e6eee5d3d3713.zip
cpython-373d90b365bb49e399329753fb8e6eee5d3d3713.tar.gz
cpython-373d90b365bb49e399329753fb8e6eee5d3d3713.tar.bz2
Convert test_imp over to unittest.
-rw-r--r--Lib/test/test_imp.py62
-rw-r--r--Misc/NEWS2
2 files changed, 35 insertions, 29 deletions
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
index 893ba24..62b14e0 100644
--- a/Lib/test/test_imp.py
+++ b/Lib/test/test_imp.py
@@ -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")
+import thread
+import unittest
+from test import test_support
-def verify_lock_state(expected):
- if imp.lock_held() != expected:
- raise TestFailed("expected imp.lock_held() to be %r" % expected)
-def testLock():
- LOOPS = 50
+class LockTests(unittest.TestCase):
- # 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)
+ """Very basic test of import lock functions."""
- for i in range(LOOPS):
- imp.acquire_lock()
- verify_lock_state(True)
+ 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
- for i in range(LOOPS):
- imp.release_lock()
+ # 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)
- # The original state should be restored now.
- verify_lock_state(lock_held_at_start)
+ for i in range(LOOPS):
+ imp.acquire_lock()
+ self.verify_lock_state(True)
- if not lock_held_at_start:
- try:
+ 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()
diff --git a/Misc/NEWS b/Misc/NEWS
index 180059b..0001f9f 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -139,6 +139,8 @@ Extension Modules
Tests
-----
+- Converted test_imp to use unittest.
+
- Fix bsddb test_basics.test06_Transactions to check the version
number properly.