Roger E. Masse | 8db1b07 | 1996-12-09 20:09:16 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | """Test the arraymodule. |
| 3 | Roger E. Masse |
| 4 | """ |
| 5 | import array |
| 6 | |
| 7 | def testtype(type, example): |
| 8 | |
| 9 | |
| 10 | a = array.array(type) |
| 11 | a.append(example) |
| 12 | #print 40*'*' |
| 13 | #print 'array after append: ', a |
| 14 | a.typecode |
| 15 | a.itemsize |
| 16 | if a.typecode in ('i', 'b', 'h', 'l'): |
| 17 | a.byteswap() |
| 18 | |
| 19 | if a.typecode == 'c': |
| 20 | f = open('/etc/passwd', 'r') |
| 21 | a.fromfile(f, 10) |
| 22 | #print 'char array with 10 bytes of /etc/passwd appended: ', a |
| 23 | a.fromlist(['a', 'b', 'c']) |
| 24 | #print 'char array with list appended: ', a |
| 25 | |
| 26 | a.insert(0, example) |
| 27 | #print 'array of %s after inserting another:' % a.typecode, a |
| 28 | f = open('/dev/null', 'w') |
| 29 | a.tofile(f) |
| 30 | a.tolist() |
| 31 | a.tostring() |
| 32 | #print 'array of %s converted to a list: ' % a.typecode, a.tolist() |
| 33 | #print 'array of %s converted to a string: ' % a.typecode, a.tostring() |
| 34 | |
| 35 | testtype('c', 'c') |
| 36 | |
| 37 | for type in (['b', 'h', 'i', 'l', 'f', 'd']): |
| 38 | testtype(type, 1) |
| 39 | |
| 40 | |