aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/lock_tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/lock_tests.py')
-rw-r--r--Lib/test/lock_tests.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py
index 009e04e9c0b..691029a1a54 100644
--- a/Lib/test/lock_tests.py
+++ b/Lib/test/lock_tests.py
@@ -124,6 +124,11 @@ class BaseLockTests(BaseTestCase):
lock = self.locktype()
del lock
+ def test_constructor_noargs(self):
+ self.assertRaises(TypeError, self.locktype, 1)
+ self.assertRaises(TypeError, self.locktype, x=1)
+ self.assertRaises(TypeError, self.locktype, 1, x=2)
+
def test_repr(self):
lock = self.locktype()
self.assertRegex(repr(lock), "<unlocked .* object (.*)?at .*>")
@@ -332,6 +337,26 @@ class RLockTests(BaseLockTests):
"""
Tests for recursive locks.
"""
+ def test_repr_count(self):
+ # see gh-134322: check that count values are correct:
+ # when a rlock is just created,
+ # in a second thread when rlock is acquired in the main thread.
+ lock = self.locktype()
+ self.assertIn("count=0", repr(lock))
+ self.assertIn("<unlocked", repr(lock))
+ lock.acquire()
+ lock.acquire()
+ self.assertIn("count=2", repr(lock))
+ self.assertIn("<locked", repr(lock))
+
+ result = []
+ def call_repr():
+ result.append(repr(lock))
+ with Bunch(call_repr, 1):
+ pass
+ self.assertIn("count=2", result[0])
+ self.assertIn("<locked", result[0])
+
def test_reacquire(self):
lock = self.locktype()
lock.acquire()
@@ -365,6 +390,24 @@ class RLockTests(BaseLockTests):
lock.release()
self.assertFalse(lock.locked())
+ def test_locked_with_2threads(self):
+ # see gh-134323: check that a rlock which
+ # is acquired in a different thread,
+ # is still locked in the main thread.
+ result = []
+ rlock = self.locktype()
+ self.assertFalse(rlock.locked())
+ def acquire():
+ result.append(rlock.locked())
+ rlock.acquire()
+ result.append(rlock.locked())
+
+ with Bunch(acquire, 1):
+ pass
+ self.assertTrue(rlock.locked())
+ self.assertFalse(result[0])
+ self.assertTrue(result[1])
+
def test_release_save_unacquired(self):
# Cannot _release_save an unacquired lock
lock = self.locktype()