aboutsummaryrefslogtreecommitdiffstats
path: root/tests/samplebinding/implicitconv_numerical_test.py
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2016-12-14 15:51:30 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2016-12-16 11:25:28 +0000
commitfba0fa2313df035584faebea7b321d6ba2d57c4f (patch)
tree7d0060f1b5d0fe3bce01126f342cae43b04eb796 /tests/samplebinding/implicitconv_numerical_test.py
parent8ae5b388797cbc2921ee83753d1e9ac556ebbbdf (diff)
implicitconv_numerical_test.py: Fix limits
Introduce variables representing the min/max of the underlying integer C-types, fixing the test to pass on Windows 64bit. Task-number: PYSIDE-431 Change-Id: I9dab0cdae5c7018003654fdc51cc213d3d6531ac Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'tests/samplebinding/implicitconv_numerical_test.py')
-rw-r--r--tests/samplebinding/implicitconv_numerical_test.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/tests/samplebinding/implicitconv_numerical_test.py b/tests/samplebinding/implicitconv_numerical_test.py
index ca46376cf..3fe66e30c 100644
--- a/tests/samplebinding/implicitconv_numerical_test.py
+++ b/tests/samplebinding/implicitconv_numerical_test.py
@@ -36,9 +36,17 @@ import sys
import sample
from py3kcompat import IS_PY3K, l, long
-if IS_PY3K:
- sys.maxint = sys.maxsize
-
+# Hardcode the limits of the underlying C-types depending on architecture and memory
+# model (taking MSVC using LLP64 into account).
+cIntMin = -2147483648
+cIntMax = 2147483647
+cLongMin = cIntMin
+cLongMax = cIntMax
+maxRepresentableInt = sys.maxsize if IS_PY3K else sys.maxint
+is64bitArchitecture = maxRepresentableInt > 2**32
+if is64bitArchitecture and sys.platform != 'win32':
+ cLongMin = -9223372036854775808
+ cLongMax = 9223372036854775807
class NumericTester(unittest.TestCase):
'''Helper class for numeric comparison testing'''
@@ -57,13 +65,13 @@ class FloatImplicitConvert(NumericTester):
def testFloatAsInt(self):
'''Float as Int'''
self.check_value(3.14, 3, sample.acceptInt, int)
- self.assertRaises(OverflowError, sample.acceptInt, sys.maxint + 400)
+ self.assertRaises(OverflowError, sample.acceptInt, cIntMax + 400)
def testFloatAsLong(self):
'''Float as Long'''
#C++ longs are python ints for us
self.check_value(3.14, 3, sample.acceptLong, int)
- self.assertRaises(OverflowError, sample.acceptLong, sys.maxint + 400)
+ self.assertRaises(OverflowError, sample.acceptLong, cLongMax + 400)
def testFloatAsUInt(self):
'''Float as unsigned Int'''
@@ -92,9 +100,9 @@ class IntImplicitConvert(NumericTester):
'''Int as Long'''
self.check_value(3, 3, sample.acceptLong, int)
- # sys.maxint goes here as CPython implements int as a C long
- self.check_value(sys.maxint, sys.maxint, sample.acceptLong, int)
- self.check_value(-sys.maxint - 1, -sys.maxint - 1, sample.acceptLong, int)
+ # cLongMax goes here as CPython implements int as a C long
+ self.check_value(cLongMax, cLongMax, sample.acceptLong, int)
+ self.check_value(cLongMin, cLongMin, sample.acceptLong, int)
def testIntAsUInt(self):
'''Int as unsigned Int'''
@@ -117,12 +125,12 @@ class LongImplicitConvert(NumericTester):
def testLongAsInt(self):
'''Long as Int'''
self.check_value(l(24224), 24224, sample.acceptInt, int)
- self.assertRaises(OverflowError, sample.acceptInt, sys.maxint + 20)
+ self.assertRaises(OverflowError, sample.acceptInt, cIntMax + 20)
def testLongAsLong(self):
'''Long as Long'''
self.check_value(l(2405), 2405, sample.acceptLong, int)
- self.assertRaises(OverflowError, sample.acceptLong, sys.maxint + 20)
+ self.assertRaises(OverflowError, sample.acceptLong, cLongMax + 20)
def testLongAsUInt(self):
'''Long as unsigned Int'''