Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_read_vs_downgrade_read(self) -> None:
"""
# Given: Instance of RWLockReadD.
# When: A reader lock is acquired OR A writer lock is downgraded.
# Then: The internal state should be the same.
"""
# ## Arrange
c_rwlock_1 = rwlock.RWLockReadD()
c_rwlock_2 = rwlock.RWLockReadD()
def assert_internal_state():
self.assertEqual(int(c_rwlock_1.v_read_count), int(c_rwlock_2.v_read_count))
self.assertEqual(bool(c_rwlock_1.c_resource.locked()), bool(c_rwlock_2.c_resource.locked()))
self.assertEqual(bool(c_rwlock_1.c_lock_read_count.locked()), bool(c_rwlock_2.c_lock_read_count.locked()))
# ## Assume
assert_internal_state()
# ## Act
a_read_lock = c_rwlock_1.gen_rlock()
a_read_lock.acquire()
a_downgrade_lock: Union[rwlock.Lockable, rwlock.LockableD] = c_rwlock_2.gen_wlock()
a_downgrade_lock.acquire()
assert isinstance(a_downgrade_lock, rwlock.LockableD)
a_downgrade_lock = a_downgrade_lock.downgrade()
# ## Assert
def test_read_vs_downgrade_read(self) -> None:
"""
# Given: Instance of RWLockReadD.
# When: A reader lock is acquired OR A writer lock is downgraded.
# Then: The internal state should be the same.
"""
# ## Arrange
c_rwlock_1 = rwlock.RWLockReadD()
c_rwlock_2 = rwlock.RWLockReadD()
def assert_internal_state():
self.assertEqual(int(c_rwlock_1.v_read_count), int(c_rwlock_2.v_read_count))
self.assertEqual(bool(c_rwlock_1.c_resource.locked()), bool(c_rwlock_2.c_resource.locked()))
self.assertEqual(bool(c_rwlock_1.c_lock_read_count.locked()), bool(c_rwlock_2.c_lock_read_count.locked()))
# ## Assume
assert_internal_state()
# ## Act
a_read_lock = c_rwlock_1.gen_rlock()
a_read_lock.acquire()
a_downgrade_lock: Union[rwlock.Lockable, rwlock.LockableD] = c_rwlock_2.gen_wlock()
a_downgrade_lock.acquire()
assert isinstance(a_downgrade_lock, rwlock.LockableD)
a_downgrade_lock = a_downgrade_lock.downgrade()