home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 June / maximum-cd-2011-06.iso / DiscContents / LibO_3.3.1_Win_x86_install_multi.exe / libreoffice1.cab / test_mutex.py < prev    next >
Encoding:
Python Source  |  2011-02-15  |  986 b   |  36 lines

  1. import unittest
  2. import test.test_support
  3.  
  4. mutex = test.test_support.import_module("mutex", deprecated=True)
  5.  
  6. class MutexTest(unittest.TestCase):
  7.  
  8.     def test_lock_and_unlock(self):
  9.  
  10.         def called_by_mutex(some_data):
  11.             self.assertEqual(some_data, "spam")
  12.             self.assert_(m.test(), "mutex not held")
  13.             # Nested locking
  14.             m.lock(called_by_mutex2, "eggs")
  15.  
  16.         def called_by_mutex2(some_data):
  17.             self.assertEquals(some_data, "eggs")
  18.             self.assert_(m.test(), "mutex not held")
  19.             self.assert_(ready_for_2,
  20.                          "called_by_mutex2 called too soon")
  21.  
  22.         m = mutex.mutex()
  23.         read_for_2 = False
  24.         m.lock(called_by_mutex, "spam")
  25.         ready_for_2 = True
  26.         # unlock both locks
  27.         m.unlock()
  28.         m.unlock()
  29.         self.failIf(m.test(), "mutex still held")
  30.  
  31. def test_main():
  32.     test.test_support.run_unittest(MutexTest)
  33.  
  34. if __name__ == "__main__":
  35.     test_main()
  36.