annotate Lib/test/test_array.py @ 28646:193b8aec00ce legacy-trunk

Changes from Jonathan Riehl to allow his pgen extension (PEP 269) to work. This includes some more code that used to be part of pgen in the main parser; I'm okay with that. I'll see if the Windows build needs work next.
author Guido van Rossum <guido@python.org>
date Thu, 17 Apr 2003 14:55:42 +0000
parents 047b6e16ab2e
children 7f0074ee8ab9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
24364
aa0d2d51fbde Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents: 23929
diff changeset
6 from test.test_support import verbose, TESTFN, unlink, TestFailed,\
23929
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
7 have_unicode, vereq
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
8
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 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
10 testtype('c', 'c')
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
11 if have_unicode:
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
12 testtype('u', unicode(r'\u263a', 'unicode-escape'))
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
13 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
14 testtype(type, 1)
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
15 if have_unicode:
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
16 testunicode()
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
17 testsubclassing()
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
18 unlink(TESTFN)
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
19
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
20 def testunicode():
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
21 try:
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
22 array.array('b', unicode('foo', 'ascii'))
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
23 except TypeError:
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
24 pass
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
25 else:
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
26 raise TestFailed("creating a non-unicode array from "
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
27 "a Unicode string should fail")
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
28
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
29 x = array.array('u', unicode(r'\xa0\xc2\u1234', 'unicode-escape'))
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
30 x.fromunicode(unicode(' ', 'ascii'))
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
31 x.fromunicode(unicode('', 'ascii'))
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
32 x.fromunicode(unicode('', 'ascii'))
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
33 x.fromunicode(unicode(r'\x11abc\xff\u1234', 'unicode-escape'))
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
34 s = x.tounicode()
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
35 if s != unicode(r'\xa0\xc2\u1234 \x11abc\xff\u1234', 'unicode-escape'):
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
36 raise TestFailed("fromunicode()/tounicode()")
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
37
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
38 s = unicode(r'\x00="\'a\\b\x80\xff\u0000\u0001\u1234', 'unicode-escape')
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
39 a = array.array('u', s)
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
40 if verbose:
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
41 print "repr of type 'u' array:", repr(a)
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
42 print " expected: array('u', %r)" % s
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
43
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
44 def testsubclassing():
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
45 class EditableString(array.array):
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
46 def __new__(cls, s, *args, **kwargs):
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
47 return array.array.__new__(cls, 'c', s)
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
48
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
49 def __init__(self, s, color='blue'):
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
50 array.array.__init__(self, 'c', s)
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
51 self.color = color
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
52
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
53 def strip(self):
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
54 self[:] = array.array('c', self.tostring().strip())
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
55
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
56 def __repr__(self):
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
57 return 'EditableString(%r)' % self.tostring()
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
58
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
59 s = EditableString("\ttest\r\n")
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
60 s.strip()
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
61 if s.tostring() != 'test':
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
62 raise TestFailed, "subclassing array.array failed somewhere"
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
63 if s.color != 'blue':
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
64 raise TestFailed, "assigning attributes to instance of array subclass"
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
65 s.color = 'red'
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
66 if s.color != 'red':
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
67 raise TestFailed, "assigning attributes to instance of array subclass"
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
68 if s.__dict__.keys() != ['color']:
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
69 raise TestFailed, "array subclass __dict__"
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
70
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
71 class ExaggeratingArray(array.array):
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
72 __slots__ = ['offset']
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
73
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
74 def __new__(cls, typecode, data, offset):
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
75 return array.array.__new__(cls, typecode, data)
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
76
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
77 def __init__(self, typecode, data, offset):
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
78 self.offset = offset
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
79
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
80 def __getitem__(self, i):
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
81 return array.array.__getitem__(self, i) + self.offset
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
82
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
83 a = ExaggeratingArray('i', [3, 6, 7, 11], 4)
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
84 if a[0] != 7:
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
85 raise TestFailed, "array subclass overriding __getitem__"
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
86 try:
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
87 a.color = 'blue'
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
88 except AttributeError:
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
89 pass
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
90 else:
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
91 raise TestFailed, "array subclass __slots__ was ignored"
5289
47d3d396d4ef Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents: 4811
diff changeset
92
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
93
13069
b76df68099a5 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 8676
diff changeset
94 def testoverflow(type, lowerLimit, upperLimit):
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
95 # should not overflow assigning lower limit
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
96 if verbose:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
97 print "overflow test: array(%s, [%s])" % (`type`, `lowerLimit`)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
98 try:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
99 a = array.array(type, [lowerLimit])
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
100 except:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
101 raise TestFailed, "array(%s) overflowed assigning %s" %\
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
102 (`type`, `lowerLimit`)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
103 # should overflow assigning less than lower limit
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
104 if verbose:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
105 print "overflow test: array(%s, [%s])" % (`type`, `lowerLimit-1`)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
106 try:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
107 a = array.array(type, [lowerLimit-1])
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
108 raise TestFailed, "array(%s) did not overflow assigning %s" %\
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
109 (`type`, `lowerLimit-1`)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
110 except OverflowError:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
111 pass
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
112 # should not overflow assigning upper limit
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
113 if verbose:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
114 print "overflow test: array(%s, [%s])" % (`type`, `upperLimit`)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
115 try:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
116 a = array.array(type, [upperLimit])
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
117 except:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
118 raise TestFailed, "array(%s) overflowed assigning %s" %\
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
119 (`type`, `upperLimit`)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
120 # should overflow assigning more than upper limit
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
121 if verbose:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
122 print "overflow test: array(%s, [%s])" % (`type`, `upperLimit+1`)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
123 try:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
124 a = array.array(type, [upperLimit+1])
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
125 raise TestFailed, "array(%s) did not overflow assigning %s" %\
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
126 (`type`, `upperLimit+1`)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
127 except OverflowError:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
128 pass
13069
b76df68099a5 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 8676
diff changeset
129
b76df68099a5 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 8676
diff changeset
130
b76df68099a5 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 8676
diff changeset
131
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
132 def testtype(type, example):
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
133 a = array.array(type)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
134 a.append(example)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
135 if verbose:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
136 print 40*'*'
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
137 print 'array after append: ', a
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
138 a.typecode
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
139 a.itemsize
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
140 if a.typecode in ('i', 'b', 'h', 'l'):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
141 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
142
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
143 if a.typecode == 'c':
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
144 f = open(TESTFN, "w")
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
145 f.write("The quick brown fox jumps over the lazy dog.\n")
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
146 f.close()
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
147 f = open(TESTFN, 'r')
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
148 a.fromfile(f, 10)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
149 f.close()
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
150 if verbose:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
151 print 'char array with 10 bytes of TESTFN appended: ', a
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
152 a.fromlist(['a', 'b', 'c'])
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
153 if verbose:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
154 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
155
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
156 a.insert(0, example)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
157 if verbose:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
158 print 'array of %s after inserting another:' % a.typecode, a
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
159 f = open(TESTFN, 'w')
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
160 a.tofile(f)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
161 f.close()
15409
99ca419ca58b Verify that str(a) and repr(a) don't blow up (part of SF patch 102068).
Tim Peters <tim.peters@gmail.com>
parents: 15305
diff changeset
162
99ca419ca58b Verify that str(a) and repr(a) don't blow up (part of SF patch 102068).
Tim Peters <tim.peters@gmail.com>
parents: 15305
diff changeset
163 # This block is just to verify that the operations don't blow up.
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
164 a.tolist()
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
165 a.tostring()
15409
99ca419ca58b Verify that str(a) and repr(a) don't blow up (part of SF patch 102068).
Tim Peters <tim.peters@gmail.com>
parents: 15305
diff changeset
166 repr(a)
99ca419ca58b Verify that str(a) and repr(a) don't blow up (part of SF patch 102068).
Tim Peters <tim.peters@gmail.com>
parents: 15305
diff changeset
167 str(a)
99ca419ca58b Verify that str(a) and repr(a) don't blow up (part of SF patch 102068).
Tim Peters <tim.peters@gmail.com>
parents: 15305
diff changeset
168
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
169 if verbose:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
170 print 'array of %s converted to a list: ' % a.typecode, a.tolist()
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
171 if verbose:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
172 print 'array of %s converted to a string: ' \
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
173 % 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
174
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
175 # Try out inplace addition and multiplication
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
176 a = array.array(type, [example])
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
177 b = a
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
178 a += array.array(type, [example]*2)
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
179 if a is not b:
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
180 raise TestFailed, "array(%s) inplace addition" % `type`
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
181 if a != array.array(type, [example] * 3):
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
182 raise TestFailed, "array(%s) inplace addition" % `type`
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
183
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
184 a *= 5
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
185 if a is not b:
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
186 raise TestFailed, "array(%s) inplace multiplication" % `type`
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
187 if a != array.array(type, [example] * 15):
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
188 raise TestFailed, "array(%s) inplace multiplication" % `type`
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
189
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
190 a *= 0
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
191 if a is not b:
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
192 raise TestFailed, "array(%s) inplace multiplication by 0" % `type`
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
193 if a != array.array(type, []):
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
194 raise TestFailed, "array(%s) inplace multiplication by 0" % `type`
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
195
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
196 a *= 1000
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
197 if a is not b:
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
198 raise TestFailed, "empty array(%s) inplace multiplication" % `type`
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
199 if a != array.array(type, []):
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
200 raise TestFailed, "empty array(%s) inplace multiplication" % `type`
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
201
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
202 if type == 'c':
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
203 a = array.array(type, "abcde")
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
204 a[:-1] = a
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
205 if a != array.array(type, "abcdee"):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
206 raise TestFailed, "array(%s) self-slice-assign (head)" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
207 a = array.array(type, "abcde")
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
208 a[1:] = a
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
209 if a != array.array(type, "aabcde"):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
210 raise TestFailed, "array(%s) self-slice-assign (tail)" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
211 a = array.array(type, "abcde")
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
212 a[1:-1] = a
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
213 if a != array.array(type, "aabcdee"):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
214 raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
215 if a.index("e") != 5:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
216 raise TestFailed, "array(%s) index-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
217 if a.count("a") != 2:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
218 raise TestFailed, "array(%s) count-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
219 a.remove("e")
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
220 if a != array.array(type, "aabcde"):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
221 raise TestFailed, "array(%s) remove-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
222 if a.pop(0) != "a":
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
223 raise TestFailed, "array(%s) pop-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
224 if a.pop(1) != "b":
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
225 raise TestFailed, "array(%s) pop-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
226 a.extend(array.array(type, "xyz"))
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
227 if a != array.array(type, "acdexyz"):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
228 raise TestFailed, "array(%s) extend-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
229 a.pop()
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
230 a.pop()
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
231 a.pop()
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
232 x = a.pop()
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
233 if x != 'e':
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
234 raise TestFailed, "array(%s) pop-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
235 if a != array.array(type, "acd"):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
236 raise TestFailed, "array(%s) pop-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
237 a.reverse()
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
238 if a != array.array(type, "dca"):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
239 raise TestFailed, "array(%s) reverse-test" % `type`
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
240 elif type == 'u':
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
241 a = array.array(type, unicode("abcde", 'ascii'))
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
242 a[:-1] = a
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
243 if a != array.array(type, unicode("abcdee", 'ascii')):
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
244 raise TestFailed, "array(%s) self-slice-assign (head)" % `type`
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
245 a = array.array(type, unicode("abcde", 'ascii'))
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
246 a[1:] = a
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
247 if a != array.array(type, unicode("aabcde", 'ascii')):
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
248 raise TestFailed, "array(%s) self-slice-assign (tail)" % `type`
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
249 a = array.array(type, unicode("abcde", 'ascii'))
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
250 a[1:-1] = a
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
251 if a != array.array(type, unicode("aabcdee", 'ascii')):
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
252 raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type`
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
253 if a.index(unicode("e", 'ascii')) != 5:
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
254 raise TestFailed, "array(%s) index-test" % `type`
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
255 if a.count(unicode("a", 'ascii')) != 2:
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
256 raise TestFailed, "array(%s) count-test" % `type`
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
257 a.remove(unicode("e", 'ascii'))
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
258 if a != array.array(type, unicode("aabcde", 'ascii')):
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
259 raise TestFailed, "array(%s) remove-test" % `type`
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
260 if a.pop(0) != unicode("a", 'ascii'):
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
261 raise TestFailed, "array(%s) pop-test" % `type`
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
262 if a.pop(1) != unicode("b", 'ascii'):
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
263 raise TestFailed, "array(%s) pop-test" % `type`
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
264 a.extend(array.array(type, unicode("xyz", 'ascii')))
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
265 if a != array.array(type, unicode("acdexyz", 'ascii')):
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
266 raise TestFailed, "array(%s) extend-test" % `type`
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
267 a.pop()
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
268 a.pop()
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
269 a.pop()
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
270 x = a.pop()
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
271 if x != unicode('e', 'ascii'):
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
272 raise TestFailed, "array(%s) pop-test" % `type`
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
273 if a != array.array(type, unicode("acd", 'ascii')):
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
274 raise TestFailed, "array(%s) pop-test" % `type`
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
275 a.reverse()
23459
7e5141b68c5f This is patch
Michael W. Hudson <mwh@python.net>
parents: 22098
diff changeset
276 if a != array.array(type, unicode("dca", 'ascii')):
22098
966725095854 Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents: 15966
diff changeset
277 raise TestFailed, "array(%s) reverse-test" % `type`
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
278 else:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
279 a = array.array(type, [1, 2, 3, 4, 5])
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
280 a[:-1] = a
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
281 if a != array.array(type, [1, 2, 3, 4, 5, 5]):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
282 raise TestFailed, "array(%s) self-slice-assign (head)" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
283 a = array.array(type, [1, 2, 3, 4, 5])
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
284 a[1:] = a
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
285 if a != array.array(type, [1, 1, 2, 3, 4, 5]):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
286 raise TestFailed, "array(%s) self-slice-assign (tail)" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
287 a = array.array(type, [1, 2, 3, 4, 5])
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
288 a[1:-1] = a
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
289 if a != array.array(type, [1, 1, 2, 3, 4, 5, 5]):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
290 raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
291 if a.index(5) != 5:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
292 raise TestFailed, "array(%s) index-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
293 if a.count(1) != 2:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
294 raise TestFailed, "array(%s) count-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
295 a.remove(5)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
296 if a != array.array(type, [1, 1, 2, 3, 4, 5]):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
297 raise TestFailed, "array(%s) remove-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
298 if a.pop(0) != 1:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
299 raise TestFailed, "array(%s) pop-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
300 if a.pop(1) != 2:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
301 raise TestFailed, "array(%s) pop-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
302 a.extend(array.array(type, [7, 8, 9]))
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
303 if a != array.array(type, [1, 3, 4, 5, 7, 8, 9]):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
304 raise TestFailed, "array(%s) extend-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
305 a.pop()
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
306 a.pop()
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
307 a.pop()
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
308 x = a.pop()
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
309 if x != 5:
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
310 raise TestFailed, "array(%s) pop-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
311 if a != array.array(type, [1, 3, 4]):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
312 raise TestFailed, "array(%s) pop-test" % `type`
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
313 a.reverse()
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
314 if a != array.array(type, [4, 3, 1]):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
315 raise TestFailed, "array(%s) reverse-test" % `type`
23929
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
316 # extended slicing
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
317 # subscription
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
318 a = array.array(type, [0,1,2,3,4])
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
319 vereq(a[::], a)
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
320 vereq(a[::2], array.array(type, [0,2,4]))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
321 vereq(a[1::2], array.array(type, [1,3]))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
322 vereq(a[::-1], array.array(type, [4,3,2,1,0]))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
323 vereq(a[::-2], array.array(type, [4,2,0]))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
324 vereq(a[3::-2], array.array(type, [3,1]))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
325 vereq(a[-100:100:], a)
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
326 vereq(a[100:-100:-1], a[::-1])
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
327 vereq(a[-100L:100L:2L], array.array(type, [0,2,4]))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
328 vereq(a[1000:2000:2], array.array(type, []))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
329 vereq(a[-1000:-2000:-2], array.array(type, []))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
330 # deletion
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
331 del a[::2]
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
332 vereq(a, array.array(type, [1,3]))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
333 a = array.array(type, range(5))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
334 del a[1::2]
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
335 vereq(a, array.array(type, [0,2,4]))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
336 a = array.array(type, range(5))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
337 del a[1::-2]
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
338 vereq(a, array.array(type, [0,2,3,4]))
24424
f4cd78b3b774 Fix for
Michael W. Hudson <mwh@python.net>
parents: 24364
diff changeset
339 a = array.array(type, range(10))
f4cd78b3b774 Fix for
Michael W. Hudson <mwh@python.net>
parents: 24364
diff changeset
340 del a[::1000]
f4cd78b3b774 Fix for
Michael W. Hudson <mwh@python.net>
parents: 24364
diff changeset
341 vereq(a, array.array(type, [1,2,3,4,5,6,7,8,9]))
23929
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
342 # assignment
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
343 a = array.array(type, range(10))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
344 a[::2] = array.array(type, [-1]*5)
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
345 vereq(a, array.array(type, [-1, 1, -1, 3, -1, 5, -1, 7, -1, 9]))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
346 a = array.array(type, range(10))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
347 a[::-4] = array.array(type, [10]*3)
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
348 vereq(a, array.array(type, [0, 10, 2, 3, 4, 10, 6, 7, 8 ,10]))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
349 a = array.array(type, range(4))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
350 a[::-1] = a
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
351 vereq(a, array.array(type, [3, 2, 1, 0]))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
352 a = array.array(type, range(10))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
353 b = a[:]
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
354 c = a[:]
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
355 ins = array.array(type, range(2))
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
356 a[2:3] = ins
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
357 b[slice(2,3)] = ins
26ba17b758b9 Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents: 23459
diff changeset
358 c[2:3:] = ins
27128
047b6e16ab2e SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents: 24424
diff changeset
359 # iteration and contains
047b6e16ab2e SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents: 24424
diff changeset
360 a = array.array(type, range(10))
047b6e16ab2e SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents: 24424
diff changeset
361 vereq(list(a), range(10))
047b6e16ab2e SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents: 24424
diff changeset
362 b = array.array(type, [20])
047b6e16ab2e SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents: 24424
diff changeset
363 vereq(a[-1] in a, True)
047b6e16ab2e SF patch #662433: Fill arraymodule's tp_iter and sq_contains slots
Raymond Hettinger <python@rcn.com>
parents: 24424
diff changeset
364 vereq(b[0] not in a, True)
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
365
15305
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
366 # test that overflow exceptions are raised as expected for assignment
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
367 # to array of specific integral types
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
368 from math import pow
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
369 if type in ('b', 'h', 'i', 'l'):
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
370 # check signed and unsigned versions
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
371 a = array.array(type)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
372 signedLowerLimit = -1 * long(pow(2, a.itemsize * 8 - 1))
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
373 signedUpperLimit = long(pow(2, a.itemsize * 8 - 1)) - 1L
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
374 unsignedLowerLimit = 0
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
375 unsignedUpperLimit = long(pow(2, a.itemsize * 8)) - 1L
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
376 testoverflow(type, signedLowerLimit, signedUpperLimit)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
377 testoverflow(type.upper(), unsignedLowerLimit, unsignedUpperLimit)
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
378
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
379
07f24261c6e6 Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents: 14649
diff changeset
380
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
381 main()