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