Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r69656:4a6f33f5edb7
Date: 2014-03-03 20:28 -0800
http://bitbucket.org/pypy/pypy/changeset/4a6f33f5edb7/

Log:    ensure we are testing the 'long' paths

diff --git a/pypy/objspace/std/test/test_longobject.py 
b/pypy/objspace/std/test/test_longobject.py
--- a/pypy/objspace/std/test/test_longobject.py
+++ b/pypy/objspace/std/test/test_longobject.py
@@ -42,46 +42,54 @@
 
 
 class AppTestLong:
+
+    def setup_class(cls):
+        from pypy.interpreter import gateway
+        from pypy.objspace.std.longobject import W_LongObject
+        def w__long(space, w_obj):
+            return W_LongObject.fromint(space, space.int_w(w_obj))
+        cls.w__long = cls.space.wrap(gateway.interp2app(w__long))
+
     def test_trunc(self):
         import math
-        assert math.trunc(1) == 1
-        assert math.trunc(-1) == -1
+        assert math.trunc(self._long(1)) == self._long(1)
+        assert math.trunc(-self._long(1)) == -self._long(1)
 
     def test_add(self):
-        x = 123
-        assert int(x + 12443) == 123 + 12443
+        x = self._long(123)
+        assert int(x + self._long(12443)) == 123 + 12443
         x = -20
-        assert x + 2 + 3 + True == -14
+        assert x + 2 + self._long(3) + True == -self._long(14)
 
     def test_sub(self):
-        x = 58543
-        assert int(x - 12332) == 58543 - 12332
-        x = 237123838281233
-        assert x * 12 == x * 12
+        x = self._long(58543)
+        assert int(x - self._long(12332)) == 58543 - 12332
+        x = self._long(237123838281233)
+        assert x * 12 == x * self._long(12)
 
     def test_mul(self):
-        x = 363
+        x = self._long(363)
         assert x * 2 ** 40 == x << 40
 
     def test_truediv(self):
-        a = 31415926 / 10000000
+        a = self._long(31415926) / self._long(10000000)
         assert a == 3.1415926
 
     def test_floordiv(self):
-        x = 31415926
-        a = x // 10000000
-        assert a == 3
+        x = self._long(31415926)
+        a = x // self._long(10000000)
+        assert a == self._long(3)
 
     def test_numerator_denominator(self):
-        assert (1).numerator == 1
-        assert (1).denominator == 1
-        assert (42).numerator == 42
-        assert (42).denominator == 1
+        assert (self._long(1)).numerator == self._long(1)
+        assert (self._long(1)).denominator == self._long(1)
+        assert (self._long(42)).numerator == self._long(42)
+        assert (self._long(42)).denominator == self._long(1)
 
     def test_compare(self):
         Z = 0
-        ZL = 0
-        for BIG in (1, 1 << 62, 1 << 9999):
+        ZL = self._long(0)
+        for BIG in (self._long(1), self._long(1) << 62, self._long(1) << 9999):
             assert Z == ZL
             assert not (Z != ZL)
             assert ZL == Z
@@ -158,7 +166,7 @@
     def test_conversion(self):
         class long2(int):
             pass
-        x = 1
+        x = self._long(1)
         x = long2(x<<100)
         y = int(x)
         assert type(y) == int
@@ -174,13 +182,13 @@
         assert type(long2(5) // 1) is int
 
     def test_pow(self):
-        x = 0
-        assert pow(x, 0, 1) == 0
-        assert pow(-1, -1) == -1.0
+        x = self._long(0)
+        assert pow(x, self._long(0), self._long(1)) == self._long(0)
+        assert pow(-self._long(1), -self._long(1)) == -1.0
 
     def test_getnewargs(self):
-        assert  0 .__getnewargs__() == (0,)
-        assert  (-1) .__getnewargs__() == (-1,)
+        assert  self._long(0) .__getnewargs__() == (self._long(0),)
+        assert  (-self._long(1)) .__getnewargs__() == (-self._long(1),)
 
     def test_divmod(self):
         def check_division(x, y):
@@ -194,8 +202,8 @@
                 assert 0 <= r < y
             else:
                 assert y < r <= 0
-        for x in [-1, 0, 1, 2 ** 100 - 1, -2 ** 100 - 1]:
-            for y in [-105566530, -1, 1, 1034522340]:
+        for x in [-self._long(1), self._long(0), self._long(1), self._long(2) 
** 100 - 1, -self._long(2) ** 100 - 1]:
+            for y in [-self._long(105566530), -self._long(1), self._long(1), 
self._long(1034522340)]:
                 print("checking division for %s, %s" % (x, y))
                 check_division(x, y)
         # special case from python tests:
@@ -206,31 +214,33 @@
         y = 10953035502453784575
         y >>= s2*16
         x = 0x3FE0003FFFFC0001FFF
-        y = 0x9800FFC1
+        y = self._long(0x9800FFC1)
         check_division(x, y)
-        raises(ZeroDivisionError, "x // 0")
+        raises(ZeroDivisionError, "x // self._long(0)")
+        divmod(3, self._long(4))
 
     def test_format(self):
         assert repr(12345678901234567890) == '12345678901234567890'
         assert str(12345678901234567890) == '12345678901234567890'
-        assert hex(0x1234567890ABCDEF) == '0x1234567890abcdef'
-        assert oct(0o1234567012345670) == '0o1234567012345670'
+        assert hex(self._long(0x1234567890ABCDEF)) == '0x1234567890abcdef'
+        assert oct(self._long(0o1234567012345670)) == '0o1234567012345670'
 
     def test_bits(self):
-        x = 0xAAAAAAAA
-        assert x | 0x55555555 == 0xFFFFFFFF
-        assert x & 0x55555555 == 0x00000000
-        assert x ^ 0x55555555 == 0xFFFFFFFF
-        assert -x | 0x55555555 == -0xAAAAAAA9
-        assert x | 0x555555555 == 0x5FFFFFFFF
-        assert x & 0x555555555 == 0x000000000
-        assert x ^ 0x555555555 == 0x5FFFFFFFF
+        x = self._long(0xAAAAAAAA)
+        assert x | self._long(0x55555555) == self._long(0xFFFFFFFF)
+        assert x & self._long(0x55555555) == self._long(0x00000000)
+        assert x ^ self._long(0x55555555) == self._long(0xFFFFFFFF)
+        assert -x | self._long(0x55555555) == -self._long(0xAAAAAAA9)
+        assert x | self._long(0x555555555) == self._long(0x5FFFFFFFF)
+        assert x & self._long(0x555555555) == self._long(0x000000000)
+        assert x ^ self._long(0x555555555) == self._long(0x5FFFFFFFF)
 
     def test_hash(self):
         import sys
         modulus = sys.hash_info.modulus
-        for x in (list(range(200)) +
-                  [1234567890123456789, 18446743523953737727,
+        for x in ([self._long(i) for i in range(200)] +
+                  [self._long(1234567890123456789),
+                   1234567890123456789, 18446743523953737727,
                    987685321987685321987685321987685321987685321]):
             y = x % modulus
             assert hash(x) == hash(y)
@@ -247,10 +257,10 @@
 
     def test_math_log(self):
         import math
-        raises(ValueError, math.log, 0)
-        raises(ValueError, math.log, -1)
-        raises(ValueError, math.log, -2)
-        raises(ValueError, math.log, -(1 << 10000))
+        raises(ValueError, math.log, self._long(0))
+        raises(ValueError, math.log, -self._long(1))
+        raises(ValueError, math.log, -self._long(2))
+        raises(ValueError, math.log, -(self._long(1) << 10000))
         #raises(ValueError, math.log, 0)
         raises(ValueError, math.log, -1)
         raises(ValueError, math.log, -2)
@@ -261,15 +271,15 @@
         assert int(n) == n
         assert str(int(n)) == str(n)
         a = memoryview(b'123')
-        assert int(a) == 123
+        assert int(a) == self._long(123)
 
     def test_huge_longs(self):
         import operator
-        x = 1
-        huge = x << 40000
+        x = self._long(1)
+        huge = x << self._long(40000)
         raises(OverflowError, float, huge)
         raises(OverflowError, operator.truediv, huge, 3)
-        raises(OverflowError, operator.truediv, huge, 3)
+        raises(OverflowError, operator.truediv, huge, self._long(3))
 
     def test_just_trunc(self):
         class myint(object):
@@ -307,8 +317,8 @@
         assert int(A('abc')) == 42
 
     def test_conjugate(self):
-        assert (7).conjugate() == 7
-        assert (-7).conjugate() == -7
+        assert (self._long(7)).conjugate() == self._long(7)
+        assert (-self._long(7)).conjugate() == -self._long(7)
 
         class L(int):
             pass
@@ -318,10 +328,10 @@
         class L(int):
             def __pos__(self):
                 return 43
-        assert L(7).conjugate() == 7
+        assert L(7).conjugate() == self._long(7)
 
     def test_bit_length(self):
-        assert (8).bit_length() == 4
+        assert self._long(8).bit_length() == 4
         assert (-1<<40).bit_length() == 41
         assert ((2**31)-1).bit_length() == 31
 
@@ -342,8 +352,8 @@
         raises(ValueError, (-5).to_bytes, 1, 'foo')
 
     def test_negative_zero(self):
-        x = eval("-0")
-        assert x == 0
+        x = eval("-self._long(0)")
+        assert x == self._long(0)
 
     def test_long_real(self):
         class A(int): pass
@@ -388,13 +398,10 @@
         assert str(e.value) == (
             "int() argument must be a string or a number, not 'list'")
 
-    def test_coerce(self):
-        assert 3.__coerce__(4) == (3, 4)
-        assert 3.__coerce__(4) == (3, 4)
-        assert 3.__coerce__(object()) == NotImplemented
-
     def test_large_identity(self):
         import sys
         a = sys.maxsize + 1
         b = sys.maxsize + 2
         assert a is not b
+        b -= 1
+        assert a is b
diff --git a/pypy/objspace/std/test/test_smalllongobject.py 
b/pypy/objspace/std/test/test_smalllongobject.py
--- a/pypy/objspace/std/test/test_smalllongobject.py
+++ b/pypy/objspace/std/test/test_smalllongobject.py
@@ -47,24 +47,31 @@
 class AppTestSmallLong(test_longobject.AppTestLong):
     spaceconfig = {"objspace.std.withsmalllong": True}
 
+    def setup_class(cls):
+        from pypy.interpreter import gateway
+        from pypy.objspace.std.smalllongobject import W_SmallLongObject
+        def w__long(space, w_obj):
+            return W_SmallLongObject.fromint(space.int_w(w_obj))
+        cls.w__long = cls.space.wrap(gateway.interp2app(w__long))
+
     def test_sl_simple(self):
         import __pypy__
-        s = __pypy__.internal_repr(5)
+        s = __pypy__.internal_repr(self._long(5))
         assert 'SmallLong' in s
 
     def test_sl_hash(self):
         import __pypy__
-        x = 5
+        x = self._long(5)
         assert 'SmallLong' in __pypy__.internal_repr(x)
         assert hash(5) == hash(x)
-        biglong = 5
+        biglong = self._long(5)
         biglong ^= 2**100      # hack based on the fact that xor__Long_Long
         biglong ^= 2**100      # does not call newlong()
         assert biglong == 5
         assert 'SmallLong' not in __pypy__.internal_repr(biglong)
         assert hash(5) == hash(biglong)
         #
-        x = 0x123456789ABCDEF
+        x = self._long(0x123456789ABCDEF)
         assert 'SmallLong' in __pypy__.internal_repr(x)
         biglong = x
         biglong ^= 2**100
@@ -74,7 +81,7 @@
         assert hash(biglong) == hash(x)
 
     def test_sl_int(self):
-        x = 0x123456789ABCDEF
+        x = self._long(0x123456789ABCDEF)
         two = 2
         assert int(x) == x
         assert type(int(x)) == type(0x1234567 ** two)
@@ -84,21 +91,21 @@
 
     def test_sl_long(self):
         import __pypy__
-        x = int(0)
+        x = self._long(0)
         assert 'SmallLong' in __pypy__.internal_repr(x)
 
     def test_sl_add(self):
         import __pypy__
-        x = 0x123456789ABCDEF
+        x = self._long(0x123456789ABCDEF)
         assert x + x == 0x2468ACF13579BDE
         assert 'SmallLong' in __pypy__.internal_repr(x + x)
-        x = -0x123456789ABCDEF
+        x = self._long(-0x123456789ABCDEF)
         assert x + x == -0x2468ACF13579BDE
         assert 'SmallLong' in __pypy__.internal_repr(x + x)
-        x = 0x723456789ABCDEF0
+        x = self._long(0x723456789ABCDEF0)
         assert x + x == 0xE468ACF13579BDE0
         assert 'SmallLong' not in __pypy__.internal_repr(x + x)
-        x = -0x723456789ABCDEF0
+        x = self._long(-0x723456789ABCDEF0)
         assert x + x == -0xE468ACF13579BDE0
         assert 'SmallLong' not in __pypy__.internal_repr(x + x)
 
@@ -113,8 +120,7 @@
             assert 'SmallLong' in __pypy__.internal_repr(x - y)
 
     def test_sl_lshift(self):
-        # XXX: was [1, 1L]
-        for x in [1, 1]:
+        for x in [1, self._long(1)]:
             x = 1
             assert x << 1 == 2
             assert x << 30 == 1073741824
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to