summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_array.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-06-28 17:50:51 (GMT)
committerFred Drake <fdrake@acm.org>2000-06-28 17:50:51 (GMT)
commit7833447f8f41d09749796cfa5e96788bccbab7a0 (patch)
treeabdca79fc57006092c349ad42658c73192e3c559 /Lib/test/test_array.py
parent541dc3b7b2606906e0ee2d9088a984443b1fa64c (diff)
downloadcpython-7833447f8f41d09749796cfa5e96788bccbab7a0.zip
cpython-7833447f8f41d09749796cfa5e96788bccbab7a0.tar.gz
cpython-7833447f8f41d09749796cfa5e96788bccbab7a0.tar.bz2
Trent Mick <trentm@activestate.com>:
Testing: test_array.py was also extended to check that one can set the full range of values for each of the integral signed and unsigned array types. This closes SourceForge patch #100506.
Diffstat (limited to 'Lib/test/test_array.py')
-rwxr-xr-xLib/test/test_array.py56
1 files changed, 54 insertions, 2 deletions
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index 1e0f1be..a82ace5 100755
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -15,6 +15,44 @@ def main():
unlink(TESTFN)
+def testoverflow(type, lowerLimit, upperLimit):
+ # should not overflow assigning lower limit
+ if verbose:
+ print "overflow test: array(%s, [%s])" % (`type`, `lowerLimit`)
+ try:
+ a = array.array(type, [lowerLimit])
+ except:
+ raise TestFailed, "array(%s) overflowed assigning %s" %\
+ (`type`, `lowerLimit`)
+ # should overflow assigning less than lower limit
+ if verbose:
+ print "overflow test: array(%s, [%s])" % (`type`, `lowerLimit-1`)
+ try:
+ a = array.array(type, [lowerLimit-1])
+ raise TestFailed, "array(%s) did not overflow assigning %s" %\
+ (`type`, `lowerLimit-1`)
+ except OverflowError:
+ pass
+ # should not overflow assigning upper limit
+ if verbose:
+ print "overflow test: array(%s, [%s])" % (`type`, `upperLimit`)
+ try:
+ a = array.array(type, [upperLimit])
+ except:
+ raise TestFailed, "array(%s) overflowed assigning %s" %\
+ (`type`, `upperLimit`)
+ # should overflow assigning more than upper limit
+ if verbose:
+ print "overflow test: array(%s, [%s])" % (`type`, `upperLimit+1`)
+ try:
+ a = array.array(type, [upperLimit+1])
+ raise TestFailed, "array(%s) did not overflow assigning %s" %\
+ (`type`, `upperLimit+1`)
+ except OverflowError:
+ pass
+
+
+
def testtype(type, example):
a = array.array(type)
@@ -81,6 +119,20 @@ def testtype(type, example):
if a != array.array(type, [1, 1, 2, 3, 4, 5, 5]):
raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type`
-
+ # test that overflow exceptions are raised as expected for assignment
+ # to array of specific integral types
+ from math import pow
+ if type in ('b', 'h', 'i', 'l'):
+ # check signed and unsigned versions
+ a = array.array(type)
+ signedLowerLimit = -1 * long(pow(2, a.itemsize * 8 - 1))
+ signedUpperLimit = long(pow(2, a.itemsize * 8 - 1)) - 1L
+ unsignedLowerLimit = 0
+ unsignedUpperLimit = long(pow(2, a.itemsize * 8)) - 1L
+ testoverflow(type, signedLowerLimit, signedUpperLimit)
+ testoverflow(type.upper(), unsignedLowerLimit, unsignedUpperLimit)
+
+
+
main()
-
+