Exemple #1
0
 def test_readline(self):
     reader = StreamReader()
     reader.feed(b'foo\n')
     self.assertEqual(reader.readline(), b'foo\n')
     reader.feed(b'bar\nbaz\n')
     self.assertEqual(reader.readline(), b'bar\n')
     self.assertEqual(reader.readline(), b'baz\n')
Exemple #2
0
 def test_readline(self):
     reader = StreamReader()
     reader.feed(b'foo\n')
     self.assertEqual(reader.readline(), b'foo\n')
     reader.feed(b'bar\nbaz\n')
     self.assertEqual(reader.readline(), b'bar\n')
     self.assertEqual(reader.readline(), b'baz\n')
Exemple #3
0
 def test_readline_incr(self):
     reader = StreamReader()
     buf = b'foo\nbar\n'
     for i in range(len(buf)):
         reader.feed(buf[i:i+1])
     self.assertEqual(reader.readline(), b'foo\n')
     self.assertEqual(reader.readline(), b'bar\n')
Exemple #4
0
 def test_readline_incr(self):
     reader = StreamReader()
     buf = b'foo\nbar\n'
     for i in range(len(buf)):
         reader.feed(buf[i:i + 1])
     self.assertEqual(reader.readline(), b'foo\n')
     self.assertEqual(reader.readline(), b'bar\n')
Exemple #5
0
 def test_readline_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.readline(), b'foobar')
     self.assertRaises(RuntimeError, reader.readline)
Exemple #6
0
 def test_readline_wait_eof(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.readline(), b'foobar')
     self.assertEqual(reader.readline(), b'')
Exemple #7
0
    def test_readline_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.readline(), b'foobar')
        self.assertRaises(RuntimeError, reader.readline)
Exemple #8
0
    def test_readline_wait_eof(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.readline(), b'foobar')
        self.assertEqual(reader.readline(), b'')
Exemple #9
0
 def test_readline_error(self):
     reader = StreamReader()
     reader.feed(b'foo')
     reader.feed_error(RuntimeError)
     self.assertEqual(reader.readline(), b'foo')
     self.assertRaises(RuntimeError, reader.readline)
Exemple #10
0
 def test_readline_eof(self):
     reader = StreamReader()
     reader.feed(b'foo')
     reader.feed_eof()
     self.assertEqual(reader.readline(), b'foo')
     self.assertEqual(reader.readline(), b'')
Exemple #11
0
 def test_readline_limit(self):
     reader = StreamReader()
     reader.feed(b'foobar\n')
     self.assertEqual(reader.readline(3), b'foo')
     self.assertEqual(reader.readline(), b'bar\n')
Exemple #12
0
 def test_readline_error(self):
     reader = StreamReader()
     reader.feed(b'foo')
     reader.feed_error(RuntimeError)
     self.assertEqual(reader.readline(), b'foo')
     self.assertRaises(RuntimeError, reader.readline)
Exemple #13
0
 def test_readline_eof(self):
     reader = StreamReader()
     reader.feed(b'foo')
     reader.feed_eof()
     self.assertEqual(reader.readline(), b'foo')
     self.assertEqual(reader.readline(), b'')
Exemple #14
0
 def test_readline_limit(self):
     reader = StreamReader()
     reader.feed(b'foobar\n')
     self.assertEqual(reader.readline(3), b'foo')
     self.assertEqual(reader.readline(), b'bar\n')