[pypy-commit] pypy py3.5: Test and fix

arigo pypy.commits at gmail.com
Sun Dec 4 16:01:02 EST 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r88886:2b00c209938d
Date: 2016-12-04 22:00 +0100
http://bitbucket.org/pypy/pypy/changeset/2b00c209938d/

Log:	Test and fix

diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -90,11 +90,15 @@
             as_int = bigint.toint()
         except OverflowError:
             from pypy.objspace.std.longobject import newbigint
+            if space.is_w(w_inttype, space.w_bool):
+                return space.w_True      # extremely obscure case
             return newbigint(space, w_inttype, bigint)
         else:
             if space.is_w(w_inttype, space.w_int):
                 # common case
                 return wrapint(space, as_int)
+            if space.is_w(w_inttype, space.w_bool):
+                return space.newbool(as_int)     # extremely obscure case
             w_obj = space.allocate_instance(W_IntObject, w_inttype)
             W_IntObject.__init__(w_obj, as_int)
             return w_obj
diff --git a/pypy/objspace/std/test/test_boolobject.py b/pypy/objspace/std/test/test_boolobject.py
--- a/pypy/objspace/std/test/test_boolobject.py
+++ b/pypy/objspace/std/test/test_boolobject.py
@@ -84,3 +84,7 @@
             def __bool__(self):
                 return 1
         raises(TypeError, bool, Spam())
+
+    def test_from_bytes(self):
+        assert bool.from_bytes(b"", 'little') is False
+        assert bool.from_bytes(b"dasijldjs" * 157, 'little') is True
diff --git a/pypy/objspace/std/test/test_intobject.py b/pypy/objspace/std/test/test_intobject.py
--- a/pypy/objspace/std/test/test_intobject.py
+++ b/pypy/objspace/std/test/test_intobject.py
@@ -607,6 +607,16 @@
         assert int(bytearray(b'100'), 2) == 4
         raises(TypeError, int, memoryview(b'100'), 2)
 
+    def test_from_bytes(self):
+        class X(int):
+            pass
+        x = X.from_bytes(b"", 'little')
+        assert type(x) is X and x == 0
+        x = X.from_bytes(b"*" * 100, 'little')
+        assert type(x) is X
+        expected = sum(256 ** i for i in range(100))
+        assert x == expected * ord('*')
+
 
 class AppTestIntShortcut(AppTestInt):
     spaceconfig = {"objspace.std.intshortcut": True}


More information about the pypy-commit mailing list