Example #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')
Example #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')
Example #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)
Example #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')
Example #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)
Example #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')
Example #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)
Example #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'')
Example #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)
Example #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'')