Esempio n. 1
0
 def test_err(self):
     r = ManualReadable([23])
     e = Exception()
     errs = []
     d = r.read()
     d.addErrback(lambda f: errs.append(f.value))
     yield r.err(e)
     self.assertEqual(errs, [e])
Esempio n. 2
0
    def test_reading(self):
        r = ManualReadable([1, 2, 3, 4])
        self.assertEqual(r.unread, [1, 2, 3, 4])
        self.assertEqual(r.reading, [])

        d1 = r.read()
        self.assertEqual(r.unread, [2, 3, 4])
        self.assertEqual(r.reading, [1])

        d2 = r.read()
        self.assertEqual(r.unread, [3, 4])
        self.assertEqual(r.reading, [1, 2])

        self.assertEqual(d1, r.next())
        self.assertEqual((yield d1), 1)
        self.assertEqual(r.unread, [3, 4])
        self.assertEqual(r.reading, [2])

        self.assertEqual(d2, r.next())
        self.assertEqual((yield d2), 2)
        self.assertEqual(r.unread, [3, 4])
        self.assertEqual(r.reading, [])

        d = r.read()
        self.assertEqual(r.unread, [4])
        self.assertEqual(r.reading, [3])
        self.assertEqual(d, r.next())
        self.assertEqual((yield d), 3)

        d = r.read()
        self.assertEqual(r.unread, [])
        self.assertEqual(r.reading, [4])
        self.assertEqual(d, r.next())
        self.assertEqual((yield d), 4)

        self.assertEqual((yield r.read()), None)
        self.assertEqual((yield r.read()), None)