Commits

Amaury Forgeot d'Arc committed 91c9b2c

Fix all tests in the io module.

Comments (0)

Files changed (7)

lib_pypy/_struct.py

     return bytes(res)
 
 def pack_signed_int(number,size,le):
-    if not isinstance(number, (int,long)):
+    if not isinstance(number, int):
         raise StructError("argument for i,I,l,L,q,Q,h,H must be integer")
     if  number > 2**(8*size-1)-1 or number < -1*2**(8*size-1):
         raise OverflowError("Number:%i too large to convert" % number)
     return pack_int(number,size,le)
 
 def pack_unsigned_int(number,size,le):
-    if not isinstance(number, (int,long)):
+    if not isinstance(number, int):
         raise StructError("argument for i,I,l,L,q,Q,h,H must be integer")
     if number < 0:
         raise TypeError("can't convert negative long to unsigned")

lib_pypy/array.py

         if self.typecode != "u":
             raise ValueError("tounicode() may only be called on type 'u' arrays")
         # XXX performance is not too good
-        return u"".join(self.tolist())
+        return "".join(self.tolist())
 
     def byteswap(self):
         """Byteswap all items of the array.  If the items in the array are not

pypy/module/_io/test/test_bytesio.py

 
     def test_init(self):
         import _io
-        raises(TypeError, _io.BytesIO, u"12345")
+        raises(TypeError, _io.BytesIO, "12345")
 
     def test_init_kwargs(self):
         import _io

pypy/module/_io/test/test_fileio.py

     def test_open_fd(self):
         import _io
         os = self.posix
-        fd = os.open(self.tmpfile, os.O_RDONLY, 0666)
+        fd = os.open(self.tmpfile, os.O_RDONLY, 0o666)
         f = _io.FileIO(fd, "rb", closefd=False)
         assert f.fileno() == fd
         assert f.closefd is False

pypy/module/_io/test/test_io.py

         import _io
         try:
             raise _io.BlockingIOError(42, "test blocking", 123)
-        except IOError, e:
+        except IOError as e:
             assert isinstance(e, _io.BlockingIOError)
             assert e.errno == 42
             assert e.strerror == "test blocking"
 
         with _io.open(self.tmpfile, "w+", encoding="utf8") as f:
             p0 = f.tell()
-            f.write(u"\xff\n")
+            f.write("\xff\n")
             p1 = f.tell()
-            f.write(u"\xff\n")
+            f.write("\xff\n")
             p2 = f.tell()
             f.seek(0)
 
             assert f.tell() == p0
             res = f.readline()
-            assert res == u"\xff\n"
+            assert res == "\xff\n"
             assert f.tell() == p1
             res = f.readline()
-            assert res == u"\xff\n"
+            assert res == "\xff\n"
             assert f.tell() == p2
             f.seek(0)
 
             for line in f:
-                assert line == u"\xff\n"
+                assert line == "\xff\n"
                 raises(IOError, f.tell)
             assert f.tell() == p2
 
         import _io
 
         with _io.open(self.tmpfile, "w+") as f:
-            f.write(u"abc")
+            f.write("abc")
 
         with _io.open(self.tmpfile, "w+") as f:
             f.truncate()
         # The BOM is not written again when appending to a non-empty file
         for charset in ["utf-8-sig", "utf-16", "utf-32"]:
             with _io.open(self.tmpfile, "w", encoding=charset) as f:
-                f.write(u"aaa")
+                f.write("aaa")
                 pos = f.tell()
             with _io.open(self.tmpfile, "rb") as f:
                 res = f.read()
                 assert res == "aaa".encode(charset)
             with _io.open(self.tmpfile, "a", encoding=charset) as f:
-                f.write(u"xxx")
+                f.write("xxx")
             with _io.open(self.tmpfile, "rb") as f:
                 res = f.read()
                 assert res == "aaaxxx".encode(charset)

pypy/module/_io/test/test_stringio.py

     def test_stringio(self):
         import io
         sio = io.StringIO()
-        sio.write(u'Hello ')
-        sio.write(u'world')
-        assert sio.getvalue() == u'Hello world'
+        sio.write('Hello ')
+        sio.write('world')
+        assert sio.getvalue() == 'Hello world'
 
-        assert io.StringIO(u"hello").read() == u'hello'
+        assert io.StringIO("hello").read() == 'hello'
 
     def test_capabilities(self):
         import io
         sio = io.StringIO()
         sio.close()
         raises(ValueError, sio.read, 1)
-        raises(ValueError, sio.write, u"text")
+        raises(ValueError, sio.write, "text")
 
     def testRead(self):
         import io
-        buf = u"1234567890"
+        buf = "1234567890"
         sio = io.StringIO(buf)
 
         assert buf[:1] == sio.read(1)
         assert buf[1:5] == sio.read(4)
         assert buf[5:] == sio.read(900)
-        assert u"" == sio.read()
+        assert "" == sio.read()
 
     def test_seek(self):
         import io
 
-        s = u"1234567890"
+        s = "1234567890"
         sio = io.StringIO(s)
 
         sio.read(5)
     def test_overseek(self):
         import io
 
-        s = u"1234567890"
+        s = "1234567890"
         sio = io.StringIO(s)
 
         res = sio.seek(11)
         assert res == 11
         res = sio.read()
-        assert res == u""
+        assert res == ""
         assert sio.tell() == 11
         assert sio.getvalue() == s
-        sio.write(u"")
+        sio.write("")
         assert sio.getvalue() == s
         sio.write(s)
-        assert sio.getvalue() == s + u"\0" + s
+        assert sio.getvalue() == s + "\0" + s
 
     def test_tell(self):
         import io
 
-        s = u"1234567890"
+        s = "1234567890"
         sio = io.StringIO(s)
 
         assert sio.tell() == 0
     def test_truncate(self):
         import io
 
-        s = u"1234567890"
+        s = "1234567890"
         sio = io.StringIO(s)
 
         raises(ValueError, sio.truncate, -1)
         res = sio.truncate(4)
         assert res == 4
         assert sio.getvalue() == s[:4]
-        # truncate() accepts long objects
-        res = sio.truncate(4L)
-        assert res == 4
-        assert sio.getvalue() == s[:4]
         assert sio.tell() == 6
         sio.seek(0, 2)
         sio.write(s)
         exc_info = raises(TypeError, io.StringIO, 3)
         assert "int" in exc_info.value.args[0]
 
-        sio = io.StringIO(u"")
+        sio = io.StringIO("")
         exc_info = raises(TypeError, sio.write, 3)
         assert "int" in exc_info.value.args[0]
 
     def test_newline_none(self):
         import io
 
-        sio = io.StringIO(u"a\nb\r\nc\rd", newline=None)
+        sio = io.StringIO("a\nb\r\nc\rd", newline=None)
         res = list(sio)
-        assert res == [u"a\n", u"b\n", u"c\n", u"d"]
+        assert res == ["a\n", "b\n", "c\n", "d"]
         sio.seek(0)
         res = sio.read(1)
-        assert res == u"a"
+        assert res == "a"
         res = sio.read(2)
-        assert res == u"\nb"
+        assert res == "\nb"
         res = sio.read(2)
-        assert res == u"\nc"
+        assert res == "\nc"
         res = sio.read(1)
-        assert res == u"\n"
+        assert res == "\n"
 
         sio = io.StringIO(newline=None)
-        res = sio.write(u"a\n")
+        res = sio.write("a\n")
         assert res == 2
-        res = sio.write(u"b\r\n")
+        res = sio.write("b\r\n")
         assert res == 3
-        res = sio.write(u"c\rd")
+        res = sio.write("c\rd")
         assert res == 3
         sio.seek(0)
         res = sio.read()
-        assert res == u"a\nb\nc\nd"
-        sio = io.StringIO(u"a\r\nb", newline=None)
+        assert res == "a\nb\nc\nd"
+        sio = io.StringIO("a\r\nb", newline=None)
         res = sio.read(3)
-        assert res == u"a\nb"
+        assert res == "a\nb"
 
     def test_newline_empty(self):
         import io
 
-        sio = io.StringIO(u"a\nb\r\nc\rd", newline="")
+        sio = io.StringIO("a\nb\r\nc\rd", newline="")
         res = list(sio)
-        assert res == [u"a\n", u"b\r\n", u"c\r", u"d"]
+        assert res == ["a\n", "b\r\n", "c\r", "d"]
         sio.seek(0)
         res = sio.read(4)
-        assert res == u"a\nb\r"
+        assert res == "a\nb\r"
         res = sio.read(2)
-        assert res == u"\nc"
+        assert res == "\nc"
         res = sio.read(1)
-        assert res == u"\r"
+        assert res == "\r"
 
         sio = io.StringIO(newline="")
-        res = sio.write(u"a\n")
+        res = sio.write("a\n")
         assert res == 2
-        res = sio.write(u"b\r")
+        res = sio.write("b\r")
         assert res == 2
-        res = sio.write(u"\nc")
+        res = sio.write("\nc")
         assert res == 2
-        res = sio.write(u"\rd")
+        res = sio.write("\rd")
         assert res == 2
         sio.seek(0)
         res = list(sio)
-        assert res == [u"a\n", u"b\r\n", u"c\r", u"d"]
+        assert res == ["a\n", "b\r\n", "c\r", "d"]
 
     def test_newline_lf(self):
         import io
 
-        sio = io.StringIO(u"a\nb\r\nc\rd")
+        sio = io.StringIO("a\nb\r\nc\rd")
         res = list(sio)
-        assert res == [u"a\n", u"b\r\n", u"c\rd"]
+        assert res == ["a\n", "b\r\n", "c\rd"]
 
     def test_newline_cr(self):
         import io
 
-        sio = io.StringIO(u"a\nb\r\nc\rd", newline="\r")
+        sio = io.StringIO("a\nb\r\nc\rd", newline="\r")
         res = sio.read()
-        assert res == u"a\rb\r\rc\rd"
+        assert res == "a\rb\r\rc\rd"
         sio.seek(0)
         res = list(sio)
-        assert res == [u"a\r", u"b\r", u"\r", u"c\r", u"d"]
+        assert res == ["a\r", "b\r", "\r", "c\r", "d"]
 
     def test_newline_crlf(self):
         import io
 
-        sio = io.StringIO(u"a\nb\r\nc\rd", newline="\r\n")
+        sio = io.StringIO("a\nb\r\nc\rd", newline="\r\n")
         res = sio.read()
-        assert res == u"a\r\nb\r\r\nc\rd"
+        assert res == "a\r\nb\r\r\nc\rd"
         sio.seek(0)
         res = list(sio)
-        assert res == [u"a\r\n", u"b\r\r\n", u"c\rd"]
+        assert res == ["a\r\n", "b\r\r\n", "c\rd"]
 
     def test_newline_property(self):
         import io
 
         sio = io.StringIO(newline=None)
         assert sio.newlines is None
-        sio.write(u"a\n")
+        sio.write("a\n")
         assert sio.newlines == "\n"
-        sio.write(u"b\r\n")
+        sio.write("b\r\n")
         assert sio.newlines == ("\n", "\r\n")
-        sio.write(u"c\rd")
+        sio.write("c\rd")
         assert sio.newlines == ("\r", "\n", "\r\n")
 
     def test_iterator(self):
         import io
 
-        s = u"1234567890\n"
+        s = "1234567890\n"
         sio = io.StringIO(s * 10)
 
         assert iter(sio) is sio
         import io
 
         sio = io.StringIO()
-        sio.__setstate__((u"no error", u"\n", 0, None))
-        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__, (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))
+        sio.__setstate__(("no error", "\n", 0, None))
+        sio.__setstate__(("no error", "", 0, {"spam": 3}))
+        raises(ValueError, sio.__setstate__, ("", "f", 0, None))
+        raises(ValueError, sio.__setstate__, ("", "", -1, None))
+        raises(TypeError, sio.__setstate__, (b"", "", 0, None))
+        raises(TypeError, sio.__setstate__, ("", "", 0.0, None))
+        raises(TypeError, sio.__setstate__, ("", "", 0, 0))
+        raises(TypeError, sio.__setstate__, ("len-test", 0))
         raises(TypeError, sio.__setstate__)
         raises(TypeError, sio.__setstate__, 0)
         sio.close()
-        raises(ValueError, sio.__setstate__, (u"closed", u"", 0, None))
+        raises(ValueError, sio.__setstate__, ("closed", "", 0, None))

pypy/module/_io/test/test_textio.py

         t.__init__(b, encoding="utf8", line_buffering=True)
         assert t.encoding == "utf8"
         assert t.line_buffering == True
-        assert t.readline() == u"\xe9\n"
+        assert t.readline() == "\xe9\n"
         raises(TypeError, t.__init__, b, newline=42)
         raises(ValueError, t.__init__, b, newline='xyzzy')
         t = _io.TextIOWrapper(b)
         r = _io.BytesIO(b"abc\r\ndef\rg")
         b = _io.BufferedReader(r, 1000)
         t = _io.TextIOWrapper(b)
-        assert t.read() == u"abc\ndef\ng"
+        assert t.read() == "abc\ndef\ng"
 
     def test_one_by_one(self):
         import _io
             if not c:
                 break
             reads.append(c)
-        assert u''.join(reads) == u"abc\ndef\ng"
+        assert ''.join(reads) == "abc\ndef\ng"
 
     def test_read_some_then_all(self):
         import _io
         t = _io.TextIOWrapper(r)
         reads = t.read(4)
         reads += t.read()
-        assert reads == u"abc\ndef\n"
+        assert reads == "abc\ndef\n"
 
     def test_read_some_then_readline(self):
         import _io
         t = _io.TextIOWrapper(r)
         reads = t.read(4)
         reads += t.readline()
-        assert reads == u"abc\ndef\n"
+        assert reads == "abc\ndef\n"
 
     def test_encoded_writes(self):
         import _io
-        data = u"1234567890"
+        data = "1234567890"
         tests = ("utf-16",
                  "utf-16-le",
                  "utf-16-be",
                 _io.BytesIO.close(self)
         b = MyBytesIO()
         t = _io.TextIOWrapper(b, encoding="ascii")
-        t.write(u"abc")
+        t.write("abc")
         del t
         import gc; gc.collect()
         assert l == [b"abc"]
         assert repr(t) == "<_io.TextIOWrapper encoding='utf-8'>"
         t = _io.TextIOWrapper(_io.BytesIO(b""), encoding="ascii")
         assert repr(t) == "<_io.TextIOWrapper encoding='ascii'>"
-        t = _io.TextIOWrapper(_io.BytesIO(b""), encoding=u"utf-8")
+        t = _io.TextIOWrapper(_io.BytesIO(b""), encoding="utf-8")
         assert repr(t) == "<_io.TextIOWrapper encoding='utf-8'>"
         b = _io.BytesIO(b"")
         t = _io.TextIOWrapper(b, encoding="utf-8")
                 decoder.setstate(state)
                 assert decoder.decode(b, **kwargs) == s
 
-            _check_decode(b'\xe8\xa2\x88', u"\u8888")
+            _check_decode(b'\xe8\xa2\x88', "\u8888")
 
             _check_decode(b'\xe8', "")
             _check_decode(b'\xa2', "")
-            _check_decode(b'\x88', u"\u8888")
+            _check_decode(b'\x88', "\u8888")
 
             _check_decode(b'\xe8', "")
             _check_decode(b'\xa2', "")
-            _check_decode(b'\x88', u"\u8888")
+            _check_decode(b'\x88', "\u8888")
 
             _check_decode(b'\xe8', "")
             raises(UnicodeDecodeError, decoder.decode, b'', final=True)
             _check_decode(b'\r', "\n")
             _check_decode(b'\na', "\na")
 
-            _check_decode(b'\xe8\xa2\x88\r\n', u"\u8888\n")
-            _check_decode(b'\xe8\xa2\x88', u"\u8888")
+            _check_decode(b'\xe8\xa2\x88\r\n', "\u8888\n")
+            _check_decode(b'\xe8\xa2\x88', "\u8888")
             _check_decode(b'\n', "\n")
-            _check_decode(b'\xe8\xa2\x88\r', u"\u8888")
+            _check_decode(b'\xe8\xa2\x88\r', "\u8888")
             _check_decode(b'\n', "\n")
 
         def check_newline_decoding(decoder, encoding):
                     for c in s:
                         result.append(decoder.decode(c))
             assert decoder.newlines == None
-            _decode_bytewise(u"abc\n\r")
+            _decode_bytewise("abc\n\r")
             assert decoder.newlines == '\n'
-            _decode_bytewise(u"\nabc")
+            _decode_bytewise("\nabc")
             assert decoder.newlines == ('\n', '\r\n')
-            _decode_bytewise(u"abc\r")
+            _decode_bytewise("abc\r")
             assert decoder.newlines == ('\n', '\r\n')
-            _decode_bytewise(u"abc")
+            _decode_bytewise("abc")
             assert decoder.newlines == ('\r', '\n', '\r\n')
-            _decode_bytewise(u"abc\r")
+            _decode_bytewise("abc\r")
             assert "".join(result) == "abc\n\nabcabc\nabcabc"
             decoder.reset()
-            input = u"abc"
+            input = "abc"
             if encoder is not None:
                 encoder.reset()
                 input = encoder.encode(input)
         # Issue 5433: Excessive optimization in IncrementalNewlineDecoder
         def _check(dec):
             assert dec.newlines is None
-            assert dec.decode(u"\u0D00") == u"\u0D00"
+            assert dec.decode("\u0D00") == "\u0D00"
             assert dec.newlines is None
-            assert dec.decode(u"\u0A00") == u"\u0A00"
+            assert dec.decode("\u0A00") == "\u0A00"
             assert dec.newlines is None
         dec = _io.IncrementalNewlineDecoder(None, translate=False)
         _check(dec)