Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_array.py @ 13772:eea51275acbf legacy-trunk
added count, extend, index, pop and remove to arraymodule
| author | Peter Schneider-Kamp <nowonder@nowonder.de> |
|---|---|
| date | Mon, 31 Jul 2000 20:52:21 +0000 |
| parents | b76df68099a5 |
| children | 1ec6c63347ea |
| rev | line source |
|---|---|
|
4627
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
2 """Test the arraymodule. |
|
4811
9ae3cccfa7cd
Many scripts, but small changes. Update the way the scripts obtain the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4627
diff
changeset
|
3 Roger E. Masse |
|
4627
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
4 """ |
|
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
5 import array |
|
8676
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
6 from test_support import verbose, TESTFN, unlink, TestFailed |
|
4811
9ae3cccfa7cd
Many scripts, but small changes. Update the way the scripts obtain the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4627
diff
changeset
|
7 |
|
9ae3cccfa7cd
Many scripts, but small changes. Update the way the scripts obtain the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4627
diff
changeset
|
8 def main(): |
|
9ae3cccfa7cd
Many scripts, but small changes. Update the way the scripts obtain the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4627
diff
changeset
|
9 |
|
9ae3cccfa7cd
Many scripts, but small changes. Update the way the scripts obtain the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4627
diff
changeset
|
10 testtype('c', 'c') |
|
9ae3cccfa7cd
Many scripts, but small changes. Update the way the scripts obtain the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4627
diff
changeset
|
11 |
|
9ae3cccfa7cd
Many scripts, but small changes. Update the way the scripts obtain the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4627
diff
changeset
|
12 for type in (['b', 'h', 'i', 'l', 'f', 'd']): |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
13 testtype(type, 1) |
|
4811
9ae3cccfa7cd
Many scripts, but small changes. Update the way the scripts obtain the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4627
diff
changeset
|
14 |
|
5289
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
15 unlink(TESTFN) |
|
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
16 |
|
4627
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
17 |
|
13069
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
18 def testoverflow(type, lowerLimit, upperLimit): |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
19 # should not overflow assigning lower limit |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
20 if verbose: |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
21 print "overflow test: array(%s, [%s])" % (`type`, `lowerLimit`) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
22 try: |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
23 a = array.array(type, [lowerLimit]) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
24 except: |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
25 raise TestFailed, "array(%s) overflowed assigning %s" %\ |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
26 (`type`, `lowerLimit`) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
27 # should overflow assigning less than lower limit |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
28 if verbose: |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
29 print "overflow test: array(%s, [%s])" % (`type`, `lowerLimit-1`) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
30 try: |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
31 a = array.array(type, [lowerLimit-1]) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
32 raise TestFailed, "array(%s) did not overflow assigning %s" %\ |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
33 (`type`, `lowerLimit-1`) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
34 except OverflowError: |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
35 pass |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
36 # should not overflow assigning upper limit |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
37 if verbose: |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
38 print "overflow test: array(%s, [%s])" % (`type`, `upperLimit`) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
39 try: |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
40 a = array.array(type, [upperLimit]) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
41 except: |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
42 raise TestFailed, "array(%s) overflowed assigning %s" %\ |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
43 (`type`, `upperLimit`) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
44 # should overflow assigning more than upper limit |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
45 if verbose: |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
46 print "overflow test: array(%s, [%s])" % (`type`, `upperLimit+1`) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
47 try: |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
48 a = array.array(type, [upperLimit+1]) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
49 raise TestFailed, "array(%s) did not overflow assigning %s" %\ |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
50 (`type`, `upperLimit+1`) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
51 except OverflowError: |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
52 pass |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
53 |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
54 |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
55 |
|
4627
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
56 def testtype(type, example): |
|
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
57 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
58 a = array.array(type) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
59 a.append(example) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
60 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
61 print 40*'*' |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
62 print 'array after append: ', a |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
63 a.typecode |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
64 a.itemsize |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
65 if a.typecode in ('i', 'b', 'h', 'l'): |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
66 a.byteswap() |
|
4627
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
67 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
68 if a.typecode == 'c': |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
69 f = open(TESTFN, "w") |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
70 f.write("The quick brown fox jumps over the lazy dog.\n") |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
71 f.close() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
72 f = open(TESTFN, 'r') |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
73 a.fromfile(f, 10) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
74 f.close() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
75 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
76 print 'char array with 10 bytes of TESTFN appended: ', a |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
77 a.fromlist(['a', 'b', 'c']) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
78 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
79 print 'char array with list appended: ', a |
|
4627
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
80 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
81 a.insert(0, example) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
82 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
83 print 'array of %s after inserting another:' % a.typecode, a |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
84 f = open(TESTFN, 'w') |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
85 a.tofile(f) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
86 f.close() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
87 a.tolist() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
88 a.tostring() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
89 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
90 print 'array of %s converted to a list: ' % a.typecode, a.tolist() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
91 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
92 print 'array of %s converted to a string: ' \ |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
93 % a.typecode, `a.tostring()` |
|
4627
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
94 |
|
8676
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
95 if type == 'c': |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
96 a = array.array(type, "abcde") |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
97 a[:-1] = a |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
98 if a != array.array(type, "abcdee"): |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
99 raise TestFailed, "array(%s) self-slice-assign (head)" % `type` |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
100 a = array.array(type, "abcde") |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
101 a[1:] = a |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
102 if a != array.array(type, "aabcde"): |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
103 raise TestFailed, "array(%s) self-slice-assign (tail)" % `type` |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
104 a = array.array(type, "abcde") |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
105 a[1:-1] = a |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
106 if a != array.array(type, "aabcdee"): |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
107 raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type` |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
108 if a.index("e") != 5: |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
109 raise TestFailed, "array(%s) index-test" % `type` |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
110 if a.count("a") != 2: |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
111 raise TestFailed, "array(%s) count-test" % `type` |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
112 a.remove("e") |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
113 if a != array.array(type, "aabcde"): |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
114 raise TestFailed, "array(%s) remove-test" % `type` |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
115 if a.pop(0) != "a": |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
116 raise TestFailed, "array(%s) pop-test" % `type` |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
117 if a.pop(1) != "b": |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
118 raise TestFailed, "array(%s) pop-test" % `type` |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
119 a.extend(array.array(type, "xyz")) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
120 if a != array.array(type, "acdexyz"): |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
121 raise TestFailed, "array(%s) extend-test" % `type` |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
122 a.pop() |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
123 a.pop() |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
124 a.pop() |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
125 a.pop() |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
126 if a != array.array(type, "acd"): |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
127 raise TestFailed, "array(%s) pop-test" % `type` |
|
8676
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
128 else: |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
129 a = array.array(type, [1, 2, 3, 4, 5]) |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
130 a[:-1] = a |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
131 if a != array.array(type, [1, 2, 3, 4, 5, 5]): |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
132 raise TestFailed, "array(%s) self-slice-assign (head)" % `type` |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
133 a = array.array(type, [1, 2, 3, 4, 5]) |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
134 a[1:] = a |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
135 if a != array.array(type, [1, 1, 2, 3, 4, 5]): |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
136 raise TestFailed, "array(%s) self-slice-assign (tail)" % `type` |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
137 a = array.array(type, [1, 2, 3, 4, 5]) |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
138 a[1:-1] = a |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
139 if a != array.array(type, [1, 1, 2, 3, 4, 5, 5]): |
|
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
140 raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type` |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
141 if a.index(5) != 5: |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
142 raise TestFailed, "array(%s) index-test" % `type` |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
143 if a.count(1) != 2: |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
144 raise TestFailed, "array(%s) count-test" % `type` |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
145 a.remove(5) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
146 if a != array.array(type, [1, 1, 2, 3, 4, 5]): |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
147 raise TestFailed, "array(%s) remove-test" % `type` |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
148 if a.pop(0) != 1: |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
149 raise TestFailed, "array(%s) pop-test" % `type` |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
150 if a.pop(1) != 2: |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
151 raise TestFailed, "array(%s) pop-test" % `type` |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
152 a.extend(array.array(type, [7, 8, 9])) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
153 if a != array.array(type, [1, 3, 4, 5, 7, 8, 9]): |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
154 raise TestFailed, "array(%s) extend-test" % `type` |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
155 a.pop() |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
156 a.pop() |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
157 a.pop() |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
158 a.pop() |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
159 if a != array.array(type, [1, 3, 4]): |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13069
diff
changeset
|
160 raise TestFailed, "array(%s) pop-test" % `type` |
|
8676
7d96842383bb
Add tests for array self-assigns. (This one has no relevance to JPython.)
Guido van Rossum <guido@python.org>
parents:
7747
diff
changeset
|
161 |
|
13069
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
162 # test that overflow exceptions are raised as expected for assignment |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
163 # to array of specific integral types |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
164 from math import pow |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
165 if type in ('b', 'h', 'i', 'l'): |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
166 # check signed and unsigned versions |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
167 a = array.array(type) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
168 signedLowerLimit = -1 * long(pow(2, a.itemsize * 8 - 1)) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
169 signedUpperLimit = long(pow(2, a.itemsize * 8 - 1)) - 1L |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
170 unsignedLowerLimit = 0 |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
171 unsignedUpperLimit = long(pow(2, a.itemsize * 8)) - 1L |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
172 testoverflow(type, signedLowerLimit, signedUpperLimit) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
173 testoverflow(type.upper(), unsignedLowerLimit, unsignedUpperLimit) |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
174 |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
175 |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
176 |
|
4811
9ae3cccfa7cd
Many scripts, but small changes. Update the way the scripts obtain the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4627
diff
changeset
|
177 main() |
|
13069
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
178 |
