[Python-checkins] CVS: python/dist/src/Lib/test test_array.py,1.6,1.7
Fred L. Drake
python-dev@python.org
Wed, 28 Jun 2000 10:50:53 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory slayer.i.sourceforge.net:/tmp/cvs-serv31348/Lib/test
Modified Files:
test_array.py
Log Message:
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.
Index: test_array.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_array.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** test_array.py 1998/07/16 15:31:43 1.6
--- test_array.py 2000/06/28 17:50:51 1.7
***************
*** 16,19 ****
--- 16,57 ----
+ 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):
***************
*** 82,86 ****
raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type`
!
main()
!
--- 120,138 ----
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()
!