+++ /dev/null
-import imp\r
-import unittest\r
-from test import test_support\r
-\r
-\r
-class LockTests(unittest.TestCase):\r
-\r
- """Very basic test of import lock functions."""\r
-\r
- def verify_lock_state(self, expected):\r
- self.assertEqual(imp.lock_held(), expected,\r
- "expected imp.lock_held() to be %r" % expected)\r
- def testLock(self):\r
- LOOPS = 50\r
-\r
- # The import lock may already be held, e.g. if the test suite is run\r
- # via "import test.autotest".\r
- lock_held_at_start = imp.lock_held()\r
- self.verify_lock_state(lock_held_at_start)\r
-\r
- for i in range(LOOPS):\r
- imp.acquire_lock()\r
- self.verify_lock_state(True)\r
-\r
- for i in range(LOOPS):\r
- imp.release_lock()\r
-\r
- # The original state should be restored now.\r
- self.verify_lock_state(lock_held_at_start)\r
-\r
- if not lock_held_at_start:\r
- try:\r
- imp.release_lock()\r
- except RuntimeError:\r
- pass\r
- else:\r
- self.fail("release_lock() without lock should raise "\r
- "RuntimeError")\r
-\r
-class ReloadTests(unittest.TestCase):\r
-\r
- """Very basic tests to make sure that imp.reload() operates just like\r
- reload()."""\r
-\r
- def test_source(self):\r
- # XXX (ncoghlan): It would be nice to use test_support.CleanImport\r
- # here, but that breaks because the os module registers some\r
- # handlers in copy_reg on import. Since CleanImport doesn't\r
- # revert that registration, the module is left in a broken\r
- # state after reversion. Reinitialising the module contents\r
- # and just reverting os.environ to its previous state is an OK\r
- # workaround\r
- with test_support.EnvironmentVarGuard():\r
- import os\r
- imp.reload(os)\r
-\r
- def test_extension(self):\r
- with test_support.CleanImport('time'):\r
- import time\r
- imp.reload(time)\r
-\r
- def test_builtin(self):\r
- with test_support.CleanImport('marshal'):\r
- import marshal\r
- imp.reload(marshal)\r
-\r
-\r
-def test_main():\r
- tests = [\r
- ReloadTests,\r
- ]\r
- try:\r
- import thread\r
- except ImportError:\r
- pass\r
- else:\r
- tests.append(LockTests)\r
- test_support.run_unittest(*tests)\r
-\r
-if __name__ == "__main__":\r
- test_main()\r