Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_array.py @ 81343:3a7cd8efc19f
#16852: merge with 3.3.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Thu, 10 Jan 2013 03:29:45 +0200 |
| parents | 7d69d04522e3 |
| children | 16c58eeca0f8 |
| rev | line source |
|---|---|
|
59522
fcfe324663a6
convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents:
58563
diff
changeset
|
1 #! /usr/bin/env python3 |
|
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
|
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 """ |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
5 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
6 import unittest |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46430
diff
changeset
|
7 from test import support |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
8 import weakref |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
9 import pickle |
|
50214
aebf7124dd32
Merged revisions 67840 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49490
diff
changeset
|
10 import operator |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
11 import io |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
12 import math |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
13 import struct |
|
64355
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
14 import warnings |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
15 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
16 import array |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
17 from array import _array_reconstructor as array_reconstructor |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
18 |
|
72430
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
19 try: |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
20 # Try to determine availability of long long independently |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
21 # of the array module under test |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
22 struct.calcsize('@q') |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
23 have_long_long = True |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
24 except struct.error: |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
25 have_long_long = False |
|
34174
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
26 |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
27 class ArraySubclass(array.array): |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
28 pass |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
29 |
|
40737
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40644
diff
changeset
|
30 class ArraySubclassWithKwargs(array.array): |
|
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40644
diff
changeset
|
31 def __init__(self, typecode, newarg=None): |
|
67334
d36e345a1a3c
test_array: fix the DeprecationWarning('object.__init__() takes no parameters')
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66818
diff
changeset
|
32 array.array.__init__(self) |
|
40737
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40644
diff
changeset
|
33 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
34 tests = [] # list to accumulate all tests |
|
42112
ebc87b94e6ea
"Fix" the array module test -- by ripping out the 'c' typecode.
Guido van Rossum <guido@python.org>
parents:
42084
diff
changeset
|
35 typecodes = "ubBhHiIlLfd" |
|
72430
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
36 if have_long_long: |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
37 typecodes += 'qQ' |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
38 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
39 class BadConstructorTest(unittest.TestCase): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
40 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
41 def test_constructor(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
42 self.assertRaises(TypeError, array.array) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
43 self.assertRaises(TypeError, array.array, spam=42) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
44 self.assertRaises(TypeError, array.array, 'xx') |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
45 self.assertRaises(ValueError, array.array, 'x') |
|
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
|
46 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
47 tests.append(BadConstructorTest) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
48 |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
49 # Machine format codes. |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
50 # |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
51 # Search for "enum machine_format_code" in Modules/arraymodule.c to get the |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
52 # authoritative values. |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
53 UNKNOWN_FORMAT = -1 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
54 UNSIGNED_INT8 = 0 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
55 SIGNED_INT8 = 1 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
56 UNSIGNED_INT16_LE = 2 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
57 UNSIGNED_INT16_BE = 3 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
58 SIGNED_INT16_LE = 4 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
59 SIGNED_INT16_BE = 5 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
60 UNSIGNED_INT32_LE = 6 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
61 UNSIGNED_INT32_BE = 7 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
62 SIGNED_INT32_LE = 8 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
63 SIGNED_INT32_BE = 9 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
64 UNSIGNED_INT64_LE = 10 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
65 UNSIGNED_INT64_BE = 11 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
66 SIGNED_INT64_LE = 12 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
67 SIGNED_INT64_BE = 13 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
68 IEEE_754_FLOAT_LE = 14 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
69 IEEE_754_FLOAT_BE = 15 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
70 IEEE_754_DOUBLE_LE = 16 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
71 IEEE_754_DOUBLE_BE = 17 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
72 UTF16_LE = 18 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
73 UTF16_BE = 19 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
74 UTF32_LE = 20 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
75 UTF32_BE = 21 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
76 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
77 class ArrayReconstructorTest(unittest.TestCase): |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
78 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
79 def test_error(self): |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
80 self.assertRaises(TypeError, array_reconstructor, |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
81 "", "b", 0, b"") |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
82 self.assertRaises(TypeError, array_reconstructor, |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
83 str, "b", 0, b"") |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
84 self.assertRaises(TypeError, array_reconstructor, |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
85 array.array, "b", '', b"") |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
86 self.assertRaises(TypeError, array_reconstructor, |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
87 array.array, "b", 0, "") |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
88 self.assertRaises(ValueError, array_reconstructor, |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
89 array.array, "?", 0, b"") |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
90 self.assertRaises(ValueError, array_reconstructor, |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
91 array.array, "b", UNKNOWN_FORMAT, b"") |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
92 self.assertRaises(ValueError, array_reconstructor, |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
93 array.array, "b", 22, b"") |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
94 self.assertRaises(ValueError, array_reconstructor, |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
95 array.array, "d", 16, b"a") |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
96 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
97 def test_numbers(self): |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
98 testcases = ( |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
99 (['B', 'H', 'I', 'L'], UNSIGNED_INT8, '=BBBB', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
100 [0x80, 0x7f, 0, 0xff]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
101 (['b', 'h', 'i', 'l'], SIGNED_INT8, '=bbb', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
102 [-0x80, 0x7f, 0]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
103 (['H', 'I', 'L'], UNSIGNED_INT16_LE, '<HHHH', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
104 [0x8000, 0x7fff, 0, 0xffff]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
105 (['H', 'I', 'L'], UNSIGNED_INT16_BE, '>HHHH', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
106 [0x8000, 0x7fff, 0, 0xffff]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
107 (['h', 'i', 'l'], SIGNED_INT16_LE, '<hhh', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
108 [-0x8000, 0x7fff, 0]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
109 (['h', 'i', 'l'], SIGNED_INT16_BE, '>hhh', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
110 [-0x8000, 0x7fff, 0]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
111 (['I', 'L'], UNSIGNED_INT32_LE, '<IIII', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
112 [1<<31, (1<<31)-1, 0, (1<<32)-1]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
113 (['I', 'L'], UNSIGNED_INT32_BE, '>IIII', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
114 [1<<31, (1<<31)-1, 0, (1<<32)-1]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
115 (['i', 'l'], SIGNED_INT32_LE, '<iii', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
116 [-1<<31, (1<<31)-1, 0]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
117 (['i', 'l'], SIGNED_INT32_BE, '>iii', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
118 [-1<<31, (1<<31)-1, 0]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
119 (['L'], UNSIGNED_INT64_LE, '<QQQQ', |
|
55264
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
120 [1<<31, (1<<31)-1, 0, (1<<32)-1]), |
|
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
121 (['L'], UNSIGNED_INT64_BE, '>QQQQ', |
|
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
122 [1<<31, (1<<31)-1, 0, (1<<32)-1]), |
|
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
123 (['l'], SIGNED_INT64_LE, '<qqq', |
|
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
124 [-1<<31, (1<<31)-1, 0]), |
|
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
125 (['l'], SIGNED_INT64_BE, '>qqq', |
|
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
126 [-1<<31, (1<<31)-1, 0]), |
|
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
127 # The following tests for INT64 will raise an OverflowError |
|
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
128 # when run on a 32-bit machine. The tests are simply skipped |
|
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
129 # in that case. |
|
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
130 (['L'], UNSIGNED_INT64_LE, '<QQQQ', |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
131 [1<<63, (1<<63)-1, 0, (1<<64)-1]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
132 (['L'], UNSIGNED_INT64_BE, '>QQQQ', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
133 [1<<63, (1<<63)-1, 0, (1<<64)-1]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
134 (['l'], SIGNED_INT64_LE, '<qqq', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
135 [-1<<63, (1<<63)-1, 0]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
136 (['l'], SIGNED_INT64_BE, '>qqq', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
137 [-1<<63, (1<<63)-1, 0]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
138 (['f'], IEEE_754_FLOAT_LE, '<ffff', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
139 [16711938.0, float('inf'), float('-inf'), -0.0]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
140 (['f'], IEEE_754_FLOAT_BE, '>ffff', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
141 [16711938.0, float('inf'), float('-inf'), -0.0]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
142 (['d'], IEEE_754_DOUBLE_LE, '<dddd', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
143 [9006104071832581.0, float('inf'), float('-inf'), -0.0]), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
144 (['d'], IEEE_754_DOUBLE_BE, '>dddd', |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
145 [9006104071832581.0, float('inf'), float('-inf'), -0.0]) |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
146 ) |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
147 for testcase in testcases: |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
148 valid_typecodes, mformat_code, struct_fmt, values = testcase |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
149 arraystr = struct.pack(struct_fmt, *values) |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
150 for typecode in valid_typecodes: |
|
55264
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
151 try: |
|
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
152 a = array.array(typecode, values) |
|
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
153 except OverflowError: |
|
bd431a0e6827
Don't check 64-bit test cases on 32-bit machine.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55259
diff
changeset
|
154 continue # Skip this test case. |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
155 b = array_reconstructor( |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
156 array.array, typecode, mformat_code, arraystr) |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
157 self.assertEqual(a, b, |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
158 msg="{0!r} != {1!r}; testcase={2!r}".format(a, b, testcase)) |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
159 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
160 def test_unicode(self): |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
161 teststr = "Bonne Journ\xe9e \U0002030a\U00020347" |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
162 testcases = ( |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
163 (UTF16_LE, "UTF-16-LE"), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
164 (UTF16_BE, "UTF-16-BE"), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
165 (UTF32_LE, "UTF-32-LE"), |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
166 (UTF32_BE, "UTF-32-BE") |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
167 ) |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
168 for testcase in testcases: |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
169 mformat_code, encoding = testcase |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
170 a = array.array('u', teststr) |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
171 b = array_reconstructor( |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
172 array.array, 'u', mformat_code, teststr.encode(encoding)) |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
173 self.assertEqual(a, b, |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
174 msg="{0!r} != {1!r}; testcase={2!r}".format(a, b, testcase)) |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
175 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
176 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
177 tests.append(ArrayReconstructorTest) |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
178 |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
179 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
180 class BaseTest(unittest.TestCase): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
181 # Required class attributes (provided by subclasses |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
182 # typecode: the typecode to test |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
183 # example: an initializer usable in the constructor for this type |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
184 # smallerexample: the same length as example, but smaller |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
185 # biggerexample: the same length as example, but bigger |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
186 # outside: An entry that is not in example |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
187 # minitemsize: the minimum guaranteed itemsize |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
188 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
189 def assertEntryEqual(self, entry1, entry2): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
190 self.assertEqual(entry1, entry2) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
191 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
192 def badtypecode(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
193 # Return a typecode that is different from our own |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
194 return typecodes[(typecodes.index(self.typecode)+1) % len(typecodes)] |
|
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
|
195 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
196 def test_constructor(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
197 a = array.array(self.typecode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
198 self.assertEqual(a.typecode, self.typecode) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
199 self.assertTrue(a.itemsize>=self.minitemsize) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
200 self.assertRaises(TypeError, array.array, self.typecode, None) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
201 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
202 def test_len(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
203 a = array.array(self.typecode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
204 a.append(self.example[0]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
205 self.assertEqual(len(a), 1) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
206 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
207 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
208 self.assertEqual(len(a), len(self.example)) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
209 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
210 def test_buffer_info(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
211 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
212 self.assertRaises(TypeError, a.buffer_info, 42) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
213 bi = a.buffer_info() |
|
58473
71acd4482e65
Merged revisions 77727 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55665
diff
changeset
|
214 self.assertIsInstance(bi, tuple) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
215 self.assertEqual(len(bi), 2) |
|
58473
71acd4482e65
Merged revisions 77727 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55665
diff
changeset
|
216 self.assertIsInstance(bi[0], int) |
|
71acd4482e65
Merged revisions 77727 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55665
diff
changeset
|
217 self.assertIsInstance(bi[1], int) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
218 self.assertEqual(bi[1], len(a)) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
219 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
220 def test_byteswap(self): |
|
72541
7fa098f6dc6a
array module uses the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72430
diff
changeset
|
221 if self.typecode == 'u': |
|
7fa098f6dc6a
array module uses the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72430
diff
changeset
|
222 example = '\U00100100' |
|
7fa098f6dc6a
array module uses the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72430
diff
changeset
|
223 else: |
|
7fa098f6dc6a
array module uses the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72430
diff
changeset
|
224 example = self.example |
|
7fa098f6dc6a
array module uses the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72430
diff
changeset
|
225 a = array.array(self.typecode, example) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
226 self.assertRaises(TypeError, a.byteswap, 42) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
227 if a.itemsize in (1, 2, 4, 8): |
|
72541
7fa098f6dc6a
array module uses the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72430
diff
changeset
|
228 b = array.array(self.typecode, example) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
229 b.byteswap() |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
230 if a.itemsize==1: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
231 self.assertEqual(a, b) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
232 else: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
233 self.assertNotEqual(a, b) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
234 b.byteswap() |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
235 self.assertEqual(a, b) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
236 |
|
31651
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30040
diff
changeset
|
237 def test_copy(self): |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30040
diff
changeset
|
238 import copy |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30040
diff
changeset
|
239 a = array.array(self.typecode, self.example) |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30040
diff
changeset
|
240 b = copy.copy(a) |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30040
diff
changeset
|
241 self.assertNotEqual(id(a), id(b)) |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30040
diff
changeset
|
242 self.assertEqual(a, b) |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30040
diff
changeset
|
243 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39543
diff
changeset
|
244 def test_deepcopy(self): |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39543
diff
changeset
|
245 import copy |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39543
diff
changeset
|
246 a = array.array(self.typecode, self.example) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39543
diff
changeset
|
247 b = copy.deepcopy(a) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39543
diff
changeset
|
248 self.assertNotEqual(id(a), id(b)) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39543
diff
changeset
|
249 self.assertEqual(a, b) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39543
diff
changeset
|
250 |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
251 def test_reduce_ex(self): |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
252 a = array.array(self.typecode, self.example) |
|
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
253 for protocol in range(3): |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64355
diff
changeset
|
254 self.assertIs(a.__reduce_ex__(protocol)[0], array.array) |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
255 for protocol in range(3, pickle.HIGHEST_PROTOCOL): |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64355
diff
changeset
|
256 self.assertIs(a.__reduce_ex__(protocol)[0], array_reconstructor) |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
257 |
|
34174
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
258 def test_pickle(self): |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
259 for protocol in range(pickle.HIGHEST_PROTOCOL + 1): |
|
34174
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
260 a = array.array(self.typecode, self.example) |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
261 b = pickle.loads(pickle.dumps(a, protocol)) |
|
34174
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
262 self.assertNotEqual(id(a), id(b)) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
263 self.assertEqual(a, b) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
264 |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
265 a = ArraySubclass(self.typecode, self.example) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
266 a.x = 10 |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
267 b = pickle.loads(pickle.dumps(a, protocol)) |
|
34174
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
268 self.assertNotEqual(id(a), id(b)) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
269 self.assertEqual(a, b) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
270 self.assertEqual(a.x, b.x) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
271 self.assertEqual(type(a), type(b)) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
272 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
273 def test_pickle_for_empty_array(self): |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
274 for protocol in range(pickle.HIGHEST_PROTOCOL + 1): |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
275 a = array.array(self.typecode) |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
276 b = pickle.loads(pickle.dumps(a, protocol)) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
277 self.assertNotEqual(id(a), id(b)) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
278 self.assertEqual(a, b) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
279 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
280 a = ArraySubclass(self.typecode) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
281 a.x = 10 |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
282 b = pickle.loads(pickle.dumps(a, protocol)) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
283 self.assertNotEqual(id(a), id(b)) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
284 self.assertEqual(a, b) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
285 self.assertEqual(a.x, b.x) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
286 self.assertEqual(type(a), type(b)) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41434
diff
changeset
|
287 |
|
76091
4ff234337e24
Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
73120
diff
changeset
|
288 def test_iterator_pickle(self): |
|
4ff234337e24
Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
73120
diff
changeset
|
289 data = array.array(self.typecode, self.example) |
|
4ff234337e24
Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
73120
diff
changeset
|
290 orgit = iter(data) |
|
4ff234337e24
Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
73120
diff
changeset
|
291 d = pickle.dumps(orgit) |
|
4ff234337e24
Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
73120
diff
changeset
|
292 it = pickle.loads(d) |
|
4ff234337e24
Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
73120
diff
changeset
|
293 self.assertEqual(type(orgit), type(it)) |
|
4ff234337e24
Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
73120
diff
changeset
|
294 self.assertEqual(list(it), list(data)) |
|
4ff234337e24
Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
73120
diff
changeset
|
295 |
|
4ff234337e24
Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
73120
diff
changeset
|
296 if len(data): |
|
4ff234337e24
Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
73120
diff
changeset
|
297 it = pickle.loads(d) |
|
4ff234337e24
Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
73120
diff
changeset
|
298 next(it) |
|
4ff234337e24
Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
73120
diff
changeset
|
299 d = pickle.dumps(it) |
|
4ff234337e24
Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
73120
diff
changeset
|
300 self.assertEqual(list(it), list(data)[1:]) |
|
4ff234337e24
Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
73120
diff
changeset
|
301 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
302 def test_insert(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
303 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
304 a.insert(0, self.example[0]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
305 self.assertEqual(len(a), 1+len(self.example)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
306 self.assertEqual(a[0], a[1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
307 self.assertRaises(TypeError, a.insert) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
308 self.assertRaises(TypeError, a.insert, None) |
|
29158
001d3c7e9637
Add another error case to the insert test.
Walter Dörwald <walter@livinglogic.de>
parents:
29157
diff
changeset
|
309 self.assertRaises(TypeError, a.insert, 0, None) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
310 |
|
29163
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
311 a = array.array(self.typecode, self.example) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
312 a.insert(-1, self.example[0]) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
313 self.assertEqual( |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
314 a, |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
315 array.array( |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
316 self.typecode, |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
317 self.example[:-1] + self.example[:1] + self.example[-1:] |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
318 ) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
319 ) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
320 |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
321 a = array.array(self.typecode, self.example) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
322 a.insert(-1000, self.example[0]) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
323 self.assertEqual( |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
324 a, |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
325 array.array(self.typecode, self.example[:1] + self.example) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
326 ) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
327 |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
328 a = array.array(self.typecode, self.example) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
329 a.insert(1000, self.example[0]) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
330 self.assertEqual( |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
331 a, |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
332 array.array(self.typecode, self.example + self.example[:1]) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
333 ) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
334 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
335 def test_tofromfile(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
336 a = array.array(self.typecode, 2*self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
337 self.assertRaises(TypeError, a.tofile) |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46430
diff
changeset
|
338 support.unlink(support.TESTFN) |
|
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46430
diff
changeset
|
339 f = open(support.TESTFN, 'wb') |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
340 try: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
341 a.tofile(f) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
342 f.close() |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
343 b = array.array(self.typecode) |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46430
diff
changeset
|
344 f = open(support.TESTFN, 'rb') |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
345 self.assertRaises(TypeError, b.fromfile) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
346 b.fromfile(f, len(self.example)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
347 self.assertEqual(b, array.array(self.typecode, self.example)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
348 self.assertNotEqual(a, b) |
|
52041
4a3b44c21b4f
Merged revisions 70203 via svnmerge from
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents:
51117
diff
changeset
|
349 self.assertRaises(EOFError, b.fromfile, f, len(self.example)+1) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
350 self.assertEqual(a, b) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
351 f.close() |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
352 finally: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
353 if not f.closed: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
354 f.close() |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46430
diff
changeset
|
355 support.unlink(support.TESTFN) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
356 |
|
63131
520bf4d1cb66
Merged revisions 83030 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58564
diff
changeset
|
357 def test_fromfile_ioerror(self): |
|
81039
7d69d04522e3
Replace IOError with OSError (#16715)
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
78494
diff
changeset
|
358 # Issue #5395: Check if fromfile raises a proper OSError |
|
63131
520bf4d1cb66
Merged revisions 83030 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58564
diff
changeset
|
359 # instead of EOFError. |
|
520bf4d1cb66
Merged revisions 83030 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58564
diff
changeset
|
360 a = array.array(self.typecode) |
|
520bf4d1cb66
Merged revisions 83030 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58564
diff
changeset
|
361 f = open(support.TESTFN, 'wb') |
|
520bf4d1cb66
Merged revisions 83030 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58564
diff
changeset
|
362 try: |
|
81039
7d69d04522e3
Replace IOError with OSError (#16715)
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
78494
diff
changeset
|
363 self.assertRaises(OSError, a.fromfile, f, len(self.example)) |
|
63131
520bf4d1cb66
Merged revisions 83030 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58564
diff
changeset
|
364 finally: |
|
520bf4d1cb66
Merged revisions 83030 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58564
diff
changeset
|
365 f.close() |
|
520bf4d1cb66
Merged revisions 83030 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58564
diff
changeset
|
366 support.unlink(support.TESTFN) |
|
520bf4d1cb66
Merged revisions 83030 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58564
diff
changeset
|
367 |
|
55665
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
368 def test_filewrite(self): |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
369 a = array.array(self.typecode, 2*self.example) |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
370 f = open(support.TESTFN, 'wb') |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
371 try: |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
372 f.write(a) |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
373 f.close() |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
374 b = array.array(self.typecode) |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
375 f = open(support.TESTFN, 'rb') |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
376 b.fromfile(f, len(self.example)) |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
377 self.assertEqual(b, array.array(self.typecode, self.example)) |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
378 self.assertNotEqual(a, b) |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
379 b.fromfile(f, len(self.example)) |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
380 self.assertEqual(a, b) |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
381 f.close() |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
382 finally: |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
383 if not f.closed: |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
384 f.close() |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
385 support.unlink(support.TESTFN) |
|
495eeff3b9ff
Merged revisions 74477 via svnmerge from
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55264
diff
changeset
|
386 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
387 def test_tofromlist(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
388 a = array.array(self.typecode, 2*self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
389 b = array.array(self.typecode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
390 self.assertRaises(TypeError, a.tolist, 42) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
391 self.assertRaises(TypeError, b.fromlist) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
392 self.assertRaises(TypeError, b.fromlist, 42) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
393 self.assertRaises(TypeError, b.fromlist, [None]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
394 b.fromlist(a.tolist()) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
395 self.assertEqual(a, b) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
396 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
397 def test_tofromstring(self): |
|
64355
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
398 nb_warnings = 4 |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
399 with warnings.catch_warnings(record=True) as r: |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
400 warnings.filterwarnings("always", |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
401 message=r"(to|from)string\(\) is deprecated", |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
402 category=DeprecationWarning) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
403 a = array.array(self.typecode, 2*self.example) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
404 b = array.array(self.typecode) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
405 self.assertRaises(TypeError, a.tostring, 42) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
406 self.assertRaises(TypeError, b.fromstring) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
407 self.assertRaises(TypeError, b.fromstring, 42) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
408 b.fromstring(a.tostring()) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
409 self.assertEqual(a, b) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
410 if a.itemsize>1: |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
411 self.assertRaises(ValueError, b.fromstring, "x") |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
412 nb_warnings += 1 |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
413 self.assertEqual(len(r), nb_warnings) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
414 |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
415 def test_tofrombytes(self): |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
416 a = array.array(self.typecode, 2*self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
417 b = array.array(self.typecode) |
|
64355
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
418 self.assertRaises(TypeError, a.tobytes, 42) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
419 self.assertRaises(TypeError, b.frombytes) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
420 self.assertRaises(TypeError, b.frombytes, 42) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
421 b.frombytes(a.tobytes()) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
422 c = array.array(self.typecode, bytearray(a.tobytes())) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
423 self.assertEqual(a, b) |
|
64355
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
424 self.assertEqual(a, c) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
425 if a.itemsize>1: |
|
64355
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
426 self.assertRaises(ValueError, b.frombytes, b"x") |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
427 |
|
67537
2581a17b29af
Issue #5109: array.array constructor will now use fast code when
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67334
diff
changeset
|
428 def test_fromarray(self): |
|
2581a17b29af
Issue #5109: array.array constructor will now use fast code when
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67334
diff
changeset
|
429 a = array.array(self.typecode, self.example) |
|
2581a17b29af
Issue #5109: array.array constructor will now use fast code when
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67334
diff
changeset
|
430 b = array.array(self.typecode, a) |
|
2581a17b29af
Issue #5109: array.array constructor will now use fast code when
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67334
diff
changeset
|
431 self.assertEqual(a, b) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
432 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
433 def test_repr(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
434 a = array.array(self.typecode, 2*self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
435 self.assertEqual(a, eval(repr(a), {"array": array.array})) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
436 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
437 a = array.array(self.typecode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
438 self.assertEqual(repr(a), "array('%s')" % self.typecode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
439 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
440 def test_str(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
441 a = array.array(self.typecode, 2*self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
442 str(a) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
443 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
444 def test_cmp(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
445 a = array.array(self.typecode, self.example) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
446 self.assertTrue((a == 42) is False) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
447 self.assertTrue((a != 42) is True) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
448 |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
449 self.assertTrue((a == a) is True) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
450 self.assertTrue((a != a) is False) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
451 self.assertTrue((a < a) is False) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
452 self.assertTrue((a <= a) is True) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
453 self.assertTrue((a > a) is False) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
454 self.assertTrue((a >= a) is True) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
455 |
|
37055
fdc05b167236
as is on the road to keyword-hood, use a different var name.
Neal Norwitz <nnorwitz@gmail.com>
parents:
34479
diff
changeset
|
456 al = array.array(self.typecode, self.smallerexample) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
457 ab = array.array(self.typecode, self.biggerexample) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
458 |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
459 self.assertTrue((a == 2*a) is False) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
460 self.assertTrue((a != 2*a) is True) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
461 self.assertTrue((a < 2*a) is True) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
462 self.assertTrue((a <= 2*a) is True) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
463 self.assertTrue((a > 2*a) is False) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
464 self.assertTrue((a >= 2*a) is False) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
465 |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
466 self.assertTrue((a == al) is False) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
467 self.assertTrue((a != al) is True) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
468 self.assertTrue((a < al) is False) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
469 self.assertTrue((a <= al) is False) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
470 self.assertTrue((a > al) is True) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
471 self.assertTrue((a >= al) is True) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
472 |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
473 self.assertTrue((a == ab) is False) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
474 self.assertTrue((a != ab) is True) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
475 self.assertTrue((a < ab) is True) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
476 self.assertTrue((a <= ab) is True) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
477 self.assertTrue((a > ab) is False) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
478 self.assertTrue((a >= ab) is False) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
479 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
480 def test_add(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
481 a = array.array(self.typecode, self.example) \ |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
482 + array.array(self.typecode, self.example[::-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
483 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
484 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
485 array.array(self.typecode, self.example + self.example[::-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
486 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
487 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
488 b = array.array(self.badtypecode()) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
489 self.assertRaises(TypeError, a.__add__, b) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
490 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
491 self.assertRaises(TypeError, a.__add__, "bad") |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
492 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
493 def test_iadd(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
494 a = array.array(self.typecode, self.example[::-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
495 b = a |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
496 a += array.array(self.typecode, 2*self.example) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
497 self.assertTrue(a is b) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
498 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
499 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
500 array.array(self.typecode, self.example[::-1]+2*self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
501 ) |
|
55602
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
502 a = array.array(self.typecode, self.example) |
|
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
503 a += a |
|
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
504 self.assertEqual( |
|
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
505 a, |
|
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
506 array.array(self.typecode, self.example + self.example) |
|
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
507 ) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
508 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
509 b = array.array(self.badtypecode()) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
510 self.assertRaises(TypeError, a.__add__, b) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
511 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
512 self.assertRaises(TypeError, a.__iadd__, "bad") |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
513 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
514 def test_mul(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
515 a = 5*array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
516 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
517 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
518 array.array(self.typecode, 5*self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
519 ) |
|
5289
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
520 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
521 a = array.array(self.typecode, self.example)*5 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
522 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
523 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
524 array.array(self.typecode, self.example*5) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
525 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
526 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
527 a = 0*array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
528 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
529 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
530 array.array(self.typecode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
531 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
532 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
533 a = (-1)*array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
534 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
535 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
536 array.array(self.typecode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
537 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
538 |
|
66688
48c40709417b
#1569291: speed up array.repeat() by making only O(log n) memcpy() calls; the code follows unicode_repeat.
Georg Brandl <georg@python.org>
parents:
66310
diff
changeset
|
539 a = 5 * array.array(self.typecode, self.example[:1]) |
|
48c40709417b
#1569291: speed up array.repeat() by making only O(log n) memcpy() calls; the code follows unicode_repeat.
Georg Brandl <georg@python.org>
parents:
66310
diff
changeset
|
540 self.assertEqual( |
|
48c40709417b
#1569291: speed up array.repeat() by making only O(log n) memcpy() calls; the code follows unicode_repeat.
Georg Brandl <georg@python.org>
parents:
66310
diff
changeset
|
541 a, |
|
48c40709417b
#1569291: speed up array.repeat() by making only O(log n) memcpy() calls; the code follows unicode_repeat.
Georg Brandl <georg@python.org>
parents:
66310
diff
changeset
|
542 array.array(self.typecode, [a[0]] * 5) |
|
48c40709417b
#1569291: speed up array.repeat() by making only O(log n) memcpy() calls; the code follows unicode_repeat.
Georg Brandl <georg@python.org>
parents:
66310
diff
changeset
|
543 ) |
|
48c40709417b
#1569291: speed up array.repeat() by making only O(log n) memcpy() calls; the code follows unicode_repeat.
Georg Brandl <georg@python.org>
parents:
66310
diff
changeset
|
544 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
545 self.assertRaises(TypeError, a.__mul__, "bad") |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
546 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
547 def test_imul(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
548 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
549 b = a |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
550 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
551 a *= 5 |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
552 self.assertTrue(a is b) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
553 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
554 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
555 array.array(self.typecode, 5*self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
556 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
557 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
558 a *= 0 |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
559 self.assertTrue(a is b) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
560 self.assertEqual(a, array.array(self.typecode)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
561 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
562 a *= 1000 |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
563 self.assertTrue(a is b) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
564 self.assertEqual(a, array.array(self.typecode)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
565 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
566 a *= -1 |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52041
diff
changeset
|
567 self.assertTrue(a is b) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
568 self.assertEqual(a, array.array(self.typecode)) |
|
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
|
569 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
570 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
571 a *= -1 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
572 self.assertEqual(a, array.array(self.typecode)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
573 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
574 self.assertRaises(TypeError, a.__imul__, "bad") |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
575 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
576 def test_getitem(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
577 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
578 self.assertEntryEqual(a[0], self.example[0]) |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
579 self.assertEntryEqual(a[0], self.example[0]) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
580 self.assertEntryEqual(a[-1], self.example[-1]) |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
581 self.assertEntryEqual(a[-1], self.example[-1]) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
582 self.assertEntryEqual(a[len(self.example)-1], self.example[-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
583 self.assertEntryEqual(a[-len(self.example)], self.example[0]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
584 self.assertRaises(TypeError, a.__getitem__) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
585 self.assertRaises(IndexError, a.__getitem__, len(self.example)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
586 self.assertRaises(IndexError, a.__getitem__, -len(self.example)-1) |
|
13069
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
587 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
588 def test_setitem(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
589 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
590 a[0] = a[-1] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
591 self.assertEntryEqual(a[0], a[-1]) |
|
13069
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
592 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
593 a = array.array(self.typecode, self.example) |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
594 a[0] = a[-1] |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
595 self.assertEntryEqual(a[0], a[-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
596 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
597 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
598 a[-1] = a[0] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
599 self.assertEntryEqual(a[0], a[-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
600 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
601 a = array.array(self.typecode, self.example) |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
602 a[-1] = a[0] |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
603 self.assertEntryEqual(a[0], a[-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
604 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
605 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
606 a[len(self.example)-1] = a[0] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
607 self.assertEntryEqual(a[0], a[-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
608 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
609 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
610 a[-len(self.example)] = a[-1] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
611 self.assertEntryEqual(a[0], a[-1]) |
|
13069
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
612 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
613 self.assertRaises(TypeError, a.__setitem__) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
614 self.assertRaises(TypeError, a.__setitem__, None) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
615 self.assertRaises(TypeError, a.__setitem__, 0, None) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
616 self.assertRaises( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
617 IndexError, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
618 a.__setitem__, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
619 len(self.example), self.example[0] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
620 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
621 self.assertRaises( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
622 IndexError, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
623 a.__setitem__, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
624 -len(self.example)-1, self.example[0] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
625 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
626 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
627 def test_delitem(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
628 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
629 del a[0] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
630 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
631 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
632 array.array(self.typecode, self.example[1:]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
633 ) |
|
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
|
634 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
635 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
636 del a[-1] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
637 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
638 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
639 array.array(self.typecode, self.example[:-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
640 ) |
|
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
|
641 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
642 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
643 del a[len(self.example)-1] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
644 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
645 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
646 array.array(self.typecode, self.example[:-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
647 ) |
|
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
|
648 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
649 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
650 del a[-len(self.example)] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
651 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
652 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
653 array.array(self.typecode, self.example[1:]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
654 ) |
|
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
|
655 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
656 self.assertRaises(TypeError, a.__delitem__) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
657 self.assertRaises(TypeError, a.__delitem__, None) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
658 self.assertRaises(IndexError, a.__delitem__, len(self.example)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
659 self.assertRaises(IndexError, a.__delitem__, -len(self.example)-1) |
|
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
|
660 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
661 def test_getslice(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
662 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
663 self.assertEqual(a[:], a) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
664 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
665 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
666 a[1:], |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
667 array.array(self.typecode, self.example[1:]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
668 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
669 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
670 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
671 a[:1], |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
672 array.array(self.typecode, self.example[:1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
673 ) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
674 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
675 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
676 a[:-1], |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
677 array.array(self.typecode, self.example[:-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
678 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
679 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
680 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
681 a[-1:], |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
682 array.array(self.typecode, self.example[-1:]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
683 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
684 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
685 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
686 a[-1:-1], |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
687 array.array(self.typecode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
688 ) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
689 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
690 self.assertEqual( |
|
34479
b9bc49b53f4d
Add a slice test with high < low.
Walter Dörwald <walter@livinglogic.de>
parents:
34174
diff
changeset
|
691 a[2:1], |
|
b9bc49b53f4d
Add a slice test with high < low.
Walter Dörwald <walter@livinglogic.de>
parents:
34174
diff
changeset
|
692 array.array(self.typecode) |
|
b9bc49b53f4d
Add a slice test with high < low.
Walter Dörwald <walter@livinglogic.de>
parents:
34174
diff
changeset
|
693 ) |
|
b9bc49b53f4d
Add a slice test with high < low.
Walter Dörwald <walter@livinglogic.de>
parents:
34174
diff
changeset
|
694 |
|
b9bc49b53f4d
Add a slice test with high < low.
Walter Dörwald <walter@livinglogic.de>
parents:
34174
diff
changeset
|
695 self.assertEqual( |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
696 a[1000:], |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
697 array.array(self.typecode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
698 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
699 self.assertEqual(a[-1000:], a) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
700 self.assertEqual(a[:1000], a) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
701 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
702 a[:-1000], |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
703 array.array(self.typecode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
704 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
705 self.assertEqual(a[-1000:1000], a) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
706 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
707 a[2000:1000], |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
708 array.array(self.typecode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
709 ) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
710 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
711 def test_extended_getslice(self): |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
712 # Test extended slicing by comparing with list slicing |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
713 # (Assumes list conversion works correctly, too) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
714 a = array.array(self.typecode, self.example) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
715 indices = (0, None, 1, 3, 19, 100, -1, -2, -31, -100) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
716 for start in indices: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
717 for stop in indices: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
718 # Everything except the initial 0 (invalid step) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
719 for step in indices[1:]: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
720 self.assertEqual(list(a[start:stop:step]), |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
721 list(a)[start:stop:step]) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
722 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
723 def test_setslice(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
724 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
725 a[:1] = a |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
726 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
727 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
728 array.array(self.typecode, self.example + self.example[1:]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
729 ) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
730 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
731 a = array.array(self.typecode, self.example) |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
732 a[:-1] = a |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
733 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
734 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
735 array.array(self.typecode, self.example + self.example[-1:]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
736 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
737 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
738 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
739 a[-1:] = a |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
740 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
741 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
742 array.array(self.typecode, self.example[:-1] + self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
743 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
744 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
745 a = array.array(self.typecode, self.example) |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
746 a[1:] = a |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
747 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
748 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
749 array.array(self.typecode, self.example[:1] + self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
750 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
751 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
752 a = array.array(self.typecode, self.example) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
753 a[1:-1] = a |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
754 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
755 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
756 array.array( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
757 self.typecode, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
758 self.example[:1] + self.example + self.example[-1:] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
759 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
760 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
761 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
762 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
763 a[1000:] = a |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
764 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
765 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
766 array.array(self.typecode, 2*self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
767 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
768 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
769 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
770 a[-1000:] = a |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
771 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
772 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
773 array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
774 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
775 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
776 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
777 a[:1000] = a |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
778 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
779 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
780 array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
781 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
782 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
783 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
784 a[:-1000] = a |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
785 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
786 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
787 array.array(self.typecode, 2*self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
788 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
789 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
790 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
791 a[1:0] = a |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
792 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
793 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
794 array.array(self.typecode, self.example[:1] + self.example + self.example[1:]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
795 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
796 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
797 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
798 a[2000:1000] = a |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
799 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
800 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
801 array.array(self.typecode, 2*self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
802 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
803 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
804 a = array.array(self.typecode, self.example) |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
805 self.assertRaises(TypeError, a.__setitem__, slice(0, 0), None) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
806 self.assertRaises(TypeError, a.__setitem__, slice(0, 1), None) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
807 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
808 b = array.array(self.badtypecode()) |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
809 self.assertRaises(TypeError, a.__setitem__, slice(0, 0), b) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
810 self.assertRaises(TypeError, a.__setitem__, slice(0, 1), b) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
811 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
812 def test_extended_set_del_slice(self): |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
813 indices = (0, None, 1, 3, 19, 100, -1, -2, -31, -100) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
814 for start in indices: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
815 for stop in indices: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
816 # Everything except the initial 0 (invalid step) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
817 for step in indices[1:]: |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
818 a = array.array(self.typecode, self.example) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
819 L = list(a) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
820 # Make sure we have a slice of exactly the right length, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
821 # but with (hopefully) different data. |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
822 data = L[start:stop:step] |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
823 data.reverse() |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
824 L[start:stop:step] = data |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
825 a[start:stop:step] = array.array(self.typecode, data) |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
63131
diff
changeset
|
826 self.assertEqual(a, array.array(self.typecode, L)) |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
827 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
828 del L[start:stop:step] |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
829 del a[start:stop:step] |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
63131
diff
changeset
|
830 self.assertEqual(a, array.array(self.typecode, L)) |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42145
diff
changeset
|
831 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
832 def test_index(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
833 example = 2*self.example |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
834 a = array.array(self.typecode, example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
835 self.assertRaises(TypeError, a.index) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
836 for x in example: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
837 self.assertEqual(a.index(x), example.index(x)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
838 self.assertRaises(ValueError, a.index, None) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
839 self.assertRaises(ValueError, a.index, self.outside) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
840 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
841 def test_count(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
842 example = 2*self.example |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
843 a = array.array(self.typecode, example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
844 self.assertRaises(TypeError, a.count) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
845 for x in example: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
846 self.assertEqual(a.count(x), example.count(x)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
847 self.assertEqual(a.count(self.outside), 0) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
848 self.assertEqual(a.count(None), 0) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
849 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
850 def test_remove(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
851 for x in self.example: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
852 example = 2*self.example |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
853 a = array.array(self.typecode, example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
854 pos = example.index(x) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
855 example2 = example[:pos] + example[pos+1:] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
856 a.remove(x) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
857 self.assertEqual(a, array.array(self.typecode, example2)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
858 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
859 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
860 self.assertRaises(ValueError, a.remove, self.outside) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
861 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
862 self.assertRaises(ValueError, a.remove, None) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
863 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
864 def test_pop(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
865 a = array.array(self.typecode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
866 self.assertRaises(IndexError, a.pop) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
867 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
868 a = array.array(self.typecode, 2*self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
869 self.assertRaises(TypeError, a.pop, 42, 42) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
870 self.assertRaises(TypeError, a.pop, None) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
871 self.assertRaises(IndexError, a.pop, len(a)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
872 self.assertRaises(IndexError, a.pop, -len(a)-1) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
873 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
874 self.assertEntryEqual(a.pop(0), self.example[0]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
875 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
876 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
877 array.array(self.typecode, self.example[1:]+self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
878 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
879 self.assertEntryEqual(a.pop(1), self.example[2]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
880 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
881 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
882 array.array(self.typecode, self.example[1:2]+self.example[3:]+self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
883 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
884 self.assertEntryEqual(a.pop(0), self.example[1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
885 self.assertEntryEqual(a.pop(), self.example[-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
886 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
887 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
888 array.array(self.typecode, self.example[3:]+self.example[:-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
889 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
890 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
891 def test_reverse(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
892 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
893 self.assertRaises(TypeError, a.reverse, 42) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
894 a.reverse() |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
895 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
896 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
897 array.array(self.typecode, self.example[::-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
898 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
899 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
900 def test_extend(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
901 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
902 self.assertRaises(TypeError, a.extend) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
903 a.extend(array.array(self.typecode, self.example[::-1])) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
904 self.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
905 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
906 array.array(self.typecode, self.example+self.example[::-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
907 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
908 |
|
55602
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
909 a = array.array(self.typecode, self.example) |
|
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
910 a.extend(a) |
|
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
911 self.assertEqual( |
|
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
912 a, |
|
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
913 array.array(self.typecode, self.example+self.example) |
|
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
914 ) |
|
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
915 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
916 b = array.array(self.badtypecode()) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
917 self.assertRaises(TypeError, a.extend, b) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
918 |
|
31660
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
919 a = array.array(self.typecode, self.example) |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
920 a.extend(self.example[::-1]) |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
921 self.assertEqual( |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
922 a, |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
923 array.array(self.typecode, self.example+self.example[::-1]) |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
924 ) |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
925 |
|
33316
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
926 def test_constructor_with_iterable_argument(self): |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
927 a = array.array(self.typecode, iter(self.example)) |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
928 b = array.array(self.typecode, self.example) |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
929 self.assertEqual(a, b) |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
930 |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
931 # non-iterable argument |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
932 self.assertRaises(TypeError, array.array, self.typecode, 10) |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
933 |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
934 # pass through errors raised in __iter__ |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
935 class A: |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
936 def __iter__(self): |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
937 raise UnicodeError |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
938 self.assertRaises(UnicodeError, array.array, self.typecode, A()) |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
939 |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
940 # pass through errors raised in next() |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
941 def B(): |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
942 raise UnicodeError |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
943 yield None |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
944 self.assertRaises(UnicodeError, array.array, self.typecode, B()) |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
945 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
946 def test_coveritertraverse(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
947 try: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
948 import gc |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
949 except ImportError: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
950 return |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
951 a = array.array(self.typecode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
952 l = [iter(a)] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
953 l.append(l) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
954 gc.collect() |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
955 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
956 def test_buffer(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
957 a = array.array(self.typecode, self.example) |
|
50214
aebf7124dd32
Merged revisions 67840 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49490
diff
changeset
|
958 m = memoryview(a) |
|
55603
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
959 expected = m.tobytes() |
|
64355
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
960 self.assertEqual(a.tobytes(), expected) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
961 self.assertEqual(a.tobytes()[0], expected[0]) |
|
55603
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
962 # Resizing is forbidden when there are buffer exports. |
|
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
963 # For issue 4509, we also check after each error that |
|
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
964 # the array was not modified. |
|
50214
aebf7124dd32
Merged revisions 67840 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49490
diff
changeset
|
965 self.assertRaises(BufferError, a.append, a[0]) |
|
55603
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
966 self.assertEqual(m.tobytes(), expected) |
|
50214
aebf7124dd32
Merged revisions 67840 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49490
diff
changeset
|
967 self.assertRaises(BufferError, a.extend, a[0:1]) |
|
55603
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
968 self.assertEqual(m.tobytes(), expected) |
|
50214
aebf7124dd32
Merged revisions 67840 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49490
diff
changeset
|
969 self.assertRaises(BufferError, a.remove, a[0]) |
|
55603
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
970 self.assertEqual(m.tobytes(), expected) |
|
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
971 self.assertRaises(BufferError, a.pop, 0) |
|
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
972 self.assertEqual(m.tobytes(), expected) |
|
50214
aebf7124dd32
Merged revisions 67840 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49490
diff
changeset
|
973 self.assertRaises(BufferError, a.fromlist, a.tolist()) |
|
55603
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
974 self.assertEqual(m.tobytes(), expected) |
|
64355
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
975 self.assertRaises(BufferError, a.frombytes, a.tobytes()) |
|
55603
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
976 self.assertEqual(m.tobytes(), expected) |
|
50214
aebf7124dd32
Merged revisions 67840 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49490
diff
changeset
|
977 if self.typecode == 'u': |
|
aebf7124dd32
Merged revisions 67840 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49490
diff
changeset
|
978 self.assertRaises(BufferError, a.fromunicode, a.tounicode()) |
|
55603
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
979 self.assertEqual(m.tobytes(), expected) |
|
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
980 self.assertRaises(BufferError, operator.imul, a, 2) |
|
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
981 self.assertEqual(m.tobytes(), expected) |
|
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
982 self.assertRaises(BufferError, operator.imul, a, 0) |
|
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
983 self.assertEqual(m.tobytes(), expected) |
|
50214
aebf7124dd32
Merged revisions 67840 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49490
diff
changeset
|
984 self.assertRaises(BufferError, operator.setitem, a, slice(0, 0), a) |
|
55603
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
985 self.assertEqual(m.tobytes(), expected) |
|
50214
aebf7124dd32
Merged revisions 67840 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49490
diff
changeset
|
986 self.assertRaises(BufferError, operator.delitem, a, 0) |
|
55603
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
987 self.assertEqual(m.tobytes(), expected) |
|
50214
aebf7124dd32
Merged revisions 67840 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49490
diff
changeset
|
988 self.assertRaises(BufferError, operator.delitem, a, slice(0, 1)) |
|
55603
12fec73cb8e5
Merged revisions 73862,73872 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55602
diff
changeset
|
989 self.assertEqual(m.tobytes(), expected) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
990 |
|
32159
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
991 def test_weakref(self): |
|
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
992 s = array.array(self.typecode, self.example) |
|
55259
edc714ffe6cc
Issue #2389: Implement a portable mechanism for pickling array objects.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55124
diff
changeset
|
993 p = weakref.proxy(s) |
|
64355
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
994 self.assertEqual(p.tobytes(), s.tobytes()) |
|
32159
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
995 s = None |
|
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
996 self.assertRaises(ReferenceError, len, p) |
|
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
997 |
|
30039
d8c8fe0c73ed
added test for bug 782369
Skip Montanaro <skip@pobox.com>
parents:
29205
diff
changeset
|
998 def test_bug_782369(self): |
|
d8c8fe0c73ed
added test for bug 782369
Skip Montanaro <skip@pobox.com>
parents:
29205
diff
changeset
|
999 import sys |
|
30040
643ffb7db18f
protect against test problems with Jython
Skip Montanaro <skip@pobox.com>
parents:
30039
diff
changeset
|
1000 if hasattr(sys, "getrefcount"): |
|
643ffb7db18f
protect against test problems with Jython
Skip Montanaro <skip@pobox.com>
parents:
30039
diff
changeset
|
1001 for i in range(10): |
|
643ffb7db18f
protect against test problems with Jython
Skip Montanaro <skip@pobox.com>
parents:
30039
diff
changeset
|
1002 b = array.array('B', range(64)) |
|
643ffb7db18f
protect against test problems with Jython
Skip Montanaro <skip@pobox.com>
parents:
30039
diff
changeset
|
1003 rc = sys.getrefcount(10) |
|
643ffb7db18f
protect against test problems with Jython
Skip Montanaro <skip@pobox.com>
parents:
30039
diff
changeset
|
1004 for i in range(10): |
|
643ffb7db18f
protect against test problems with Jython
Skip Montanaro <skip@pobox.com>
parents:
30039
diff
changeset
|
1005 b = array.array('B', range(64)) |
|
643ffb7db18f
protect against test problems with Jython
Skip Montanaro <skip@pobox.com>
parents:
30039
diff
changeset
|
1006 self.assertEqual(rc, sys.getrefcount(10)) |
|
30039
d8c8fe0c73ed
added test for bug 782369
Skip Montanaro <skip@pobox.com>
parents:
29205
diff
changeset
|
1007 |
|
40737
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40644
diff
changeset
|
1008 def test_subclass_with_kwargs(self): |
|
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40644
diff
changeset
|
1009 # SF bug #1486663 -- this used to erroneously raise a TypeError |
|
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40644
diff
changeset
|
1010 ArraySubclassWithKwargs('b', newarg=1) |
|
32159
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
1011 |
|
42145
8eeaa9923901
Creating an array with a bytes object as initializer
Guido van Rossum <guido@python.org>
parents:
42112
diff
changeset
|
1012 def test_create_from_bytes(self): |
|
55602
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
1013 # XXX This test probably needs to be moved in a subclass or |
|
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55593
diff
changeset
|
1014 # generalized to use self.typecode. |
|
42145
8eeaa9923901
Creating an array with a bytes object as initializer
Guido van Rossum <guido@python.org>
parents:
42112
diff
changeset
|
1015 a = array.array('H', b"1234") |
|
8eeaa9923901
Creating an array with a bytes object as initializer
Guido van Rossum <guido@python.org>
parents:
42112
diff
changeset
|
1016 self.assertEqual(len(a) * a.itemsize, 4) |
|
8eeaa9923901
Creating an array with a bytes object as initializer
Guido van Rossum <guido@python.org>
parents:
42112
diff
changeset
|
1017 |
|
78493
45ef9bc8739f
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1018 @support.cpython_only |
|
45ef9bc8739f
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1019 def test_sizeof_with_buffer(self): |
|
45ef9bc8739f
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1020 a = array.array(self.typecode, self.example) |
|
78494
7d82a60850fd
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
diff
changeset
|
1021 basesize = support.calcvobjsize('Pn2Pi') |
|
78493
45ef9bc8739f
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1022 buffer_size = a.buffer_info()[1] * a.itemsize |
|
45ef9bc8739f
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1023 support.check_sizeof(self, a, basesize + buffer_size) |
|
45ef9bc8739f
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1024 |
|
45ef9bc8739f
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1025 @support.cpython_only |
|
45ef9bc8739f
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1026 def test_sizeof_without_buffer(self): |
|
45ef9bc8739f
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1027 a = array.array(self.typecode) |
|
78494
7d82a60850fd
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
diff
changeset
|
1028 basesize = support.calcvobjsize('Pn2Pi') |
|
78493
45ef9bc8739f
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1029 support.check_sizeof(self, a, basesize) |
|
45ef9bc8739f
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1030 |
|
32159
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
1031 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1032 class StringTest(BaseTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1033 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1034 def test_setitem(self): |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41859
diff
changeset
|
1035 super().test_setitem() |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1036 a = array.array(self.typecode, self.example) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1037 self.assertRaises(TypeError, a.__setitem__, 0, self.example[:2]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1038 |
|
41821
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1039 class UnicodeTest(StringTest): |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1040 typecode = 'u' |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1041 example = '\x01\u263a\x00\ufeff' |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1042 smallerexample = '\x01\u263a\x00\ufefe' |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1043 biggerexample = '\x01\u263a\x01\ufeff' |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1044 outside = str('\x33') |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1045 minitemsize = 2 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1046 |
|
41821
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1047 def test_unicode(self): |
|
78467
4ee4cceda047
Issue #13072: Fix test_array for installation without the ctypes module
Victor Stinner <victor.stinner@gmail.com>
parents:
78464
diff
changeset
|
1048 try: |
|
4ee4cceda047
Issue #13072: Fix test_array for installation without the ctypes module
Victor Stinner <victor.stinner@gmail.com>
parents:
78464
diff
changeset
|
1049 import ctypes |
|
4ee4cceda047
Issue #13072: Fix test_array for installation without the ctypes module
Victor Stinner <victor.stinner@gmail.com>
parents:
78464
diff
changeset
|
1050 sizeof_wchar = ctypes.sizeof(ctypes.c_wchar) |
|
4ee4cceda047
Issue #13072: Fix test_array for installation without the ctypes module
Victor Stinner <victor.stinner@gmail.com>
parents:
78464
diff
changeset
|
1051 except ImportError: |
|
4ee4cceda047
Issue #13072: Fix test_array for installation without the ctypes module
Victor Stinner <victor.stinner@gmail.com>
parents:
78464
diff
changeset
|
1052 import sys |
|
4ee4cceda047
Issue #13072: Fix test_array for installation without the ctypes module
Victor Stinner <victor.stinner@gmail.com>
parents:
78464
diff
changeset
|
1053 if sys.platform == 'win32': |
|
4ee4cceda047
Issue #13072: Fix test_array for installation without the ctypes module
Victor Stinner <victor.stinner@gmail.com>
parents:
78464
diff
changeset
|
1054 sizeof_wchar = 2 |
|
4ee4cceda047
Issue #13072: Fix test_array for installation without the ctypes module
Victor Stinner <victor.stinner@gmail.com>
parents:
78464
diff
changeset
|
1055 else: |
|
4ee4cceda047
Issue #13072: Fix test_array for installation without the ctypes module
Victor Stinner <victor.stinner@gmail.com>
parents:
78464
diff
changeset
|
1056 sizeof_wchar = 4 |
|
4ee4cceda047
Issue #13072: Fix test_array for installation without the ctypes module
Victor Stinner <victor.stinner@gmail.com>
parents:
78464
diff
changeset
|
1057 |
|
41821
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1058 self.assertRaises(TypeError, array.array, 'b', 'foo') |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1059 |
|
41821
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1060 a = array.array('u', '\xa0\xc2\u1234') |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1061 a.fromunicode(' ') |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1062 a.fromunicode('') |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1063 a.fromunicode('') |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1064 a.fromunicode('\x11abc\xff\u1234') |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1065 s = a.tounicode() |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1066 self.assertEqual(s, '\xa0\xc2\u1234 \x11abc\xff\u1234') |
|
78467
4ee4cceda047
Issue #13072: Fix test_array for installation without the ctypes module
Victor Stinner <victor.stinner@gmail.com>
parents:
78464
diff
changeset
|
1067 self.assertEqual(a.itemsize, sizeof_wchar) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1068 |
|
41821
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1069 s = '\x00="\'a\\b\x80\xff\u0000\u0001\u1234' |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1070 a = array.array('u', s) |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1071 self.assertEqual( |
|
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1072 repr(a), |
|
47611
da47e7e135ae
#2630: Implement PEP 3138.
Georg Brandl <georg@python.org>
parents:
47463
diff
changeset
|
1073 "array('u', '\\x00=\"\\'a\\\\b\\x80\xff\\x00\\x01\u1234')") |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1074 |
|
41821
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1075 self.assertRaises(TypeError, a.fromunicode) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1076 |
|
41821
ae691227fd34
Remove have_unicode checks and merge those tests into the
Walter Dörwald <walter@livinglogic.de>
parents:
41685
diff
changeset
|
1077 tests.append(UnicodeTest) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1078 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1079 class NumberTest(BaseTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1080 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1081 def test_extslice(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1082 a = array.array(self.typecode, range(5)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1083 self.assertEqual(a[::], a) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1084 self.assertEqual(a[::2], array.array(self.typecode, [0,2,4])) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1085 self.assertEqual(a[1::2], array.array(self.typecode, [1,3])) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1086 self.assertEqual(a[::-1], array.array(self.typecode, [4,3,2,1,0])) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1087 self.assertEqual(a[::-2], array.array(self.typecode, [4,2,0])) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1088 self.assertEqual(a[3::-2], array.array(self.typecode, [3,1])) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1089 self.assertEqual(a[-100:100:], a) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1090 self.assertEqual(a[100:-100:-1], a[::-1]) |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
1091 self.assertEqual(a[-100:100:2], array.array(self.typecode, [0,2,4])) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1092 self.assertEqual(a[1000:2000:2], array.array(self.typecode, [])) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1093 self.assertEqual(a[-1000:-2000:-2], array.array(self.typecode, [])) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1094 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1095 def test_delslice(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1096 a = array.array(self.typecode, range(5)) |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
1097 del a[::2] |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1098 self.assertEqual(a, array.array(self.typecode, [1,3])) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1099 a = array.array(self.typecode, range(5)) |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
1100 del a[1::2] |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1101 self.assertEqual(a, array.array(self.typecode, [0,2,4])) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1102 a = array.array(self.typecode, range(5)) |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
1103 del a[1::-2] |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1104 self.assertEqual(a, array.array(self.typecode, [0,2,3,4])) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1105 a = array.array(self.typecode, range(10)) |
| 24424 | 1106 del a[::1000] |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1107 self.assertEqual(a, array.array(self.typecode, [1,2,3,4,5,6,7,8,9])) |
|
58564
6de64896c6f8
Merged revisions 77823 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
55603
diff
changeset
|
1108 # test issue7788 |
|
6de64896c6f8
Merged revisions 77823 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
55603
diff
changeset
|
1109 a = array.array(self.typecode, range(10)) |
|
6de64896c6f8
Merged revisions 77823 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
55603
diff
changeset
|
1110 del a[9::1<<333] |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1111 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1112 def test_assignment(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1113 a = array.array(self.typecode, range(10)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1114 a[::2] = array.array(self.typecode, [42]*5) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1115 self.assertEqual(a, array.array(self.typecode, [42, 1, 42, 3, 42, 5, 42, 7, 42, 9])) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1116 a = array.array(self.typecode, range(10)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1117 a[::-4] = array.array(self.typecode, [10]*3) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1118 self.assertEqual(a, array.array(self.typecode, [0, 10, 2, 3, 4, 10, 6, 7, 8 ,10])) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1119 a = array.array(self.typecode, range(4)) |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
1120 a[::-1] = a |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1121 self.assertEqual(a, array.array(self.typecode, [3, 2, 1, 0])) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1122 a = array.array(self.typecode, range(10)) |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
1123 b = a[:] |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
1124 c = a[:] |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1125 ins = array.array(self.typecode, range(2)) |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
1126 a[2:3] = ins |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
1127 b[slice(2,3)] = ins |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
1128 c[2:3:] = ins |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1129 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1130 def test_iterationcontains(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1131 a = array.array(self.typecode, range(10)) |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41592
diff
changeset
|
1132 self.assertEqual(list(a), list(range(10))) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1133 b = array.array(self.typecode, [20]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1134 self.assertEqual(a[-1] in a, True) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1135 self.assertEqual(b[0] not in a, True) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1136 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1137 def check_overflow(self, lower, upper): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1138 # method to be used by subclasses |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1139 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1140 # should not overflow assigning lower limit |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1141 a = array.array(self.typecode, [lower]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1142 a[0] = lower |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1143 # should overflow assigning less than lower limit |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1144 self.assertRaises(OverflowError, array.array, self.typecode, [lower-1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1145 self.assertRaises(OverflowError, a.__setitem__, 0, lower-1) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1146 # should not overflow assigning upper limit |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1147 a = array.array(self.typecode, [upper]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1148 a[0] = upper |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1149 # should overflow assigning more than upper limit |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1150 self.assertRaises(OverflowError, array.array, self.typecode, [upper+1]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1151 self.assertRaises(OverflowError, a.__setitem__, 0, upper+1) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1152 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1153 def test_subclassing(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1154 typecode = self.typecode |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1155 class ExaggeratingArray(array.array): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1156 __slots__ = ['offset'] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1157 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1158 def __new__(cls, typecode, data, offset): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1159 return array.array.__new__(cls, typecode, data) |
|
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
|
1160 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1161 def __init__(self, typecode, data, offset): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1162 self.offset = offset |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1163 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1164 def __getitem__(self, i): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1165 return array.array.__getitem__(self, i) + self.offset |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1166 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1167 a = ExaggeratingArray(self.typecode, [3, 6, 7, 11], 4) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1168 self.assertEntryEqual(a[0], 7) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1169 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1170 self.assertRaises(AttributeError, setattr, a, "color", "blue") |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1171 |
|
67537
2581a17b29af
Issue #5109: array.array constructor will now use fast code when
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67334
diff
changeset
|
1172 def test_frombytearray(self): |
|
2581a17b29af
Issue #5109: array.array constructor will now use fast code when
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67334
diff
changeset
|
1173 a = array.array('b', range(10)) |
|
2581a17b29af
Issue #5109: array.array constructor will now use fast code when
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67334
diff
changeset
|
1174 b = array.array(self.typecode, a) |
|
2581a17b29af
Issue #5109: array.array constructor will now use fast code when
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67334
diff
changeset
|
1175 self.assertEqual(a, b) |
|
2581a17b29af
Issue #5109: array.array constructor will now use fast code when
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
67334
diff
changeset
|
1176 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1177 class SignedNumberTest(NumberTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1178 example = [-1, 0, 1, 42, 0x7f] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1179 smallerexample = [-1, 0, 1, 42, 0x7e] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1180 biggerexample = [-1, 0, 1, 43, 0x7f] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1181 outside = 23 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1182 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1183 def test_overflow(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1184 a = array.array(self.typecode) |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
1185 lower = -1 * int(pow(2, a.itemsize * 8 - 1)) |
|
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
1186 upper = int(pow(2, a.itemsize * 8 - 1)) - 1 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1187 self.check_overflow(lower, upper) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1188 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1189 class UnsignedNumberTest(NumberTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1190 example = [0, 1, 17, 23, 42, 0xff] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1191 smallerexample = [0, 1, 17, 23, 42, 0xfe] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1192 biggerexample = [0, 1, 17, 23, 43, 0xff] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1193 outside = 0xaa |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1194 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1195 def test_overflow(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1196 a = array.array(self.typecode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1197 lower = 0 |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
1198 upper = int(pow(2, a.itemsize * 8)) - 1 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1199 self.check_overflow(lower, upper) |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
1200 |
|
64355
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1201 def test_bytes_extend(self): |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1202 s = bytes(self.example) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1203 |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1204 a = array.array(self.typecode, self.example) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1205 a.extend(s) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1206 self.assertEqual( |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1207 a, |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1208 array.array(self.typecode, self.example+self.example) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1209 ) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1210 |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1211 a = array.array(self.typecode, self.example) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1212 a.extend(bytearray(reversed(s))) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1213 self.assertEqual( |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1214 a, |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1215 array.array(self.typecode, self.example+self.example[::-1]) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1216 ) |
|
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1217 |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
1218 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1219 class ByteTest(SignedNumberTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1220 typecode = 'b' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1221 minitemsize = 1 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1222 tests.append(ByteTest) |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
1223 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1224 class UnsignedByteTest(UnsignedNumberTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1225 typecode = 'B' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1226 minitemsize = 1 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1227 tests.append(UnsignedByteTest) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1228 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1229 class ShortTest(SignedNumberTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1230 typecode = 'h' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1231 minitemsize = 2 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1232 tests.append(ShortTest) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1233 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1234 class UnsignedShortTest(UnsignedNumberTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1235 typecode = 'H' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1236 minitemsize = 2 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1237 tests.append(UnsignedShortTest) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1238 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1239 class IntTest(SignedNumberTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1240 typecode = 'i' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1241 minitemsize = 2 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1242 tests.append(IntTest) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1243 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1244 class UnsignedIntTest(UnsignedNumberTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1245 typecode = 'I' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1246 minitemsize = 2 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1247 tests.append(UnsignedIntTest) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1248 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1249 class LongTest(SignedNumberTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1250 typecode = 'l' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1251 minitemsize = 4 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1252 tests.append(LongTest) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1253 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1254 class UnsignedLongTest(UnsignedNumberTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1255 typecode = 'L' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1256 minitemsize = 4 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1257 tests.append(UnsignedLongTest) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1258 |
|
72430
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1259 @unittest.skipIf(not have_long_long, 'need long long support') |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1260 class LongLongTest(SignedNumberTest): |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1261 typecode = 'q' |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1262 minitemsize = 8 |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1263 tests.append(LongLongTest) |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1264 |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1265 @unittest.skipIf(not have_long_long, 'need long long support') |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1266 class UnsignedLongLongTest(UnsignedNumberTest): |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1267 typecode = 'Q' |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1268 minitemsize = 8 |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1269 tests.append(UnsignedLongLongTest) |
|
15659e0e2b2e
Issue #1172711: Add 'long long' support to the array module.
Meador Inge <meadori@gmail.com>
parents:
68257
diff
changeset
|
1270 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1271 class FPTest(NumberTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1272 example = [-42.0, 0, 42, 1e5, -1e10] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1273 smallerexample = [-42.0, 0, 42, 1e5, -2e10] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1274 biggerexample = [-42.0, 0, 42, 1e5, 1e10] |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1275 outside = 23 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1276 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1277 def assertEntryEqual(self, entry1, entry2): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1278 self.assertAlmostEqual(entry1, entry2) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1279 |
|
29204
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1280 def test_byteswap(self): |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1281 a = array.array(self.typecode, self.example) |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1282 self.assertRaises(TypeError, a.byteswap, 42) |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1283 if a.itemsize in (1, 2, 4, 8): |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1284 b = array.array(self.typecode, self.example) |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1285 b.byteswap() |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1286 if a.itemsize==1: |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1287 self.assertEqual(a, b) |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1288 else: |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1289 # On alphas treating the byte swapped bit patters as |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1290 # floats/doubles results in floating point exceptions |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1291 # => compare the 8bit string values instead |
|
64355
fa8b57f987c5
Issue #8990: array.fromstring() and array.tostring() get renamed to
Antoine Pitrou <solipsis@pitrou.net>
parents:
63128
diff
changeset
|
1292 self.assertNotEqual(a.tobytes(), b.tobytes()) |
|
29204
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1293 b.byteswap() |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1294 self.assertEqual(a, b) |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1295 |
|
29205
56ffca02c824
Walter's last checkin also needs to work on doubles.
Neal Norwitz <nnorwitz@gmail.com>
parents:
29204
diff
changeset
|
1296 class FloatTest(FPTest): |
|
56ffca02c824
Walter's last checkin also needs to work on doubles.
Neal Norwitz <nnorwitz@gmail.com>
parents:
29204
diff
changeset
|
1297 typecode = 'f' |
|
56ffca02c824
Walter's last checkin also needs to work on doubles.
Neal Norwitz <nnorwitz@gmail.com>
parents:
29204
diff
changeset
|
1298 minitemsize = 4 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1299 tests.append(FloatTest) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1300 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1301 class DoubleTest(FPTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1302 typecode = 'd' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1303 minitemsize = 8 |
|
48330
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47611
diff
changeset
|
1304 |
|
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47611
diff
changeset
|
1305 def test_alloc_overflow(self): |
|
49490
c0ac47984b11
Merged revisions 66703,66708 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48330
diff
changeset
|
1306 from sys import maxsize |
|
48330
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47611
diff
changeset
|
1307 a = array.array('d', [-1]*65536) |
|
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47611
diff
changeset
|
1308 try: |
|
49490
c0ac47984b11
Merged revisions 66703,66708 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48330
diff
changeset
|
1309 a *= maxsize//65536 + 1 |
|
48330
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47611
diff
changeset
|
1310 except MemoryError: |
|
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47611
diff
changeset
|
1311 pass |
|
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47611
diff
changeset
|
1312 else: |
|
49490
c0ac47984b11
Merged revisions 66703,66708 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48330
diff
changeset
|
1313 self.fail("Array of size > maxsize created - MemoryError expected") |
|
48330
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47611
diff
changeset
|
1314 b = array.array('d', [ 2.71828183, 3.14159265, -1]) |
|
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47611
diff
changeset
|
1315 try: |
|
49490
c0ac47984b11
Merged revisions 66703,66708 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48330
diff
changeset
|
1316 b * (maxsize//3 + 1) |
|
48330
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47611
diff
changeset
|
1317 except MemoryError: |
|
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47611
diff
changeset
|
1318 pass |
|
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47611
diff
changeset
|
1319 else: |
|
49490
c0ac47984b11
Merged revisions 66703,66708 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48330
diff
changeset
|
1320 self.fail("Array of size > maxsize created - MemoryError expected") |
|
48330
ac854cde3135
Merged revisions 64114 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47611
diff
changeset
|
1321 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1322 tests.append(DoubleTest) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1323 |
|
33316
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1324 def test_main(verbose=None): |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1325 import sys |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1326 |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46430
diff
changeset
|
1327 support.run_unittest(*tests) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1328 |
|
33316
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1329 # verify reference counting |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1330 if verbose and hasattr(sys, "gettotalrefcount"): |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1331 import gc |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1332 counts = [None] * 5 |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41592
diff
changeset
|
1333 for i in range(len(counts)): |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46430
diff
changeset
|
1334 support.run_unittest(*tests) |
|
33316
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1335 gc.collect() |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1336 counts[i] = sys.gettotalrefcount() |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1337 print(counts) |
|
33316
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1338 |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1339 if __name__ == "__main__": |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1340 test_main(verbose=True) |
