move sections
[python/dscho.git] / Lib / test / test_mutex.py
blob2882213394740bbccd161654242bcb250848598e
1 import unittest
2 import test.test_support
4 mutex = test.test_support.import_module("mutex", deprecated=True)
6 class MutexTest(unittest.TestCase):
8 def test_lock_and_unlock(self):
10 def called_by_mutex(some_data):
11 self.assertEqual(some_data, "spam")
12 self.assertTrue(m.test(), "mutex not held")
13 # Nested locking
14 m.lock(called_by_mutex2, "eggs")
16 def called_by_mutex2(some_data):
17 self.assertEquals(some_data, "eggs")
18 self.assertTrue(m.test(), "mutex not held")
19 self.assertTrue(ready_for_2,
20 "called_by_mutex2 called too soon")
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.assertFalse(m.test(), "mutex still held")
31 def test_main():
32 test.test_support.run_unittest(MutexTest)
34 if __name__ == "__main__":
35 test_main()