Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_array.py @ 6719:faebc1940432 legacy-trunk
Understand -Xlinker option.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 02 Dec 1997 20:38:11 +0000 |
| parents | d9e51451ebdf |
| children | aedd2d0dcb31 |
| 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 |
|
5289
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
6 from test_support import verbose, TESTFN, unlink |
|
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']): |
|
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
|
13 testtype(type, 1) |
|
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 |
|
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
20 a = array.array(type) |
|
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
21 a.append(example) |
|
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
|
22 if verbose: |
|
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
|
23 print 40*'*' |
|
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
|
24 print 'array after append: ', 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
|
25 a.typecode |
|
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
26 a.itemsize |
|
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
27 if a.typecode in ('i', 'b', 'h', 'l'): |
|
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
28 a.byteswap() |
|
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 |
|
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
30 if a.typecode == 'c': |
|
5289
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
31 f = open(TESTFN, "w") |
|
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
32 f.write("The quick brown fox jumps over the lazy dog.\n") |
|
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
33 f.close() |
|
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
34 f = open(TESTFN, 'r') |
|
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
|
35 a.fromfile(f, 10) |
|
5289
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
36 f.close() |
|
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
|
37 if verbose: |
|
5289
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
38 print 'char array with 10 bytes of TESTFN 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
|
39 a.fromlist(['a', 'b', 'c']) |
|
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
|
40 if verbose: |
|
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
|
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 |
|
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
43 a.insert(0, example) |
|
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
|
44 if verbose: |
|
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
|
45 print 'array of %s after inserting another:' % a.typecode, a |
|
5289
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
46 f = open(TESTFN, 'w') |
|
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
|
47 a.tofile(f) |
|
5289
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
48 f.close() |
|
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
|
49 a.tolist() |
|
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
50 a.tostring() |
|
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
|
51 if verbose: |
|
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
|
52 print 'array of %s converted to a list: ' % a.typecode, a.tolist() |
|
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
|
53 if verbose: |
|
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
|
54 print 'array of %s converted to a string: ' \ |
|
6441
d9e51451ebdf
Use `...` around binary strings.
Guido van Rossum <guido@python.org>
parents:
5289
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 |
|
5289
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
57 |
|
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
|
58 main() |
|
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
|
59 |
