def testIterMultipleValues(self): c = Channel() for x in range(10): c.Put(x) c.Close() self.assertSequenceEqual(range(10), [x for x in c])
def testOffThreadWrite(self): c = Channel() def WriteStuff(): c.Put(1) t = Thread(target=WriteStuff) t.start() self.assertEqual(1, c.Get()) c.Close()
def testOffThreadRead(self): c = Channel() r = [] def ReadStuff(): for x in range(3): r.append(c.Get()) t = Thread(target=ReadStuff) t.start() c.Put(1) c.Put(2) c.Put(3) t.join() self.assertSequenceEqual([1, 2, 3], r) c.Close()
def testIter(self): c = Channel() c.Put(1) c.Close() for v in c: self.assertEqual(1, v)
def testNoneIsInvalid(self): with self.assertRaises(ValueError): c = Channel() c.Put(None)
def testGetAfterEOF(self): c = Channel() c.Close() self.assertEqual(None, c.Get()) self.assertEqual(None, c.Get())
def testReadAfterClose(self): c = Channel() c.Close() self.assertEqual(None, c.Get())
def testReadWrite(self): c = Channel() c.Put(1) self.assertEqual(1, c.Get()) c.Close()