def test_get_nowait_with_putter(self): q = Queue(maxsize=2) d = q.put('first') self.assertTrue(d.done()) d = q.put('second') self.assertTrue(d.done()) d = q.put('third') self.assertFalse(d.done()) d2 = q.put('fourth') self.assertFalse(d2.done()) # We have a putter waiting for a free slot self.assertEqual(q.get_nowait(), 'first') self.assertTrue(d.done()) self.assertFalse(d2.done()) self.assertEqual(q.get_nowait(), 'second') self.assertTrue(d2.done()) self.assertEqual(q.get_nowait(), 'third') self.assertEqual(q.get_nowait(), 'fourth')
def test_get_nowait(self): q = Queue() self.assertRaises(Empty, q.get_nowait) self.assertRaises(Empty, q.get, wait=False) r = q.put('ciao') self.assertIsInstance(r, Deferred) self.assertTrue(r.done()) self.assertEqual(r.result, None) self.assertEqual(q.get_nowait(), 'ciao') self.assertRaises(Empty, q.get_nowait)