[pypy-commit] pypy default: use modern py3k compat. syntax when we can: byte literals, except exc as,

pjenvey noreply at buildbot.pypy.org
Tue Mar 11 21:24:11 CET 2014


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: 
Changeset: r69872:76e1b1d43ca4
Date: 2014-03-11 13:08 -0700
http://bitbucket.org/pypy/pypy/changeset/76e1b1d43ca4/

Log:	use modern py3k compat. syntax when we can: byte literals, except
	exc as, str(exc) and sys.maxsize vs sys.maxint

diff --git a/pypy/module/__builtin__/test/test_builtin.py b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -489,24 +489,24 @@
     def test_compile_error_message(self):
         import re
         compile('# -*- coding: iso-8859-15 -*-\n', 'dummy', 'exec')
-        compile('\xef\xbb\xbf\n', 'dummy', 'exec')
-        compile('\xef\xbb\xbf# -*- coding: utf-8 -*-\n', 'dummy', 'exec')
+        compile(b'\xef\xbb\xbf\n', 'dummy', 'exec')
+        compile(b'\xef\xbb\xbf# -*- coding: utf-8 -*-\n', 'dummy', 'exec')
         exc = raises(SyntaxError, compile,
-            '# -*- coding: fake -*-\n', 'dummy', 'exec')
-        assert 'fake' in exc.value[0]
+            b'# -*- coding: fake -*-\n', 'dummy', 'exec')
+        assert 'fake' in str(exc.value)
         exc = raises(SyntaxError, compile,
-            '\xef\xbb\xbf# -*- coding: iso-8859-15 -*-\n', 'dummy', 'exec')
-        assert 'iso-8859-15' in exc.value[0]
-        assert 'BOM' in exc.value[0]
+            b'\xef\xbb\xbf# -*- coding: iso-8859-15 -*-\n', 'dummy', 'exec')
+        assert 'iso-8859-15' in str(exc.value), str(exc.value)
+        assert 'BOM' in str(exc.value)
         exc = raises(SyntaxError, compile,
-            '\xef\xbb\xbf# -*- coding: fake -*-\n', 'dummy', 'exec')
-        assert 'fake' in exc.value[0]
-        assert 'BOM' in exc.value[0]
+            b'\xef\xbb\xbf# -*- coding: fake -*-\n', 'dummy', 'exec')
+        assert 'fake' in str(exc.value)
+        assert 'BOM' in str(exc.value)
 
     def test_unicode_compile(self):
         try:
             compile(u'-', '?', 'eval')
-        except SyntaxError, e:
+        except SyntaxError as e:
             assert e.lineno == 1
 
     def test_unicode_encoding_compile(self):
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
@@ -216,7 +216,7 @@
 
     def test_flush_error_on_close(self):
         import _io
-        txt = _io.TextIOWrapper(_io.BytesIO(""), encoding="ascii")
+        txt = _io.TextIOWrapper(_io.BytesIO(b""), encoding="ascii")
         def bad_flush():
             raise IOError()
         txt.flush = bad_flush
diff --git a/pypy/module/fcntl/test/test_fcntl.py b/pypy/module/fcntl/test/test_fcntl.py
--- a/pypy/module/fcntl/test/test_fcntl.py
+++ b/pypy/module/fcntl/test/test_fcntl.py
@@ -36,15 +36,15 @@
         raises(TypeError, fcntl.fcntl, "foo")
         raises(TypeError, fcntl.fcntl, f, "foo")
         exc = raises(TypeError, fcntl.fcntl, F("foo"), 1)
-        assert exc.value[0] == 'fileno() returned a non-integer'
+        assert str(exc.value) == 'fileno() returned a non-integer'
         exc = raises(ValueError, fcntl.fcntl, 2147483647 + 1, 1, 0)
-        assert exc.value[0] == 'file descriptor cannot be a negative integer (-1)'
+        assert str(exc.value) == 'file descriptor cannot be a negative integer (-1)'
         exc = raises(ValueError, fcntl.fcntl, F(2147483647 + 1), 1, 0)
-        assert exc.value[0] == 'file descriptor cannot be a negative integer (-1)'
+        assert str(exc.value) == 'file descriptor cannot be a negative integer (-1)'
         exc = raises(ValueError, fcntl.fcntl, -2147483648 - 1, 1, 0)
-        assert exc.value[0] == 'file descriptor cannot be a negative integer (-1)'
+        assert str(exc.value) == 'file descriptor cannot be a negative integer (-1)'
         exc = raises(ValueError, fcntl.fcntl, F(-2147483648 - 1), 1, 0)
-        assert exc.value[0] == 'file descriptor cannot be a negative integer (-1)'
+        assert str(exc.value) == 'file descriptor cannot be a negative integer (-1)'
         raises(ValueError, fcntl.fcntl, -1, 1, 0)
         raises(ValueError, fcntl.fcntl, F(-1), 1, 0)
         raises(ValueError, fcntl.fcntl, F(long(-1)), 1, 0)
diff --git a/pypy/module/mmap/test/test_mmap.py b/pypy/module/mmap/test/test_mmap.py
--- a/pypy/module/mmap/test/test_mmap.py
+++ b/pypy/module/mmap/test/test_mmap.py
@@ -843,6 +843,6 @@
                 m.close()
                 assert False, "should not have been able to mmap empty file"
             except ValueError as e:
-                assert e.message == "cannot mmap an empty file"
+                assert str(e) == "cannot mmap an empty file"
             except BaseException as e:
                 assert False, "unexpected exception: " + str(e)
diff --git a/pypy/module/pwd/test/test_pwd.py b/pypy/module/pwd/test/test_pwd.py
--- a/pypy/module/pwd/test/test_pwd.py
+++ b/pypy/module/pwd/test/test_pwd.py
@@ -24,7 +24,7 @@
         assert type(pw.pw_gid) is int
         raises(TypeError, pwd.getpwuid)
         raises(TypeError, pwd.getpwuid, 3.14)
-        raises(KeyError, pwd.getpwuid, sys.maxint)
+        raises(KeyError, pwd.getpwuid, sys.maxsize)
         # -1 is allowed, cast to uid_t
         exc = raises(KeyError, pwd.getpwuid, -1)
         m = re.match('getpwuid\(\): uid not found: ([0-9]+)', exc.value[0])
diff --git a/pypy/module/select/test/test_select.py b/pypy/module/select/test/test_select.py
--- a/pypy/module/select/test/test_select.py
+++ b/pypy/module/select/test/test_select.py
@@ -219,15 +219,15 @@
         pollster = select.poll()
         pollster.register(1)
         exc = raises(OverflowError, pollster.register, 0, 32768) # SHRT_MAX + 1
-        assert exc.value[0] == 'signed short integer is greater than maximum'
+        assert str(exc.value) == 'signed short integer is greater than maximum'
         exc = raises(OverflowError, pollster.register, 0, -32768 - 1)
-        assert exc.value[0] == 'signed short integer is less than minimum'
+        assert str(exc.value) == 'signed short integer is less than minimum'
         raises(OverflowError, pollster.register, 0, 65535) # USHRT_MAX + 1
         raises(OverflowError, pollster.poll, 2147483648) # INT_MAX +  1
         raises(OverflowError, pollster.poll, -2147483648 - 1)
         raises(OverflowError, pollster.poll, 4294967296) # UINT_MAX + 1
         exc = raises(TypeError, pollster.poll, '123')
-        assert exc.value[0] == 'timeout must be an integer or None'
+        assert str(exc.value) == 'timeout must be an integer or None'
 
 
 class AppTestSelectWithPipes(_AppTestSelect):
@@ -277,7 +277,7 @@
                     pollster.unregister(fd)
                 pollster.register(w, select.POLLOUT)
                 exc = raises(RuntimeError, pollster.poll)
-                assert exc.value[0] == 'concurrent poll() invocation'
+                assert str(exc.value) == 'concurrent poll() invocation'
             finally:
                 # and make the call to poll() from the thread return
                 os.write(w, b'spam')
diff --git a/pypy/module/zlib/test/test_zlib.py b/pypy/module/zlib/test/test_zlib.py
--- a/pypy/module/zlib/test/test_zlib.py
+++ b/pypy/module/zlib/test/test_zlib.py
@@ -166,9 +166,9 @@
         raises(ValueError, zlib.decompressobj().flush, -1)
         raises(TypeError, zlib.decompressobj().flush, None)
         raises(OverflowError, zlib.decompressobj().flush, 2**31)
-        raises(ValueError, zlib.decompressobj().decompress, 'abc', -1)
-        raises(TypeError, zlib.decompressobj().decompress, 'abc', None)
-        raises(OverflowError, zlib.decompressobj().decompress, 'abc', 2**31)
+        raises(ValueError, zlib.decompressobj().decompress, b'abc', -1)
+        raises(TypeError, zlib.decompressobj().decompress, b'abc', None)
+        raises(OverflowError, zlib.decompressobj().decompress, b'abc', 2**31)
         raises(TypeError, self.zlib.decompress, self.compressed, None)
         raises(OverflowError, self.zlib.decompress, self.compressed, 2**31)
 
@@ -177,21 +177,21 @@
         co = zlib.compressobj(zlib.Z_BEST_COMPRESSION)
         assert co.flush()  # Returns a zlib header
         dco = zlib.decompressobj()
-        assert dco.flush() == ""
+        assert dco.flush() == b""
 
     def test_decompress_incomplete_stream(self):
         import zlib
         # This is 'foo', deflated
-        x = 'x\x9cK\xcb\xcf\x07\x00\x02\x82\x01E'
+        x = b'x\x9cK\xcb\xcf\x07\x00\x02\x82\x01E'
         # For the record
-        assert zlib.decompress(x) == 'foo'
+        assert zlib.decompress(x) == b'foo'
         raises(zlib.error, zlib.decompress, x[:-5])
         # Omitting the stream end works with decompressor objects
         # (see issue #8672).
         dco = zlib.decompressobj()
         y = dco.decompress(x[:-5])
         y += dco.flush()
-        assert y == 'foo'
+        assert y == b'foo'
 
     def test_unused_data(self):
         """
@@ -256,13 +256,13 @@
     def test_flush_with_freed_input(self):
         # Issue #16411: decompressor accesses input to last decompress() call
         # in flush(), even if this object has been freed in the meanwhile.
-        input1 = 'abcdefghijklmnopqrstuvwxyz'
-        input2 = 'QWERTYUIOPASDFGHJKLZXCVBNM'
+        input1 = b'abcdefghijklmnopqrstuvwxyz'
+        input2 = b'QWERTYUIOPASDFGHJKLZXCVBNM'
         data = self.zlib.compress(input1)
         dco = self.zlib.decompressobj()
         dco.decompress(data, 1)
         del data
         data = self.zlib.compress(input2)
         assert dco.flush(1) == input1[1:]
-        assert dco.unused_data == ''
-        assert dco.unconsumed_tail == ''
+        assert dco.unused_data == b''
+        assert dco.unconsumed_tail == b''


More information about the pypy-commit mailing list