Ejemplo n.º 1
0
 def test_read(self):
     reader = StreamReader()
     reader.feed(b'foo')
     self.assertEqual(reader.read(3), b'foo')
     reader.feed(b'foo bar')
     self.assertEqual(reader.read(3), b'foo')
     self.assertEqual(reader.read(4), b' bar')
Ejemplo n.º 2
0
 def test_read(self):
     reader = StreamReader()
     reader.feed(b'foo')
     self.assertEqual(reader.read(3), b'foo')
     reader.feed(b'foo bar')
     self.assertEqual(reader.read(3), b'foo')
     self.assertEqual(reader.read(4), b' bar')
Ejemplo n.º 3
0
 def test_read_eof(self):
     reader = StreamReader()
     reader.feed(b'foo')
     reader.feed_eof()
     self.assertEqual(reader.read(), b'foo')
     self.assertEqual(reader.read(), b'')
     reader.feed_error(RuntimeError)
Ejemplo n.º 4
0
 def test_read_incr(self):
     reader = StreamReader()
     buf = b'foobar'
     for i in range(len(buf)):
         reader.feed(buf[i:i+1])
     reader.feed_eof()
     self.assertEqual(reader.read(), b'foobar')
Ejemplo n.º 5
0
 def test_read_eof(self):
     reader = StreamReader()
     reader.feed(b'foo')
     reader.feed_eof()
     self.assertEqual(reader.read(), b'foo')
     self.assertEqual(reader.read(), b'')
     reader.feed_error(RuntimeError)
Ejemplo n.º 6
0
 def test_read_incr(self):
     reader = StreamReader()
     buf = b'foobar'
     for i in range(len(buf)):
         reader.feed(buf[i:i + 1])
     reader.feed_eof()
     self.assertEqual(reader.read(), b'foobar')
Ejemplo n.º 7
0
 def test_read_wait_error(self):
     reader = StreamReader()
     reader.feed(b'foo')
     def write_more():
         gruvi.sleep(0.01)
         reader.feed(b'bar')
         gruvi.sleep(0.01)
         reader.feed_error(RuntimeError)
     gruvi.spawn(write_more)
     self.assertEqual(reader.read(), b'foobar')
     self.assertRaises(RuntimeError, reader.read)
Ejemplo n.º 8
0
 def test_read_wait(self):
     reader = StreamReader()
     reader.feed(b'foo')
     def write_more():
         gruvi.sleep(0.01)
         reader.feed(b'bar')
         gruvi.sleep(0.01)
         reader.feed_eof()
     gruvi.spawn(write_more)
     self.assertEqual(reader.read(), b'foobar')
     self.assertEqual(reader.read(), b'')
Ejemplo n.º 9
0
    def test_read_wait_error(self):
        reader = StreamReader()
        reader.feed(b'foo')

        def write_more():
            gruvi.sleep(0.01)
            reader.feed(b'bar')
            gruvi.sleep(0.01)
            reader.feed_error(RuntimeError)

        gruvi.spawn(write_more)
        self.assertEqual(reader.read(), b'foobar')
        self.assertRaises(RuntimeError, reader.read)
Ejemplo n.º 10
0
    def test_read_wait(self):
        reader = StreamReader()
        reader.feed(b'foo')

        def write_more():
            gruvi.sleep(0.01)
            reader.feed(b'bar')
            gruvi.sleep(0.01)
            reader.feed_eof()

        gruvi.spawn(write_more)
        self.assertEqual(reader.read(), b'foobar')
        self.assertEqual(reader.read(), b'')