Пример #1
0
    def testIterMultipleValues(self):
        c = Channel()
        for x in range(10):
            c.Put(x)
        c.Close()

        self.assertSequenceEqual(range(10), [x for x in c])
Пример #2
0
    def testOffThreadWrite(self):
        c = Channel()

        def WriteStuff():
            c.Put(1)

        t = Thread(target=WriteStuff)
        t.start()

        self.assertEqual(1, c.Get())
        c.Close()
Пример #3
0
    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()
Пример #4
0
 def testIter(self):
     c = Channel()
     c.Put(1)
     c.Close()
     for v in c:
         self.assertEqual(1, v)
Пример #5
0
 def testGetAfterEOF(self):
     c = Channel()
     c.Close()
     self.assertEqual(None, c.Get())
     self.assertEqual(None, c.Get())
Пример #6
0
 def testReadAfterClose(self):
     c = Channel()
     c.Close()
     self.assertEqual(None, c.Get())
Пример #7
0
 def testReadWrite(self):
     c = Channel()
     c.Put(1)
     self.assertEqual(1, c.Get())
     c.Close()