home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 June / PCWorld_2005-06_cd.bin / software / vyzkuste / firewally / firewally.exe / framework-2.3.exe / test_imp.py < prev    next >
Text File  |  2003-12-30  |  983b  |  40 lines

  1. import imp
  2. from test.test_support import TestFailed
  3.  
  4. def verify_lock_state(expected):
  5.     if imp.lock_held() != expected:
  6.         raise TestFailed("expected imp.lock_held() to be %r" % expected)
  7.  
  8. def testLock():
  9.     LOOPS = 50
  10.  
  11.     # The import lock may already be held, e.g. if the test suite is run
  12.     # via "import test.autotest".
  13.     lock_held_at_start = imp.lock_held()
  14.     verify_lock_state(lock_held_at_start)
  15.  
  16.     for i in range(LOOPS):
  17.         imp.acquire_lock()
  18.         verify_lock_state(True)
  19.  
  20.     for i in range(LOOPS):
  21.         imp.release_lock()
  22.  
  23.     # The original state should be restored now.
  24.     verify_lock_state(lock_held_at_start)
  25.  
  26.     if not lock_held_at_start:
  27.         try:
  28.             imp.release_lock()
  29.         except RuntimeError:
  30.             pass
  31.         else:
  32.             raise TestFailed("release_lock() without lock should raise "
  33.                              "RuntimeError")
  34.  
  35. def test_main():
  36.     testLock()
  37.  
  38. if __name__ == "__main__":
  39.     test_main()
  40.