def test_readlines_wait_error(self): reader = StreamReader() reader.feed(b'foo\n') def write_more(): gruvi.sleep(0.01) reader.feed(b'bar\n') gruvi.sleep(0.01) reader.feed_error(RuntimeError) gruvi.spawn(write_more) self.assertEqual(reader.readlines(), [b'foo\n', b'bar\n']) self.assertRaises(RuntimeError, reader.readlines)
def test_readlines_wait_eof(self): reader = StreamReader() reader.feed(b'foo\n') def write_more(): gruvi.sleep(0.01) reader.feed(b'bar\n') gruvi.sleep(0.01) reader.feed_eof() gruvi.spawn(write_more) self.assertEqual(reader.readlines(), [b'foo\n', b'bar\n']) self.assertEqual(reader.readlines(), [])
def test_readlines_error(self): reader = StreamReader() reader.feed(b'foo\nbar\n') reader.feed_error(RuntimeError) self.assertEqual(reader.readlines(), [b'foo\n', b'bar\n']) self.assertRaises(RuntimeError, reader.readlines)
def test_readlines_eof(self): reader = StreamReader() reader.feed(b'foo\nbar\n') reader.feed_eof() self.assertEqual(reader.readlines(), [b'foo\n', b'bar\n']) self.assertEqual(reader.readlines(), [])
def test_readlines_limit(self): reader = StreamReader() reader.feed(b'foo\nbar\n') self.assertEqual(reader.readlines(4), [b'foo\n', b'bar\n'])