def test_readline(self): f = StringBuffer('aaaa\nbbbb\ncccc\ndddd') assert f.readline() == 'aaaa\n' assert f.readline() == 'bbbb\n' assert f.readline() == 'cccc\n' assert f.readline() == 'dddd' assert f.readline() == ''
def test_read(self): f = StringBuffer('aaaabbbb') assert f.read(4) == 'aaaa' assert f.read(2) == 'bb' assert f.read(2) == 'bb' assert f.read(4) == '' assert f.read(4) == ''
def loads(buf, payload_type): """ Same as load(), but load from a string instead of a file """ f = StringBuffer(buf) obj = load(f, payload_type) if f.tell() != len(buf): remaining = len(buf)-f.tell() raise ValueError("Not all bytes were consumed: %d bytes left" % remaining) return obj
def test_read_and_readline(self): f = StringBuffer(b'aaaa\nbbbb\ncccc\ndddd') assert f.read(2) == b'aa' assert f.readline() == b'aa\n' assert f.readline() == b'bbbb\n' assert f.read(5) == b'cccc\n' assert f.readline() == b'dddd' assert f.readline() == b'' assert f.read(2) == b''
def test_read_all(self): f = StringBuffer(b'aaaabbbb') assert f.read(2) == b'aa' assert f.read() == b'aabbbb' assert f.read() == b''