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(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_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(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_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_iter_error(self): reader = StreamReader() reader.feed(b'foo\nbar\n') reader.feed_error(RuntimeError) it = iter(reader) self.assertEqual(six.next(it), b'foo\n') self.assertEqual(six.next(it), b'bar\n') self.assertRaises(RuntimeError, six.next, it)
def test_partial_decode_wait(self): reader = StreamReader() wrapped = TextIOWrapper(reader, 'utf-8') buf = u'20 \u20ac'.encode('utf-8') reader.feed(buf[:-1]) def write_last(): gruvi.sleep(0.01) reader.feed(buf[-1:]) gruvi.spawn(write_last) self.assertEqual(wrapped.read(4), u'20 \u20ac')
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_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_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'')
def test_iter_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) 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_iter_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) it = iter(reader) self.assertEqual(six.next(it), b'foo\n') self.assertEqual(six.next(it), b'bar\n') self.assertRaises(RuntimeError, six.next, it)
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'])
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_simple(self): reader = StreamReader() wrapped = TextIOWrapper(reader, 'utf-8') reader.feed(b'foo') self.assertEqual(wrapped.read(3), 'foo')
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_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_limit(self): reader = StreamReader() reader.feed(b'foobar\n') self.assertEqual(reader.readline(3), b'foo') self.assertEqual(reader.readline(), b'bar\n')