Commit c5393c64 authored by Benjamin Peterson's avatar Benjamin Peterson

make test_mutex more elegant

parent a2a89a87
...@@ -5,26 +5,28 @@ mutex = test.test_support.import_module("mutex", deprecated=True) ...@@ -5,26 +5,28 @@ mutex = test.test_support.import_module("mutex", deprecated=True)
class MutexTest(unittest.TestCase): class MutexTest(unittest.TestCase):
def setUp(self): def test_lock_and_unlock(self):
self.mutex = mutex.mutex()
def called_by_mutex(self, some_data): def called_by_mutex(some_data):
self.assert_(self.mutex.test(), "mutex not held") self.assertEqual(some_data, "spam")
self.assert_(m.test(), "mutex not held")
# Nested locking # Nested locking
self.mutex.lock(self.called_by_mutex2, "eggs") m.lock(called_by_mutex2, "eggs")
def called_by_mutex2(self, some_data): def called_by_mutex2(some_data):
self.assert_(self.ready_for_2, self.assertEquals(some_data, "eggs")
self.assert_(m.test(), "mutex not held")
self.assert_(ready_for_2,
"called_by_mutex2 called too soon") "called_by_mutex2 called too soon")
def test_lock_and_unlock(self): m = mutex.mutex()
self.read_for_2 = False read_for_2 = False
self.mutex.lock(self.called_by_mutex, "spam") m.lock(called_by_mutex, "spam")
self.ready_for_2 = True ready_for_2 = True
# unlock both locks # unlock both locks
self.mutex.unlock() m.unlock()
self.mutex.unlock() m.unlock()
self.failIf(self.mutex.test(), "mutex still held") self.failIf(m.test(), "mutex still held")
def test_main(): def test_main():
test.test_support.run_unittest(MutexTest) test.test_support.run_unittest(MutexTest)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment