0001 import imp 0002 from test.test_support import TestFailed 0003 0004 def verify_lock_state(expected): 0005 if imp.lock_held() != expected: 0006 raise TestFailed("expected imp.lock_held() to be %r" % expected) 0007 0008 def testLock(): 0009 LOOPS = 50 0010 0011 # The import lock may already be held, e.g. if the test suite is run 0012 # via "import test.autotest". 0013 lock_held_at_start = imp.lock_held() 0014 verify_lock_state(lock_held_at_start) 0015 0016 for i in range(LOOPS): 0017 imp.acquire_lock() 0018 verify_lock_state(True) 0019 0020 for i in range(LOOPS): 0021 imp.release_lock() 0022 0023 # The original state should be restored now. 0024 verify_lock_state(lock_held_at_start) 0025 0026 if not lock_held_at_start: 0027 try: 0028 imp.release_lock() 0029 except RuntimeError: 0030 pass 0031 else: 0032 raise TestFailed("release_lock() without lock should raise " 0033 "RuntimeError") 0034 0035 def test_main(): 0036 testLock() 0037 0038 if __name__ == "__main__": 0039 test_main() 0040
Generated by PyXR 0.9.4