def test_lock(self): green = greenio.getcurrent() lock = greenio.GreenLock() self.assertTrue(lock.acquire()) self.assertEqual(lock.locked(), green) # # create a new greenlet child = greenio.greenlet(self._test_lock) future = child.switch(lock) self.assertIsInstance(future, Future) self.assertEqual(lock.locked(), green) # release the lock lock.release() self.assertTrue(future.done()) self.assertEqual(lock.locked(), green)
def test_lock_error(self): lock = greenio.GreenLock() self.assertFalse(lock.locked()) self.assertRaises(RuntimeError, lock.acquire) self.assertFalse(lock.locked()) self.assertRaises(RuntimeError, lock.release)