Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_array.py @ 22360:c8a6ea00a9e1 legacy-trunk
restructure a bit to not rely on test case execution ordering
add test case for bug #482460
| author | Skip Montanaro <skip@pobox.com> |
|---|---|
| date | Sun, 17 Mar 2002 23:03:42 +0000 |
| parents | 966725095854 |
| children | 7e5141b68c5f |
| 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 |
|
15966
e59b835ad89a
a bold attempt to fix things broken by MAL's verify patch: import
Fredrik Lundh <fredrik@pythonware.com>
parents:
15957
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 testtype('c', 'c') |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
10 testtype('u', u'\u263a') |
|
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
|
11 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
|
12 testtype(type, 1) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
13 testunicode() |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
14 testsubclassing() |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
15 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
|
16 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
17 def testunicode(): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
18 try: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
19 array.array('b', u'foo') |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
20 except TypeError: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
21 pass |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
22 else: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
23 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
|
24 "a Unicode string should fail") |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
25 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
26 x = array.array('u', u'\xa0\xc2\u1234') |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
27 x.fromunicode(u' ') |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
28 x.fromunicode(u'') |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
29 x.fromunicode(u'') |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
30 x.fromunicode(u'\x11abc\xff\u1234') |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
31 s = x.tounicode() |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
32 if s != u'\xa0\xc2\u1234 \x11abc\xff\u1234': |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
33 raise TestFailed("fromunicode()/tounicode()") |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
34 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
35 s = u'\x00="\'a\\b\x80\xff\u0000\u0001\u1234' |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
36 a = array.array('u', s) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
37 if verbose: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
38 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
|
39 print " expected: array('u', %r)" % s |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
40 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
41 def testsubclassing(): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
42 class EditableString(array.array): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
43 def __new__(cls, s, *args, **kwargs): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
44 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
|
45 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
46 def __init__(self, s, color='blue'): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
47 array.array.__init__(self, 'c', s) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
48 self.color = color |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
49 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
50 def strip(self): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
51 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
|
52 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
53 def __repr__(self): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
54 return 'EditableString(%r)' % self.tostring() |
|
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 s = EditableString("\ttest\r\n") |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
57 s.strip() |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
58 if s.tostring() != 'test': |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
59 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
|
60 if s.color != 'blue': |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
61 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
|
62 s.color = 'red' |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
63 if s.color != 'red': |
|
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 if s.__dict__.keys() != ['color']: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
66 raise TestFailed, "array subclass __dict__" |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
67 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
68 class ExaggeratingArray(array.array): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
69 __slots__ = ['offset'] |
|
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 def __new__(cls, typecode, data, offset): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
72 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
|
73 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
74 def __init__(self, typecode, data, offset): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
75 self.offset = offset |
|
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 __getitem__(self, i): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
78 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
|
79 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
80 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
|
81 if a[0] != 7: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
82 raise TestFailed, "array subclass overriding __getitem__" |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
83 try: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
84 a.color = 'blue' |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
85 except AttributeError: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
86 pass |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
87 else: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
88 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
|
89 |
|
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
|
90 |
|
13069
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
91 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
|
92 # 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
|
93 if verbose: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
94 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
|
95 try: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
96 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
|
97 except: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
98 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
|
99 (`type`, `lowerLimit`) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
100 # 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
|
101 if verbose: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
102 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
|
103 try: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
104 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
|
105 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
|
106 (`type`, `lowerLimit-1`) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
107 except OverflowError: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
108 pass |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
109 # 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
|
110 if verbose: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
111 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
|
112 try: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
113 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
|
114 except: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
115 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
|
116 (`type`, `upperLimit`) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
117 # 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
|
118 if verbose: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
119 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
|
120 try: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
121 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
|
122 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
|
123 (`type`, `upperLimit+1`) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
124 except OverflowError: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
125 pass |
|
13069
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
126 |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
127 |
|
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
128 |
|
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
|
129 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
|
130 a = array.array(type) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
131 a.append(example) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
132 if verbose: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
133 print 40*'*' |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
134 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
|
135 a.typecode |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
136 a.itemsize |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
137 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
|
138 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
|
139 |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
140 if a.typecode == 'c': |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
141 f = open(TESTFN, "w") |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
142 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
|
143 f.close() |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
144 f = open(TESTFN, 'r') |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
145 a.fromfile(f, 10) |
|
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 if verbose: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
148 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
|
149 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
|
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 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
|
152 |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
153 a.insert(0, example) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
154 if verbose: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
155 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
|
156 f = open(TESTFN, 'w') |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
157 a.tofile(f) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
158 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
|
159 |
|
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
|
160 # 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
|
161 a.tolist() |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
162 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
|
163 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
|
164 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
|
165 |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
166 if verbose: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
167 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
|
168 if verbose: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
169 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
|
170 % 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
|
171 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
172 # Try out inplace addition and multiplication |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
173 a = array.array(type, [example]) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
174 b = a |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
175 a += array.array(type, [example]*2) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
176 if a is not b: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
177 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
|
178 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
|
179 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
|
180 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
181 a *= 5 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
182 if a is not b: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
183 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
|
184 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
|
185 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
|
186 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
187 a *= 0 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
188 if a is not b: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
189 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
|
190 if a != array.array(type, []): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
191 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
|
192 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
193 a *= 1000 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
194 if a is not b: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
195 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
|
196 if a != array.array(type, []): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
197 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
|
198 |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
199 if type == 'c': |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
200 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
|
201 a[:-1] = a |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
202 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
|
203 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
|
204 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
|
205 a[1:] = a |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
206 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
|
207 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
|
208 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
|
209 a[1:-1] = a |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 a.remove("e") |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 a.pop() |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
227 a.pop() |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
228 a.pop() |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
229 x = a.pop() |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
230 if x != 'e': |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
231 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
|
232 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
|
233 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
|
234 a.reverse() |
|
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, "dca"): |
|
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) reverse-test" % `type` |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
237 elif type == 'u': |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
238 a = array.array(type, u"abcde") |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
239 a[:-1] = a |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
240 if a != array.array(type, u"abcdee"): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
241 raise TestFailed, "array(%s) self-slice-assign (head)" % `type` |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
242 a = array.array(type, u"abcde") |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
243 a[1:] = a |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
244 if a != array.array(type, u"aabcde"): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
245 raise TestFailed, "array(%s) self-slice-assign (tail)" % `type` |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
246 a = array.array(type, u"abcde") |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
247 a[1:-1] = a |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
248 if a != array.array(type, u"aabcdee"): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
249 raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type` |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
250 if a.index(u"e") != 5: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
251 raise TestFailed, "array(%s) index-test" % `type` |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
252 if a.count(u"a") != 2: |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
253 raise TestFailed, "array(%s) count-test" % `type` |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
254 a.remove(u"e") |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
255 if a != array.array(type, u"aabcde"): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
256 raise TestFailed, "array(%s) remove-test" % `type` |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
257 if a.pop(0) != u"a": |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
258 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
|
259 if a.pop(1) != u"b": |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
260 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
|
261 a.extend(array.array(type, u"xyz")) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
262 if a != array.array(type, u"acdexyz"): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
263 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
|
264 a.pop() |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
265 a.pop() |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
266 a.pop() |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
267 x = a.pop() |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
268 if x != u'e': |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
269 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
|
270 if a != array.array(type, u"acd"): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
271 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
|
272 a.reverse() |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
273 if a != array.array(type, u"dca"): |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
274 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
|
275 else: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
276 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
|
277 a[:-1] = a |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 a[1:] = a |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
282 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
|
283 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
|
284 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
|
285 a[1:-1] = a |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 a.remove(5) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 a.pop() |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
303 a.pop() |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
304 a.pop() |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
305 x = a.pop() |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
306 if x != 5: |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
307 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
|
308 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
|
309 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
|
310 a.reverse() |
|
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, [4, 3, 1]): |
|
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) reverse-test" % `type` |
|
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
|
313 |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
314 # 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
|
315 # 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
|
316 from math import pow |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
317 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
|
318 # 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
|
319 a = array.array(type) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
320 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
|
321 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
|
322 unsignedLowerLimit = 0 |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
323 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
|
324 testoverflow(type, signedLowerLimit, signedUpperLimit) |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
325 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
|
326 |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
327 |
|
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
328 |
|
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
|
329 main() |
