[pypy-commit] pypy py3k: Fix tests in the _io module
amauryfa
noreply at buildbot.pypy.org
Wed Oct 19 23:11:17 CEST 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r48242:74214095bb4a
Date: 2011-10-19 22:31 +0200
http://bitbucket.org/pypy/pypy/changeset/74214095bb4a/
Log: Fix tests in the _io module
diff --git a/pypy/module/_io/interp_bufferedio.py b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -50,7 +50,7 @@
if not space.isinstance_w(w_data, space.w_str):
raise OperationError(space.w_TypeError, space.wrap(
"read() should return bytes"))
- data = space.str_w(w_data)
+ data = space.bytes_w(w_data)
rwbuffer.setslice(0, data)
return space.wrap(len(data))
@@ -468,7 +468,7 @@
if current_size == 0:
return w_data
break
- data = space.str_w(w_data)
+ data = space.bytes_w(w_data)
size = len(data)
if size == 0:
break
diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py
--- a/pypy/module/_io/interp_bytesio.py
+++ b/pypy/module/_io/interp_bytesio.py
@@ -50,7 +50,7 @@
output = buffer2string(self.buf, self.pos, self.pos + size)
self.pos += size
- return space.wrap(output)
+ return space.wrapbytes(output)
def read1_w(self, space, w_size):
return self.read_w(space, w_size)
@@ -125,7 +125,7 @@
def getvalue_w(self, space):
self._check_closed(space)
- return space.wrap(buffer2string(self.buf, 0, self.string_size))
+ return space.wrapbytes(buffer2string(self.buf, 0, self.string_size))
def tell_w(self, space):
self._check_closed(space)
@@ -176,7 +176,7 @@
def getstate_w(self, space):
self._check_closed(space)
- w_content = space.wrap(buffer2string(self.buf, 0, self.string_size))
+ w_content = space.wrapbytes(buffer2string(self.buf, 0, self.string_size))
return space.newtuple([
w_content,
space.wrap(self.pos),
diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -391,7 +391,7 @@
break
builder.append(chunk)
total += len(chunk)
- return space.wrap(builder.build())
+ return space.wrapbytes(builder.build())
if sys.platform == "win32":
def _truncate(self, size):
diff --git a/pypy/module/_io/interp_iobase.py b/pypy/module/_io/interp_iobase.py
--- a/pypy/module/_io/interp_iobase.py
+++ b/pypy/module/_io/interp_iobase.py
@@ -275,7 +275,7 @@
if space.is_w(w_length, space.w_None):
return w_length
space.delslice(w_buffer, w_length, space.len(w_buffer))
- return space.str(w_buffer)
+ return space.call_function(space.w_bytes, w_buffer)
def readall_w(self, space):
builder = StringBuilder()
@@ -283,7 +283,7 @@
w_data = space.call_method(self, "read",
space.wrap(DEFAULT_BUFFER_SIZE))
- if not space.isinstance_w(w_data, space.w_str):
+ if not space.isinstance_w(w_data, space.w_bytes):
raise OperationError(space.w_TypeError, space.wrap(
"read() should return bytes"))
data = space.bytes_w(w_data)
diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -923,7 +923,7 @@
i = 0
while i < len(input):
w_decoded = space.call_method(self.w_decoder, "decode",
- space.wrap(input[i]))
+ space.wrapbytes(input[i]))
chars_decoded += len(space.unicode_w(w_decoded))
cookie.bytes_to_feed += 1
diff --git a/pypy/module/_io/test/test_bufferedio.py b/pypy/module/_io/test/test_bufferedio.py
--- a/pypy/module/_io/test/test_bufferedio.py
+++ b/pypy/module/_io/test/test_bufferedio.py
@@ -14,24 +14,24 @@
import _io
raw = _io.FileIO(self.tmpfile)
f = _io.BufferedReader(raw)
- assert f.read() == "a\nb\nc"
+ assert f.read() == b"a\nb\nc"
raises(ValueError, f.read, -2)
f.close()
#
raw = _io.FileIO(self.tmpfile)
f = _io.BufferedReader(raw)
r = f.read(4)
- assert r == "a\nb\n"
+ assert r == b"a\nb\n"
f.close()
def test_read_pieces(self):
import _io
raw = _io.FileIO(self.tmpfile)
f = _io.BufferedReader(raw)
- assert f.read(3) == "a\nb"
- assert f.read(3) == "\nc"
- assert f.read(3) == ""
- assert f.read(3) == ""
+ assert f.read(3) == b"a\nb"
+ assert f.read(3) == b"\nc"
+ assert f.read(3) == b""
+ assert f.read(3) == b""
f.close()
def test_slow_provider(self):
@@ -40,16 +40,16 @@
def readable(self):
return True
def readinto(self, buf):
- buf[:3] = "abc"
+ buf[:3] = b"abc"
return 3
bufio = _io.BufferedReader(MockIO())
r = bufio.read(5)
- assert r == "abcab"
+ assert r == b"abcab"
def test_read_past_eof(self):
import _io
class MockIO(_io._IOBase):
- stack = ["abc", "d", "efg"]
+ stack = [b"abc", b"d", b"efg"]
def readable(self):
return True
def readinto(self, buf):
@@ -60,7 +60,7 @@
else:
return 0
bufio = _io.BufferedReader(MockIO())
- assert bufio.read(9000) == "abcdefg"
+ assert bufio.read(9000) == b"abcdefg"
def test_buffering(self):
import _io
@@ -102,10 +102,10 @@
import _io
raw = _io.FileIO(self.tmpfile)
f = _io.BufferedReader(raw)
- assert f.read(2) == 'a\n'
- assert f.peek().startswith('b\nc')
- assert f.read(3) == 'b\nc'
- assert f.peek() == ''
+ assert f.read(2) == b'a\n'
+ assert f.peek().startswith(b'b\nc')
+ assert f.read(3) == b'b\nc'
+ assert f.peek() == b''
def test_read1(self):
import _io
@@ -119,42 +119,42 @@
raw = RecordingFileIO(self.tmpfile)
raw.nbreads = 0
f = _io.BufferedReader(raw, buffer_size=3)
- assert f.read(1) == 'a'
- assert f.read1(1) == '\n'
+ assert f.read(1) == b'a'
+ assert f.read1(1) == b'\n'
assert raw.nbreads == 1
- assert f.read1(100) == 'b'
+ assert f.read1(100) == b'b'
assert raw.nbreads == 1
- assert f.read1(100) == '\nc'
+ assert f.read1(100) == b'\nc'
assert raw.nbreads == 2
- assert f.read1(100) == ''
+ assert f.read1(100) == b''
assert raw.nbreads == 3
f.close()
def test_readinto(self):
import _io
- a = bytearray('x' * 10)
+ a = bytearray(b'x' * 10)
raw = _io.FileIO(self.tmpfile)
f = _io.BufferedReader(raw)
assert f.readinto(a) == 5
f.close()
- assert a == 'a\nb\ncxxxxx'
+ assert a == b'a\nb\ncxxxxx'
def test_seek(self):
import _io
raw = _io.FileIO(self.tmpfile)
f = _io.BufferedReader(raw)
- assert f.read() == "a\nb\nc"
+ assert f.read() == b"a\nb\nc"
f.seek(0)
- assert f.read() == "a\nb\nc"
+ assert f.read() == b"a\nb\nc"
f.seek(-2, 2)
- assert f.read() == "\nc"
+ assert f.read() == b"\nc"
f.close()
def test_readlines(self):
import _io
raw = _io.FileIO(self.tmpfile)
f = _io.BufferedReader(raw)
- assert f.readlines() == ['a\n', 'b\n', 'c']
+ assert f.readlines() == [b'a\n', b'b\n', b'c']
def test_detach(self):
import _io
@@ -204,24 +204,24 @@
cls.w_readfile = tmpfile.read
else:
def readfile(space):
- return space.wrap(tmpfile.read())
+ return space.wrapbytes(tmpfile.read())
cls.w_readfile = cls.space.wrap(interp2app(readfile))
def test_write(self):
import _io
raw = _io.FileIO(self.tmpfile, 'w')
f = _io.BufferedWriter(raw)
- f.write("abcd")
+ f.write(b"abcd")
f.close()
- assert self.readfile() == "abcd"
+ assert self.readfile() == b"abcd"
def test_largewrite(self):
import _io
raw = _io.FileIO(self.tmpfile, 'w')
f = _io.BufferedWriter(raw)
- f.write("abcd" * 5000)
+ f.write(b"abcd" * 5000)
f.close()
- assert self.readfile() == "abcd" * 5000
+ assert self.readfile() == b"abcd" * 5000
def test_incomplete(self):
import _io
@@ -249,9 +249,9 @@
b = _io.BufferedWriter(raw, 13)
for i in range(4):
- assert b.write('x' * 10) == 10
+ assert b.write(b'x' * 10) == 10
b.flush()
- assert self.readfile() == 'x' * 40
+ assert self.readfile() == b'x' * 40
def test_destructor(self):
import _io
@@ -275,7 +275,7 @@
def test_truncate(self):
import _io
raw = _io.FileIO(self.tmpfile, 'w+')
- raw.write('x' * 20)
+ raw.write(b'x' * 20)
b = _io.BufferedReader(raw)
assert b.seek(8) == 8
assert b.truncate() == 8
@@ -293,7 +293,7 @@
closed = False
def pop_written(self):
- s = ''.join(self._write_stack)
+ s = b''.join(self._write_stack)
self._write_stack[:] = []
return s
@@ -322,11 +322,11 @@
raw = MockNonBlockWriterIO()
bufio = _io.BufferedWriter(raw, 8)
- assert bufio.write("abcd") == 4
- assert bufio.write("efghi") == 5
+ assert bufio.write(b"abcd") == 4
+ assert bufio.write(b"efghi") == 5
# 1 byte will be written, the rest will be buffered
raw.block_on(b"k")
- assert bufio.write("jklmn") == 5
+ assert bufio.write(b"jklmn") == 5
# 8 bytes will be written, 8 will be buffered and the rest will be lost
raw.block_on(b"0")
@@ -337,12 +337,12 @@
else:
self.fail("BlockingIOError should have been raised")
assert written == 16
- assert raw.pop_written() == "abcdefghijklmnopqrwxyz"
+ assert raw.pop_written() == b"abcdefghijklmnopqrwxyz"
- assert bufio.write("ABCDEFGHI") == 9
+ assert bufio.write(b"ABCDEFGHI") == 9
s = raw.pop_written()
# Previously buffered bytes were flushed
- assert s.startswith("01234567A")
+ assert s.startswith(b"01234567A")
def test_read_non_blocking(self):
import _io
@@ -374,28 +374,28 @@
try:
return self._read_stack.pop(0)
except IndexError:
- return ""
+ return b""
# Inject some None's in there to simulate EWOULDBLOCK
rawio = MockRawIO((b"abc", b"d", None, b"efg", None, None, None))
bufio = _io.BufferedReader(rawio)
- assert bufio.read(6) == "abcd"
- assert bufio.read(1) == "e"
- assert bufio.read() == "fg"
- assert bufio.peek(1) == ""
+ assert bufio.read(6) == b"abcd"
+ assert bufio.read(1) == b"e"
+ assert bufio.read() == b"fg"
+ assert bufio.peek(1) == b""
assert bufio.read() is None
- assert bufio.read() == ""
+ assert bufio.read() == b""
class AppTestBufferedRWPair:
def test_pair(self):
import _io
- pair = _io.BufferedRWPair(_io.BytesIO("abc"), _io.BytesIO())
+ pair = _io.BufferedRWPair(_io.BytesIO(b"abc"), _io.BytesIO())
assert not pair.closed
assert pair.readable()
assert pair.writable()
assert not pair.isatty()
- assert pair.read() == "abc"
- assert pair.write("abc") == 3
+ assert pair.read() == b"abc"
+ assert pair.write(b"abc") == 3
def test_constructor_with_not_readable(self):
import _io
@@ -417,14 +417,14 @@
def setup_class(cls):
cls.space = gettestobjspace(usemodules=['_io'])
tmpfile = udir.join('tmpfile')
- tmpfile.write("a\nb\nc", mode='wb')
+ tmpfile.write(b"a\nb\nc", mode='wb')
cls.w_tmpfile = cls.space.wrap(str(tmpfile))
def test_simple_read(self):
import _io
raw = _io.FileIO(self.tmpfile, 'rb+')
f = _io.BufferedRandom(raw)
- assert f.read(3) == 'a\nb'
- f.write('xxxx')
+ assert f.read(3) == b'a\nb'
+ f.write(b'xxxx')
f.seek(0)
- assert f.read() == 'a\nbxxxx'
+ assert f.read() == b'a\nbxxxx'
diff --git a/pypy/module/_io/test/test_bytesio.py b/pypy/module/_io/test/test_bytesio.py
--- a/pypy/module/_io/test/test_bytesio.py
+++ b/pypy/module/_io/test/test_bytesio.py
@@ -11,7 +11,7 @@
def test_init_kwargs(self):
import _io
- buf = "1234567890"
+ buf = b"1234567890"
b = _io.BytesIO(initial_bytes=buf)
assert b.read() == buf
raises(TypeError, _io.BytesIO, buf, foo=None)
@@ -27,22 +27,22 @@
def test_write(self):
import _io
f = _io.BytesIO()
- assert f.write("hello") == 5
+ assert f.write(b"hello") == 5
import gc; gc.collect()
- assert f.getvalue() == "hello"
+ assert f.getvalue() == b"hello"
f.close()
def test_read(self):
import _io
- f = _io.BytesIO("hello")
- assert f.read() == "hello"
+ f = _io.BytesIO(b"hello")
+ assert f.read() == b"hello"
import gc; gc.collect()
- assert f.read(8192) == ""
+ assert f.read(8192) == b""
f.close()
def test_seek(self):
import _io
- f = _io.BytesIO("hello")
+ f = _io.BytesIO(b"hello")
assert f.tell() == 0
assert f.seek(-1, 2) == 4
assert f.tell() == 4
@@ -50,24 +50,24 @@
def test_truncate(self):
import _io
- f = _io.BytesIO("hello")
+ f = _io.BytesIO(b"hello")
f.seek(3)
assert f.truncate() == 3
- assert f.getvalue() == "hel"
+ assert f.getvalue() == b"hel"
def test_setstate(self):
# state is (content, position, __dict__)
import _io
- f = _io.BytesIO("hello")
+ f = _io.BytesIO(b"hello")
content, pos, __dict__ = f.__getstate__()
- assert (content, pos) == ("hello", 0)
+ assert (content, pos) == (b"hello", 0)
assert __dict__ is None or __dict__ == {}
- f.__setstate__(("world", 3, {"a": 1}))
- assert f.getvalue() == "world"
- assert f.read() == "ld"
+ f.__setstate__((b"world", 3, {"a": 1}))
+ assert f.getvalue() == b"world"
+ assert f.read() == b"ld"
assert f.a == 1
- assert f.__getstate__() == ("world", 5, {"a": 1})
- raises(TypeError, f.__setstate__, ("", 0))
+ assert f.__getstate__() == (b"world", 5, {"a": 1})
+ raises(TypeError, f.__setstate__, (b"", 0))
f.close()
raises(ValueError, f.__getstate__)
raises(ValueError, f.__setstate__, ("world", 3, {"a": 1}))
@@ -75,6 +75,6 @@
def test_readinto(self):
import _io
- b = _io.BytesIO("hello")
+ b = _io.BytesIO(b"hello")
b.close()
- raises(ValueError, b.readinto, bytearray("hello"))
+ raises(ValueError, b.readinto, bytearray(b"hello"))
diff --git a/pypy/module/_io/test/test_fileio.py b/pypy/module/_io/test/test_fileio.py
--- a/pypy/module/_io/test/test_fileio.py
+++ b/pypy/module/_io/test/test_fileio.py
@@ -46,34 +46,34 @@
def test_readline(self):
import _io
f = _io.FileIO(self.tmpfile, 'rb')
- assert f.readline() == 'a\n'
- assert f.readline() == 'b\n'
- assert f.readline() == 'c'
- assert f.readline() == ''
+ assert f.readline() == b'a\n'
+ assert f.readline() == b'b\n'
+ assert f.readline() == b'c'
+ assert f.readline() == b''
f.close()
def test_readlines(self):
import _io
f = _io.FileIO(self.tmpfile, 'rb')
- assert f.readlines() == ["a\n", "b\n", "c"]
+ assert f.readlines() == [b"a\n", b"b\n", b"c"]
f.seek(0)
- assert f.readlines(3) == ["a\n", "b\n"]
+ assert f.readlines(3) == [b"a\n", b"b\n"]
f.close()
def test_readall(self):
import _io
f = _io.FileIO(self.tmpfile, 'rb')
- assert f.readall() == "a\nb\nc"
+ assert f.readall() == b"a\nb\nc"
f.close()
def test_write(self):
import _io
filename = self.tmpfile + '_w'
f = _io.FileIO(filename, 'wb')
- f.write("test")
+ f.write(b"test")
# try without flushing
f2 = _io.FileIO(filename, 'rb')
- assert f2.read() == "test"
+ assert f2.read() == b"test"
f.close()
f2.close()
@@ -81,9 +81,9 @@
import _io
filename = self.tmpfile + '_w'
f = _io.FileIO(filename, 'wb')
- f.writelines(["line1\n", "line2", "line3"])
+ f.writelines([b"line1\n", b"line2", b"line3"])
f2 = _io.FileIO(filename, 'rb')
- assert f2.read() == "line1\nline2line3"
+ assert f2.read() == b"line1\nline2line3"
f.close()
f2.close()
@@ -120,18 +120,18 @@
def test_readinto(self):
import _io
- a = bytearray('x' * 10)
+ a = bytearray(b'x' * 10)
f = _io.FileIO(self.tmpfile, 'r+')
assert f.readinto(a) == 10
f.close()
- assert a == 'a\nb\nc\0\0\0\0\0'
+ assert a == b'a\nb\nc\0\0\0\0\0'
#
- a = bytearray('x' * 10)
+ a = bytearray(b'x' * 10)
f = _io.FileIO(self.tmpfile, 'r+')
f.truncate(3)
assert f.readinto(a) == 3
f.close()
- assert a == 'a\nbxxxxxxx'
+ assert a == b'a\nbxxxxxxx'
def test_repr(self):
import _io
diff --git a/pypy/module/_io/test/test_io.py b/pypy/module/_io/test/test_io.py
--- a/pypy/module/_io/test/test_io.py
+++ b/pypy/module/_io/test/test_io.py
@@ -69,9 +69,9 @@
return _io.BytesIO.write(f, data)
f.write = write
bufio = _io.BufferedWriter(f)
- bufio.write("abc")
+ bufio.write(b"abc")
bufio.flush()
- assert f.getvalue() == "ABC"
+ assert f.getvalue() == b"ABC"
def test_destructor(self):
import io
@@ -109,17 +109,17 @@
def test_rawio_read(self):
import _io
class MockRawIO(_io._RawIOBase):
- stack = ['abc', 'de', '']
+ stack = [b'abc', b'de', b'']
def readinto(self, buf):
data = self.stack.pop(0)
buf[:len(data)] = data
return len(data)
- assert MockRawIO().read() == 'abcde'
+ assert MockRawIO().read() == b'abcde'
def test_rawio_read_pieces(self):
import _io
class MockRawIO(_io._RawIOBase):
- stack = ['abc', 'de', None, 'fg', '']
+ stack = [b'abc', b'de', None, b'fg', b'']
def readinto(self, buf):
data = self.stack.pop(0)
if data is None:
@@ -132,12 +132,12 @@
self.stack.insert(0, data[len(buf):])
return len(buf)
r = MockRawIO()
- assert r.read(2) == 'ab'
- assert r.read(2) == 'c'
- assert r.read(2) == 'de'
+ assert r.read(2) == b'ab'
+ assert r.read(2) == b'c'
+ assert r.read(2) == b'de'
assert r.read(2) == None
- assert r.read(2) == 'fg'
- assert r.read(2) == ''
+ assert r.read(2) == b'fg'
+ assert r.read(2) == b''
class AppTestOpen:
def setup_class(cls):
@@ -169,7 +169,7 @@
def test_array_write(self):
import _io, array
- a = array.array(b'i', range(10))
+ a = array.array('i', range(10))
n = len(a.tostring())
with _io.open(self.tmpfile, "wb", 0) as f:
res = f.write(a)
@@ -208,13 +208,13 @@
import _io
with _io.open(self.tmpfile, "wb") as f:
- f.write("abcd")
+ f.write(b"abcd")
with _io.open(self.tmpfile) as f:
decoded = f.read()
# seek positions
- for i in xrange(len(decoded) + 1):
+ for i in range(len(decoded) + 1):
# read lenghts
for j in [1, 5, len(decoded) - i]:
with _io.open(self.tmpfile) as f:
@@ -306,7 +306,7 @@
assert f.newlines is None
with _io.open(self.tmpfile, "wb") as f:
- f.write("hello\nworld\n")
+ f.write(b"hello\nworld\n")
with _io.open(self.tmpfile, "r") as f:
res = f.readline()
@@ -314,4 +314,4 @@
res = f.readline()
assert res == "world\n"
assert f.newlines == "\n"
- assert type(f.newlines) is unicode
+ assert type(f.newlines) is str
diff --git a/pypy/module/_io/test/test_stringio.py b/pypy/module/_io/test/test_stringio.py
--- a/pypy/module/_io/test/test_stringio.py
+++ b/pypy/module/_io/test/test_stringio.py
@@ -248,7 +248,7 @@
assert iter(sio) is sio
assert hasattr(sio, "__iter__")
- assert hasattr(sio, "next")
+ assert hasattr(sio, "__next__")
i = 0
for line in sio:
@@ -271,7 +271,7 @@
sio = io.StringIO()
state = sio.__getstate__()
assert len(state) == 4
- assert isinstance(state[0], unicode)
+ assert isinstance(state[0], str)
assert isinstance(state[1], str)
assert isinstance(state[2], int)
assert isinstance(state[3], dict)
@@ -286,7 +286,7 @@
sio.__setstate__((u"no error", u"", 0, {"spam": 3}))
raises(ValueError, sio.__setstate__, (u"", u"f", 0, None))
raises(ValueError, sio.__setstate__, (u"", u"", -1, None))
- raises(TypeError, sio.__setstate__, ("", u"", 0, None))
+ raises(TypeError, sio.__setstate__, (b"", u"", 0, None))
raises(TypeError, sio.__setstate__, (u"", u"", 0.0, None))
raises(TypeError, sio.__setstate__, (u"", u"", 0, 0))
raises(TypeError, sio.__setstate__, (u"len-test", 0))
diff --git a/pypy/module/_io/test/test_textio.py b/pypy/module/_io/test/test_textio.py
--- a/pypy/module/_io/test/test_textio.py
+++ b/pypy/module/_io/test/test_textio.py
@@ -71,7 +71,7 @@
def test_read_some_then_all(self):
import _io
- r = _io.BytesIO("abc\ndef\n")
+ r = _io.BytesIO(b"abc\ndef\n")
t = _io.TextIOWrapper(r)
reads = t.read(4)
reads += t.read()
@@ -79,7 +79,7 @@
def test_read_some_then_readline(self):
import _io
- r = _io.BytesIO("abc\ndef\n")
+ r = _io.BytesIO(b"abc\ndef\n")
t = _io.TextIOWrapper(r)
reads = t.read(4)
reads += t.readline()
@@ -108,7 +108,7 @@
def test_tell(self):
import _io
- r = _io.BytesIO("abc\ndef\n")
+ r = _io.BytesIO(b"abc\ndef\n")
t = _io.TextIOWrapper(r)
assert t.tell() == 0
t.read(4)
@@ -126,7 +126,7 @@
t.write(u"abc")
del t
import gc; gc.collect()
- assert l == ["abc"]
+ assert l == [b"abc"]
def test_newlines(self):
import _io
@@ -169,8 +169,8 @@
def test_readline(self):
import _io
- s = "AAA\r\nBBB\rCCC\r\nDDD\nEEE\r\n"
- r = "AAA\nBBB\nCCC\nDDD\nEEE\n".decode("ascii")
+ s = b"AAA\r\nBBB\rCCC\r\nDDD\nEEE\r\n"
+ r = "AAA\nBBB\nCCC\nDDD\nEEE\n"
txt = _io.TextIOWrapper(_io.BytesIO(s), encoding="ascii")
txt._CHUNK_SIZE = 4
@@ -184,20 +184,20 @@
def test_name(self):
import _io
- t = _io.TextIOWrapper(_io.BytesIO(""))
+ t = _io.TextIOWrapper(_io.BytesIO(b""))
# CPython raises an AttributeError, we raise a TypeError.
raises((AttributeError, TypeError), setattr, t, "name", "anything")
def test_repr(self):
import _io
- t = _io.TextIOWrapper(_io.BytesIO(""), encoding="utf-8")
+ t = _io.TextIOWrapper(_io.BytesIO(b""), encoding="utf-8")
assert repr(t) == "<_io.TextIOWrapper encoding='utf-8'>"
- t = _io.TextIOWrapper(_io.BytesIO(""), encoding="ascii")
+ t = _io.TextIOWrapper(_io.BytesIO(b""), encoding="ascii")
assert repr(t) == "<_io.TextIOWrapper encoding='ascii'>"
- t = _io.TextIOWrapper(_io.BytesIO(""), encoding=u"utf-8")
+ t = _io.TextIOWrapper(_io.BytesIO(b""), encoding=u"utf-8")
assert repr(t) == "<_io.TextIOWrapper encoding='utf-8'>"
- b = _io.BytesIO("")
+ b = _io.BytesIO(b"")
t = _io.TextIOWrapper(b, encoding="utf-8")
b.name = "dummy"
assert repr(t) == "<_io.TextIOWrapper name='dummy' encoding='utf-8'>"
@@ -256,7 +256,7 @@
def _decode_bytewise(s):
# Decode one byte at a time
for b in encoder.encode(s):
- result.append(decoder.decode(b))
+ result.append(decoder.decode(bytes([b])))
else:
encoder = None
def _decode_bytewise(s):
More information about the pypy-commit
mailing list