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