blob: 74fcd45a603769cd1b1bb92c0b6bbaae499f7f23 [file] [log] [blame]
Guido van Rossum5de1f8d1996-12-10 16:02:14 +00001#! /usr/bin/env python
2"""Test the arraymodule.
3Roger E. Masse
4"""
5import array
6
7def 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
35testtype('c', 'c')
36
37for type in (['b', 'h', 'i', 'l', 'f', 'd']):
38 testtype(type, 1)
39
40