Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_array.py @ 8831:00a6bb65ff29 legacy-trunk
Getting rid of this ancient stuff.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 05 Aug 1998 21:10:09 +0000 |
| parents | 7d96842383bb |
| children | b76df68099a5 |
| 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 |
|
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
18 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
|
19 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
20 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
|
21 a.append(example) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
22 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
23 print 40*'*' |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
24 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
|
25 a.typecode |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
26 a.itemsize |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
27 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
|
28 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
|
29 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
30 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
|
31 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
|
32 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
|
33 f.close() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
34 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
|
35 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
|
36 f.close() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
37 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
38 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
|
39 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
|
40 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
41 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
|
42 |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
43 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
|
44 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
45 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
|
46 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
|
47 a.tofile(f) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
48 f.close() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
49 a.tolist() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
50 a.tostring() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
51 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
52 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
|
53 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
54 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
|
55 % 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
|
56 |
|
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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 raise TestFailed, "array(%s) self-slice-assign (cntr)" % `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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 raise TestFailed, "array(%s) self-slice-assign (cntr)" % `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
|
83 |
|
5289
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
84 |
|
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
|
85 main() |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6441
diff
changeset
|
86 |
