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_partial_decode_at_eof(self): reader = StreamReader() wrapped = TextIOWrapper(reader, 'utf-8') # \u20ac is the euro sign in case you wondered.. buf = u'20 \u20ac'.encode('utf-8') reader.feed(buf[:-1]) reader.feed_eof() self.assertRaises(UnicodeDecodeError, wrapped.read, 4)
def test_iter_eof(self): reader = StreamReader() reader.feed(b'foo\nbar\n') reader.feed_eof() it = iter(reader) self.assertEqual(six.next(it), b'foo\n') self.assertEqual(six.next(it), b'bar\n') self.assertRaises(StopIteration, six.next, it)
def test_read_eof(self): reader = StreamReader() wrapped = TextIOWrapper(reader, 'utf-8') reader.feed(b'foo') reader.feed_eof() self.assertEqual(wrapped.read(), 'foo')
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_readline_eof(self): reader = StreamReader() reader.feed(b'foo') reader.feed_eof() self.assertEqual(reader.readline(), b'foo') self.assertEqual(reader.readline(), b'')