bpo-36688: Adding an implementation of RLock in _dummy_thread (GH-12943)

(cherry picked from commit c5905f39bc)

Co-authored-by: Joost Lek <vlabakje@gmail.com>
This commit is contained in:
Miss Islington (bot) 2019-06-17 01:34:27 -07:00 committed by GitHub
parent e784f9f1c3
commit ad505918a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 1 deletions

View file

@ -102,6 +102,24 @@ class LockTests(unittest.TestCase):
self.assertIn("unlocked", repr(self.lock))
class RLockTests(unittest.TestCase):
"""Test dummy RLock objects."""
def setUp(self):
self.rlock = _thread.RLock()
def test_multiple_acquire(self):
self.assertIn("unlocked", repr(self.rlock))
self.rlock.acquire()
self.rlock.acquire()
self.assertIn("locked", repr(self.rlock))
self.rlock.release()
self.assertIn("locked", repr(self.rlock))
self.rlock.release()
self.assertIn("unlocked", repr(self.rlock))
self.assertRaises(RuntimeError, self.rlock.release)
class MiscTests(unittest.TestCase):
"""Miscellaneous tests."""
@ -253,3 +271,6 @@ class ThreadTests(unittest.TestCase):
func = mock.Mock(side_effect=Exception)
_thread.start_new_thread(func, tuple())
self.assertTrue(mock_print_exc.called)
if __name__ == '__main__':
unittest.main()