Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_array.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | 91382d4e2dfb |
| children | 2d330f7908e7 |
| rev | line source |
|---|---|
|
4627
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
2 """Test the arraymodule. |
|
4811
9ae3cccfa7cd
Many scripts, but small changes. Update the way the scripts obtain the
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4627
diff
changeset
|
3 Roger E. Masse |
|
4627
6b765453b041
module to test the arraymodule created and added to testall.py
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
diff
changeset
|
4 """ |
|
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 |
|
71226
7bfedb159e82
test_array: make quiet the DeprecationWarning
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68256
diff
changeset
|
7 import warnings |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
8 from test import test_support |
|
32159
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
9 from weakref import proxy |
|
45468
1d84bf5f9478
Patch #2167 from calvin: Remove unused imports
Christian Heimes <christian@cheimes.de>
parents:
42951
diff
changeset
|
10 import array, cStringIO |
|
50305
e673632e1885
Merged revisions 67898,67904-67907,67912,67918,67920-67921,67923-67924,67927,67930,67932,67943 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49362
diff
changeset
|
11 from cPickle import loads, dumps, HIGHEST_PROTOCOL |
|
34174
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
12 |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
13 class ArraySubclass(array.array): |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
14 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
|
15 |
|
40682
77e0f4718a7c
Bug #1486663: don't reject keyword arguments for subclasses of builtin
Georg Brandl <georg@python.org>
parents:
39653
diff
changeset
|
16 class ArraySubclassWithKwargs(array.array): |
|
77e0f4718a7c
Bug #1486663: don't reject keyword arguments for subclasses of builtin
Georg Brandl <georg@python.org>
parents:
39653
diff
changeset
|
17 def __init__(self, typecode, newarg=None): |
|
68015
8eeee9d6d32b
Merged revisions 87050,87101,87146,87156,87172,87175,87371,87378,87522-87524,87526,87530-87535 via svnmerge from
Georg Brandl <georg@python.org>
parents:
67540
diff
changeset
|
18 array.array.__init__(self, typecode) |
|
40682
77e0f4718a7c
Bug #1486663: don't reject keyword arguments for subclasses of builtin
Georg Brandl <georg@python.org>
parents:
39653
diff
changeset
|
19 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
20 tests = [] # list to accumulate all tests |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
21 typecodes = "cubBhHiIlLfd" |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
22 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
23 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
|
24 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
31 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
|
32 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
33 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
|
34 # 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
|
35 # 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
|
36 # 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
|
37 # 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
|
38 # 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
|
39 # 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
|
40 # 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
|
41 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
42 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
|
43 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
|
44 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
45 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
|
46 # 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
|
47 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
|
48 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
49 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
|
50 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
|
51 self.assertEqual(a.typecode, self.typecode) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
52 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
|
53 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
|
54 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 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
|
59 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
60 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
|
61 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
|
62 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 bi = a.buffer_info() |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
67 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
|
68 self.assertEqual(len(bi), 2) |
|
58472
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
69 self.assertIsInstance(bi[0], (int, long)) |
|
6ffcdafa0118
use assert[Not]IsInstance where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
70 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
|
71 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
|
72 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
73 def test_byteswap(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
74 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
|
75 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
|
76 if a.itemsize in (1, 2, 4, 8): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
77 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
|
78 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
|
79 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
|
80 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
|
81 else: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 |
|
31651
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30040
diff
changeset
|
86 def test_copy(self): |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30040
diff
changeset
|
87 import copy |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30040
diff
changeset
|
88 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
|
89 b = copy.copy(a) |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30040
diff
changeset
|
90 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
|
91 self.assertEqual(a, b) |
|
35cb8114b45c
SF bug #910986: copy.copy fails for array.array
Raymond Hettinger <python@rcn.com>
parents:
30040
diff
changeset
|
92 |
|
39653
a88bc3bad651
Fix SF bug #1545837: array.array borks on deepcopy.
Thomas Wouters <thomas@python.org>
parents:
37571
diff
changeset
|
93 def test_deepcopy(self): |
|
a88bc3bad651
Fix SF bug #1545837: array.array borks on deepcopy.
Thomas Wouters <thomas@python.org>
parents:
37571
diff
changeset
|
94 import copy |
|
a88bc3bad651
Fix SF bug #1545837: array.array borks on deepcopy.
Thomas Wouters <thomas@python.org>
parents:
37571
diff
changeset
|
95 a = array.array(self.typecode, self.example) |
|
a88bc3bad651
Fix SF bug #1545837: array.array borks on deepcopy.
Thomas Wouters <thomas@python.org>
parents:
37571
diff
changeset
|
96 b = copy.deepcopy(a) |
|
a88bc3bad651
Fix SF bug #1545837: array.array borks on deepcopy.
Thomas Wouters <thomas@python.org>
parents:
37571
diff
changeset
|
97 self.assertNotEqual(id(a), id(b)) |
|
a88bc3bad651
Fix SF bug #1545837: array.array borks on deepcopy.
Thomas Wouters <thomas@python.org>
parents:
37571
diff
changeset
|
98 self.assertEqual(a, b) |
|
a88bc3bad651
Fix SF bug #1545837: array.array borks on deepcopy.
Thomas Wouters <thomas@python.org>
parents:
37571
diff
changeset
|
99 |
|
34174
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
100 def test_pickle(self): |
|
50305
e673632e1885
Merged revisions 67898,67904-67907,67912,67918,67920-67921,67923-67924,67927,67930,67932,67943 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49362
diff
changeset
|
101 for protocol in range(HIGHEST_PROTOCOL + 1): |
|
34174
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
102 a = array.array(self.typecode, self.example) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
103 b = loads(dumps(a, protocol)) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
104 self.assertNotEqual(id(a), id(b)) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
105 self.assertEqual(a, b) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
106 |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
107 a = ArraySubclass(self.typecode, self.example) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
108 a.x = 10 |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
109 b = loads(dumps(a, protocol)) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
110 self.assertNotEqual(id(a), id(b)) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
111 self.assertEqual(a, b) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
112 self.assertEqual(a.x, b.x) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
113 self.assertEqual(type(a), type(b)) |
|
30b97c1bb12d
SF #1085304: Make array.array pickle-able
Raymond Hettinger <python@rcn.com>
parents:
33316
diff
changeset
|
114 |
|
41359
f764a7552162
SF #1693079: Cannot save empty array in shelve
Raymond Hettinger <python@rcn.com>
parents:
40682
diff
changeset
|
115 def test_pickle_for_empty_array(self): |
|
50305
e673632e1885
Merged revisions 67898,67904-67907,67912,67918,67920-67921,67923-67924,67927,67930,67932,67943 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49362
diff
changeset
|
116 for protocol in range(HIGHEST_PROTOCOL + 1): |
|
41359
f764a7552162
SF #1693079: Cannot save empty array in shelve
Raymond Hettinger <python@rcn.com>
parents:
40682
diff
changeset
|
117 a = array.array(self.typecode) |
|
f764a7552162
SF #1693079: Cannot save empty array in shelve
Raymond Hettinger <python@rcn.com>
parents:
40682
diff
changeset
|
118 b = loads(dumps(a, protocol)) |
|
f764a7552162
SF #1693079: Cannot save empty array in shelve
Raymond Hettinger <python@rcn.com>
parents:
40682
diff
changeset
|
119 self.assertNotEqual(id(a), id(b)) |
|
f764a7552162
SF #1693079: Cannot save empty array in shelve
Raymond Hettinger <python@rcn.com>
parents:
40682
diff
changeset
|
120 self.assertEqual(a, b) |
|
f764a7552162
SF #1693079: Cannot save empty array in shelve
Raymond Hettinger <python@rcn.com>
parents:
40682
diff
changeset
|
121 |
|
f764a7552162
SF #1693079: Cannot save empty array in shelve
Raymond Hettinger <python@rcn.com>
parents:
40682
diff
changeset
|
122 a = ArraySubclass(self.typecode) |
|
f764a7552162
SF #1693079: Cannot save empty array in shelve
Raymond Hettinger <python@rcn.com>
parents:
40682
diff
changeset
|
123 a.x = 10 |
|
f764a7552162
SF #1693079: Cannot save empty array in shelve
Raymond Hettinger <python@rcn.com>
parents:
40682
diff
changeset
|
124 b = loads(dumps(a, protocol)) |
|
f764a7552162
SF #1693079: Cannot save empty array in shelve
Raymond Hettinger <python@rcn.com>
parents:
40682
diff
changeset
|
125 self.assertNotEqual(id(a), id(b)) |
|
f764a7552162
SF #1693079: Cannot save empty array in shelve
Raymond Hettinger <python@rcn.com>
parents:
40682
diff
changeset
|
126 self.assertEqual(a, b) |
|
f764a7552162
SF #1693079: Cannot save empty array in shelve
Raymond Hettinger <python@rcn.com>
parents:
40682
diff
changeset
|
127 self.assertEqual(a.x, b.x) |
|
f764a7552162
SF #1693079: Cannot save empty array in shelve
Raymond Hettinger <python@rcn.com>
parents:
40682
diff
changeset
|
128 self.assertEqual(type(a), type(b)) |
|
f764a7552162
SF #1693079: Cannot save empty array in shelve
Raymond Hettinger <python@rcn.com>
parents:
40682
diff
changeset
|
129 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 |
|
29163
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
139 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
|
140 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
|
141 self.assertEqual( |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
142 a, |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
143 array.array( |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
144 self.typecode, |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
145 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
|
146 ) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
147 ) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
148 |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
149 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
|
150 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
|
151 self.assertEqual( |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
152 a, |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
153 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
|
154 ) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
155 |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
156 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
|
157 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
|
158 self.assertEqual( |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
159 a, |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
160 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
|
161 ) |
|
2bb5ceef9ac3
Fix array.array.insert(), so that it treats negative indices as
Walter Dörwald <walter@livinglogic.de>
parents:
29158
diff
changeset
|
162 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
163 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
|
164 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
|
165 self.assertRaises(TypeError, a.tofile) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
166 self.assertRaises(TypeError, a.tofile, cStringIO.StringIO()) |
|
46388
8d555850f73d
Remove the test file before writing it in case there is no write permission.
Neal Norwitz <nnorwitz@gmail.com>
parents:
45468
diff
changeset
|
167 test_support.unlink(test_support.TESTFN) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
168 f = open(test_support.TESTFN, 'wb') |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
169 try: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 f = open(test_support.TESTFN, 'rb') |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
174 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
|
175 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
|
176 TypeError, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
177 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
|
178 cStringIO.StringIO(), 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
|
179 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 self.assertRaises(EOFError, b.fromfile, f, 1) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
186 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
|
187 finally: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
188 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
|
189 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
|
190 test_support.unlink(test_support.TESTFN) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
191 |
|
63130
7b5d1527c0ce
Merged revisions 83031 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58562
diff
changeset
|
192 def test_fromfile_ioerror(self): |
|
7b5d1527c0ce
Merged revisions 83031 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58562
diff
changeset
|
193 # Issue #5395: Check if fromfile raises a proper IOError |
|
7b5d1527c0ce
Merged revisions 83031 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58562
diff
changeset
|
194 # instead of EOFError. |
|
7b5d1527c0ce
Merged revisions 83031 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58562
diff
changeset
|
195 a = array.array(self.typecode) |
|
7b5d1527c0ce
Merged revisions 83031 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58562
diff
changeset
|
196 f = open(test_support.TESTFN, 'wb') |
|
7b5d1527c0ce
Merged revisions 83031 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58562
diff
changeset
|
197 try: |
|
7b5d1527c0ce
Merged revisions 83031 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58562
diff
changeset
|
198 self.assertRaises(IOError, a.fromfile, f, len(self.example)) |
|
7b5d1527c0ce
Merged revisions 83031 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58562
diff
changeset
|
199 finally: |
|
7b5d1527c0ce
Merged revisions 83031 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58562
diff
changeset
|
200 f.close() |
|
7b5d1527c0ce
Merged revisions 83031 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58562
diff
changeset
|
201 test_support.unlink(test_support.TESTFN) |
|
7b5d1527c0ce
Merged revisions 83031 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58562
diff
changeset
|
202 |
|
55664
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
203 def test_filewrite(self): |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
204 a = array.array(self.typecode, 2*self.example) |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
205 f = open(test_support.TESTFN, 'wb') |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
206 try: |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
207 f.write(a) |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
208 f.close() |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
209 b = array.array(self.typecode) |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
210 f = open(test_support.TESTFN, 'rb') |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
211 b.fromfile(f, len(self.example)) |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
212 self.assertEqual(b, array.array(self.typecode, self.example)) |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
213 self.assertNotEqual(a, b) |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
214 b.fromfile(f, len(self.example)) |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
215 self.assertEqual(a, b) |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
216 f.close() |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
217 finally: |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
218 if not f.closed: |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
219 f.close() |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
220 test_support.unlink(test_support.TESTFN) |
|
6da6edfa6296
Add test of file.write(array) extracted from Jython.
Frank Wierzbicki <fwierzbicki@gmail.com>
parents:
55117
diff
changeset
|
221 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 self.assertEqual(a, b) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
231 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
232 def test_tofromstring(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
233 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
|
234 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
|
235 self.assertRaises(TypeError, a.tostring, 42) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
236 self.assertRaises(TypeError, b.fromstring) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
237 self.assertRaises(TypeError, b.fromstring, 42) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
238 b.fromstring(a.tostring()) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
239 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
|
240 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
|
241 self.assertRaises(ValueError, b.fromstring, "x") |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
242 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
243 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
|
244 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
|
245 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
|
246 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
247 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
|
248 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
|
249 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
250 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
|
251 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
|
252 str(a) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
253 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
254 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
|
255 a = array.array(self.typecode, self.example) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
256 self.assertTrue((a == 42) is False) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
257 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
|
258 |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
259 self.assertTrue((a == a) is True) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
260 self.assertTrue((a != a) is False) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
261 self.assertTrue((a < a) is False) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
262 self.assertTrue((a <= a) is True) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
263 self.assertTrue((a > a) is False) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
264 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
|
265 |
|
37055
fdc05b167236
as is on the road to keyword-hood, use a different var name.
Neal Norwitz <nnorwitz@gmail.com>
parents:
34479
diff
changeset
|
266 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
|
267 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
|
268 |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
269 self.assertTrue((a == 2*a) is False) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
270 self.assertTrue((a != 2*a) is True) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
271 self.assertTrue((a < 2*a) is True) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
272 self.assertTrue((a <= 2*a) is True) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
273 self.assertTrue((a > 2*a) is False) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
274 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
|
275 |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
276 self.assertTrue((a == al) is False) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
277 self.assertTrue((a != al) is True) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
278 self.assertTrue((a < al) is False) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
279 self.assertTrue((a <= al) is False) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
280 self.assertTrue((a > al) is True) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
281 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
|
282 |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
283 self.assertTrue((a == ab) is False) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
284 self.assertTrue((a != ab) is True) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
285 self.assertTrue((a < ab) is True) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
286 self.assertTrue((a <= ab) is True) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
287 self.assertTrue((a > ab) is False) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
288 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
|
289 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
290 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
|
291 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
|
292 + 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
|
293 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
|
294 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
295 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
|
296 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
297 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
298 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
|
299 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
|
300 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
301 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
|
302 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
303 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
|
304 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
|
305 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
|
306 a += array.array(self.typecode, 2*self.example) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
307 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
|
308 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
|
309 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
310 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
|
311 ) |
|
55117
c6f13934f4c6
Backport test cases added in r73852.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55002
diff
changeset
|
312 a = array.array(self.typecode, self.example) |
|
c6f13934f4c6
Backport test cases added in r73852.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55002
diff
changeset
|
313 a += a |
|
c6f13934f4c6
Backport test cases added in r73852.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55002
diff
changeset
|
314 self.assertEqual( |
|
c6f13934f4c6
Backport test cases added in r73852.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55002
diff
changeset
|
315 a, |
|
c6f13934f4c6
Backport test cases added in r73852.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55002
diff
changeset
|
316 array.array(self.typecode, self.example + self.example) |
|
c6f13934f4c6
Backport test cases added in r73852.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55002
diff
changeset
|
317 ) |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
318 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
319 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
|
320 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
|
321 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
322 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
|
323 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
324 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
|
325 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
|
326 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
|
327 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
328 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
|
329 ) |
|
5289
47d3d396d4ef
Use TESTFN instead of /etc/passwd and /dev/null as test files.
Guido van Rossum <guido@python.org>
parents:
4811
diff
changeset
|
330 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
331 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
|
332 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
|
333 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
334 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
|
335 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
336 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
337 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
|
338 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
|
339 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
340 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
|
341 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
342 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
343 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
|
344 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
|
345 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
346 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
|
347 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
348 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
349 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
|
350 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
351 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
|
352 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
|
353 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
|
354 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
355 a *= 5 |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
356 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
|
357 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
|
358 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
359 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
|
360 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
361 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
362 a *= 0 |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
363 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
|
364 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
|
365 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
366 a *= 1000 |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
367 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
|
368 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
|
369 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
370 a *= -1 |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50305
diff
changeset
|
371 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
|
372 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
|
373 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
374 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
|
375 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
|
376 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
|
377 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
378 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
|
379 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
380 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
|
381 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
|
382 self.assertEntryEqual(a[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
|
383 self.assertEntryEqual(a[0L], 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
|
384 self.assertEntryEqual(a[-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
|
385 self.assertEntryEqual(a[-1L], 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
|
386 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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
392 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
|
393 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
|
394 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
|
395 self.assertEntryEqual(a[0], a[-1]) |
|
13069
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
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 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
|
398 a[0L] = 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
|
399 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
|
400 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
401 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
|
402 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
|
403 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
|
404 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
405 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
|
406 a[-1L] = 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
|
407 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
|
408 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
409 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
|
410 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
|
411 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
|
412 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
413 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
|
414 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
|
415 self.assertEntryEqual(a[0], a[-1]) |
|
13069
b76df68099a5
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
8676
diff
changeset
|
416 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
417 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
|
418 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
|
419 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
|
420 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
|
421 IndexError, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
422 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
|
423 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
|
424 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
425 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
|
426 IndexError, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
427 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
|
428 -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
|
429 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
430 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
431 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
|
432 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
|
433 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
|
434 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
|
435 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
436 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
|
437 ) |
|
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
|
438 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
439 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
|
440 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
|
441 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
|
442 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
443 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
|
444 ) |
|
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
|
445 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
446 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
|
447 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
|
448 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
|
449 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
450 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
|
451 ) |
|
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
|
452 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
453 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
|
454 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
|
455 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
|
456 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
457 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
|
458 ) |
|
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
|
459 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
460 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
|
461 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
|
462 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
|
463 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
|
464 |
|
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 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
|
466 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
|
467 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
|
468 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
469 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
|
470 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
|
471 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
|
472 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
473 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
474 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
|
475 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
|
476 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
|
477 ) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
478 |
|
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 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
|
480 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
|
481 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
|
482 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
483 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
484 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
|
485 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
|
486 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
|
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 |
|
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.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
490 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
|
491 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
|
492 ) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
493 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
494 self.assertEqual( |
|
34479
b9bc49b53f4d
Add a slice test with high < low.
Walter Dörwald <walter@livinglogic.de>
parents:
34174
diff
changeset
|
495 a[2:1], |
|
b9bc49b53f4d
Add a slice test with high < low.
Walter Dörwald <walter@livinglogic.de>
parents:
34174
diff
changeset
|
496 array.array(self.typecode) |
|
b9bc49b53f4d
Add a slice test with high < low.
Walter Dörwald <walter@livinglogic.de>
parents:
34174
diff
changeset
|
497 ) |
|
b9bc49b53f4d
Add a slice test with high < low.
Walter Dörwald <walter@livinglogic.de>
parents:
34174
diff
changeset
|
498 |
|
b9bc49b53f4d
Add a slice test with high < low.
Walter Dörwald <walter@livinglogic.de>
parents:
34174
diff
changeset
|
499 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
|
500 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
|
501 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
|
502 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
503 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
|
504 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
|
505 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
|
506 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
|
507 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
|
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 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
|
510 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
|
511 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
|
512 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
|
513 ) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
514 |
|
42951
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
515 def test_extended_getslice(self): |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
516 # Test extended slicing by comparing with list slicing |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
517 # (Assumes list conversion works correctly, too) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
518 a = array.array(self.typecode, self.example) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
519 indices = (0, None, 1, 3, 19, 100, -1, -2, -31, -100) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
520 for start in indices: |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
521 for stop in indices: |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
522 # Everything except the initial 0 (invalid step) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
523 for step in indices[1:]: |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
524 self.assertEqual(list(a[start:stop:step]), |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
525 list(a)[start:stop:step]) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
526 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
527 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
|
528 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
|
529 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
|
530 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
|
531 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
532 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
|
533 ) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
15966
diff
changeset
|
534 |
|
29157
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 = 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
|
536 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
|
537 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
|
538 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
539 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
|
540 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
541 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
542 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
|
543 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
|
544 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
|
545 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
546 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
|
547 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
548 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
549 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
|
550 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
|
551 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
|
552 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
553 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
|
554 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
555 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
556 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
|
557 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
|
558 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
|
559 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
560 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
|
561 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
|
562 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
|
563 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
564 ) |
|
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 = 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
|
567 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
|
568 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
|
569 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
570 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
|
571 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
572 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
573 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
|
574 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
|
575 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
|
576 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
577 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 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
579 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
580 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
|
581 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
|
582 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
|
583 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
584 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
|
585 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
586 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
587 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
|
588 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
|
589 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
|
590 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
591 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
|
592 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
593 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
594 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
|
595 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
|
596 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
|
597 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
598 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
|
599 ) |
|
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) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
602 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
|
603 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
|
604 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
605 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
|
606 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
607 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
608 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
|
609 self.assertRaises(TypeError, a.__setslice__, 0, 0, None) |
|
42951
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
610 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
|
611 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
|
612 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
613 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
|
614 self.assertRaises(TypeError, a.__setslice__, 0, 0, b) |
|
42951
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
615 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
|
616 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
|
617 |
|
42951
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
618 def test_extended_set_del_slice(self): |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
619 indices = (0, None, 1, 3, 19, 100, -1, -2, -31, -100) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
620 for start in indices: |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
621 for stop in indices: |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
622 # Everything except the initial 0 (invalid step) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
623 for step in indices[1:]: |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
624 a = array.array(self.typecode, self.example) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
625 L = list(a) |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
626 # Make sure we have a slice of exactly the right length, |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
627 # but with (hopefully) different data. |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
628 data = L[start:stop:step] |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
629 data.reverse() |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
630 L[start:stop:step] = data |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
631 a[start:stop:step] = array.array(self.typecode, data) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
63129
diff
changeset
|
632 self.assertEqual(a, array.array(self.typecode, L)) |
|
42951
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
633 |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
634 del L[start:stop:step] |
|
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
635 del a[start:stop:step] |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
63129
diff
changeset
|
636 self.assertEqual(a, array.array(self.typecode, L)) |
|
42951
9620134010a5
Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents:
41362
diff
changeset
|
637 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
638 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
|
639 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
|
640 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
|
641 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
|
642 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
|
643 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
|
644 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
|
645 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
|
646 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
647 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
|
648 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
|
649 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
|
650 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
|
651 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
|
652 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
|
653 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
|
654 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
|
655 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
656 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
|
657 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
|
658 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
|
659 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
|
660 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
|
661 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
|
662 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
|
663 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
|
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 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
|
666 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
|
667 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
668 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
|
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 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
|
671 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
|
672 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
|
673 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
674 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
|
675 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
|
676 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
|
677 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
|
678 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
|
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.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
|
681 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
|
682 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
683 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
|
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.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
|
686 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
|
687 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
688 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
|
689 ) |
|
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.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
|
691 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
|
692 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
|
693 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
694 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
|
695 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
696 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
697 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
|
698 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
|
699 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
|
700 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
|
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, |
|
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, 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
|
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 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
706 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
|
707 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
|
708 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
|
709 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
|
710 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
|
711 a, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
712 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
|
713 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
714 |
|
55117
c6f13934f4c6
Backport test cases added in r73852.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55002
diff
changeset
|
715 a = array.array(self.typecode, self.example) |
|
c6f13934f4c6
Backport test cases added in r73852.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55002
diff
changeset
|
716 a.extend(a) |
|
c6f13934f4c6
Backport test cases added in r73852.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55002
diff
changeset
|
717 self.assertEqual( |
|
c6f13934f4c6
Backport test cases added in r73852.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55002
diff
changeset
|
718 a, |
|
c6f13934f4c6
Backport test cases added in r73852.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55002
diff
changeset
|
719 array.array(self.typecode, self.example+self.example) |
|
c6f13934f4c6
Backport test cases added in r73852.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55002
diff
changeset
|
720 ) |
|
c6f13934f4c6
Backport test cases added in r73852.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55002
diff
changeset
|
721 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
722 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
|
723 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
|
724 |
|
31660
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
725 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
|
726 a.extend(self.example[::-1]) |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
727 self.assertEqual( |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
728 a, |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
729 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
|
730 ) |
|
35f56e08727f
SF feature request #686323: Minor array module enhancements
Raymond Hettinger <python@rcn.com>
parents:
31651
diff
changeset
|
731 |
|
33316
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
732 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
|
733 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
|
734 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
|
735 self.assertEqual(a, b) |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
736 |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
737 # non-iterable argument |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
738 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
|
739 |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
740 # 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
|
741 class A: |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
742 def __iter__(self): |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
743 raise UnicodeError |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
744 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
|
745 |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
746 # 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
|
747 def B(): |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
748 raise UnicodeError |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
749 yield None |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
750 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
|
751 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
752 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
|
753 try: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
754 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
|
755 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
|
756 return |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
757 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
|
758 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
|
759 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
|
760 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
|
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 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
|
763 a = array.array(self.typecode, self.example) |
|
59783
c8c840162804
#7092 - Silence more py3k deprecation warnings, using test_support.check_py3k_warnings() helper.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58561
diff
changeset
|
764 with test_support.check_py3k_warnings(): |
|
63572
51102abdec50
Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
63130
diff
changeset
|
765 b = buffer(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
|
766 self.assertEqual(b[0], a.tostring()[0]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
767 |
|
32159
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
768 def test_weakref(self): |
|
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
769 s = array.array(self.typecode, self.example) |
|
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
770 p = proxy(s) |
|
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
771 self.assertEqual(p.tostring(), s.tostring()) |
|
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
772 s = None |
|
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
773 self.assertRaises(ReferenceError, len, p) |
|
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
774 |
|
30039
d8c8fe0c73ed
added test for bug 782369
Skip Montanaro <skip@pobox.com>
parents:
29205
diff
changeset
|
775 def test_bug_782369(self): |
|
d8c8fe0c73ed
added test for bug 782369
Skip Montanaro <skip@pobox.com>
parents:
29205
diff
changeset
|
776 import sys |
|
30040
643ffb7db18f
protect against test problems with Jython
Skip Montanaro <skip@pobox.com>
parents:
30039
diff
changeset
|
777 if hasattr(sys, "getrefcount"): |
|
643ffb7db18f
protect against test problems with Jython
Skip Montanaro <skip@pobox.com>
parents:
30039
diff
changeset
|
778 for i in range(10): |
|
643ffb7db18f
protect against test problems with Jython
Skip Montanaro <skip@pobox.com>
parents:
30039
diff
changeset
|
779 b = array.array('B', range(64)) |
|
643ffb7db18f
protect against test problems with Jython
Skip Montanaro <skip@pobox.com>
parents:
30039
diff
changeset
|
780 rc = sys.getrefcount(10) |
|
643ffb7db18f
protect against test problems with Jython
Skip Montanaro <skip@pobox.com>
parents:
30039
diff
changeset
|
781 for i in range(10): |
|
643ffb7db18f
protect against test problems with Jython
Skip Montanaro <skip@pobox.com>
parents:
30039
diff
changeset
|
782 b = array.array('B', range(64)) |
|
643ffb7db18f
protect against test problems with Jython
Skip Montanaro <skip@pobox.com>
parents:
30039
diff
changeset
|
783 self.assertEqual(rc, sys.getrefcount(10)) |
|
30039
d8c8fe0c73ed
added test for bug 782369
Skip Montanaro <skip@pobox.com>
parents:
29205
diff
changeset
|
784 |
|
40682
77e0f4718a7c
Bug #1486663: don't reject keyword arguments for subclasses of builtin
Georg Brandl <georg@python.org>
parents:
39653
diff
changeset
|
785 def test_subclass_with_kwargs(self): |
|
77e0f4718a7c
Bug #1486663: don't reject keyword arguments for subclasses of builtin
Georg Brandl <georg@python.org>
parents:
39653
diff
changeset
|
786 # SF bug #1486663 -- this used to erroneously raise a TypeError |
|
71226
7bfedb159e82
test_array: make quiet the DeprecationWarning
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68256
diff
changeset
|
787 with warnings.catch_warnings(): |
|
7bfedb159e82
test_array: make quiet the DeprecationWarning
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68256
diff
changeset
|
788 warnings.filterwarnings("ignore", '', DeprecationWarning) |
|
7bfedb159e82
test_array: make quiet the DeprecationWarning
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68256
diff
changeset
|
789 ArraySubclassWithKwargs('b', newarg=1) |
|
32159
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
790 |
|
2c169ca5fa69
Add weakref support to array.array and file objects.
Raymond Hettinger <python@rcn.com>
parents:
31660
diff
changeset
|
791 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
792 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
|
793 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
794 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
|
795 super(StringTest, self).test_setitem() |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
796 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
|
797 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
|
798 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
799 class CharacterTest(StringTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
800 typecode = 'c' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
801 example = '\x01azAZ\x00\xfe' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
802 smallerexample = '\x01azAY\x00\xfe' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
803 biggerexample = '\x01azAZ\x00\xff' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
804 outside = '\x33' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
805 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
|
806 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
807 def test_subbclassing(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
808 class EditableString(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
|
809 def __new__(cls, s, *args, **kwargs): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
810 return array.array.__new__(cls, 'c', s) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
811 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
812 def __init__(self, s, 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
|
813 self.color = color |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
814 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
815 def strip(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
816 self[:] = array.array('c', self.tostring().strip()) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
817 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
818 def __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
|
819 return 'EditableString(%r)' % self.tostring() |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
820 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
821 s = EditableString("\ttest\r\n") |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
822 s.strip() |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
823 self.assertEqual(s.tostring(), "test") |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
824 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
825 self.assertEqual(s.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
|
826 s.color = "red" |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
827 self.assertEqual(s.color, "red") |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
828 self.assertEqual(s.__dict__.keys(), ["color"]) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
829 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
830 def test_nounicode(self): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
831 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
|
832 self.assertRaises(ValueError, a.fromunicode, unicode('')) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
833 self.assertRaises(ValueError, a.tounicode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
834 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
835 tests.append(CharacterTest) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
836 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
837 if test_support.have_unicode: |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
838 class UnicodeTest(StringTest): |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
839 typecode = 'u' |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
840 example = unicode(r'\x01\u263a\x00\ufeff', 'unicode-escape') |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
841 smallerexample = unicode(r'\x01\u263a\x00\ufefe', 'unicode-escape') |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
842 biggerexample = unicode(r'\x01\u263a\x01\ufeff', 'unicode-escape') |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
843 outside = unicode('\x33') |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
844 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
|
845 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
846 def test_unicode(self): |
|
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.assertRaises(TypeError, array.array, 'b', unicode('foo', 'ascii')) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
848 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
849 a = array.array('u', unicode(r'\xa0\xc2\u1234', 'unicode-escape')) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
850 a.fromunicode(unicode(' ', 'ascii')) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
851 a.fromunicode(unicode('', 'ascii')) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
852 a.fromunicode(unicode('', 'ascii')) |
|
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.fromunicode(unicode(r'\x11abc\xff\u1234', 'unicode-escape')) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
854 s = a.tounicode() |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
855 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
|
856 s, |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
857 unicode(r'\xa0\xc2\u1234 \x11abc\xff\u1234', 'unicode-escape') |
|
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 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
860 s = unicode(r'\x00="\'a\\b\x80\xff\u0000\u0001\u1234', 'unicode-escape') |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
861 a = array.array('u', s) |
|
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.assertEqual( |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
863 repr(a), |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
864 r"""array('u', u'\x00="\'a\\b\x80\xff\x00\x01\u1234')""" |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
865 ) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
866 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
867 self.assertRaises(TypeError, a.fromunicode) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
868 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
869 tests.append(UnicodeTest) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
870 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
871 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
|
872 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
873 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
|
874 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
|
875 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
|
876 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
|
877 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
|
878 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
|
879 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
|
880 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
|
881 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
|
882 self.assertEqual(a[100:-100:-1], 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
|
883 self.assertEqual(a[-100L:100L:2L], 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
|
884 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
|
885 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
|
886 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
887 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
|
888 a = array.array(self.typecode, range(5)) |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
889 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
|
890 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
|
891 a = array.array(self.typecode, range(5)) |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
892 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
|
893 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
|
894 a = array.array(self.typecode, range(5)) |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
895 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
|
896 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
|
897 a = array.array(self.typecode, range(10)) |
| 24424 | 898 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
|
899 self.assertEqual(a, array.array(self.typecode, [1,2,3,4,5,6,7,8,9])) |
|
58562
3ce860b9e732
Merged revisions 77821 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50305
diff
changeset
|
900 # test issue7788 |
|
3ce860b9e732
Merged revisions 77821 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50305
diff
changeset
|
901 a = array.array(self.typecode, range(10)) |
|
3ce860b9e732
Merged revisions 77821 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50305
diff
changeset
|
902 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
|
903 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
904 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
|
905 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
|
906 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
|
907 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
|
908 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
|
909 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
|
910 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
|
911 a = array.array(self.typecode, range(4)) |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
912 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
|
913 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
|
914 a = array.array(self.typecode, range(10)) |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
915 b = a[:] |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
916 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
|
917 ins = array.array(self.typecode, range(2)) |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
918 a[2:3] = ins |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
919 b[slice(2,3)] = ins |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23459
diff
changeset
|
920 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
|
921 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
922 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
|
923 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
|
924 self.assertEqual(list(a), 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
|
925 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
|
926 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
|
927 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
|
928 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
929 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
|
930 # 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
|
931 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
932 # 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
|
933 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
|
934 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
|
935 # 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
|
936 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
|
937 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
|
938 # 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
|
939 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
|
940 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
|
941 # 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
|
942 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
|
943 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
|
944 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
945 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
|
946 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
|
947 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
|
948 __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
|
949 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
950 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
|
951 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
|
952 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
953 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
|
954 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
|
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 __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
|
957 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
|
958 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
959 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
|
960 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
|
961 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
962 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
|
963 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
964 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
|
965 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
|
966 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
|
967 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
|
968 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
|
969 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
970 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
|
971 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
|
972 lower = -1 * long(pow(2, a.itemsize * 8 - 1)) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
973 upper = long(pow(2, a.itemsize * 8 - 1)) - 1L |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
974 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
|
975 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
976 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
|
977 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
|
978 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
|
979 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
|
980 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
|
981 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
982 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
|
983 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
|
984 lower = 0 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
985 upper = long(pow(2, a.itemsize * 8)) - 1L |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
986 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
|
987 |
|
78492
91382d4e2dfb
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
71226
diff
changeset
|
988 @test_support.cpython_only |
|
91382d4e2dfb
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
71226
diff
changeset
|
989 def test_sizeof_with_buffer(self): |
|
91382d4e2dfb
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
71226
diff
changeset
|
990 a = array.array(self.typecode, self.example) |
|
91382d4e2dfb
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
71226
diff
changeset
|
991 basesize = test_support.calcvobjsize('4P') |
|
91382d4e2dfb
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
71226
diff
changeset
|
992 buffer_size = a.buffer_info()[1] * a.itemsize |
|
91382d4e2dfb
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
71226
diff
changeset
|
993 test_support.check_sizeof(self, a, basesize + buffer_size) |
|
91382d4e2dfb
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
71226
diff
changeset
|
994 |
|
91382d4e2dfb
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
71226
diff
changeset
|
995 @test_support.cpython_only |
|
91382d4e2dfb
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
71226
diff
changeset
|
996 def test_sizeof_without_buffer(self): |
|
91382d4e2dfb
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
71226
diff
changeset
|
997 a = array.array(self.typecode) |
|
91382d4e2dfb
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
71226
diff
changeset
|
998 basesize = test_support.calcvobjsize('4P') |
|
91382d4e2dfb
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
71226
diff
changeset
|
999 test_support.check_sizeof(self, a, basesize) |
|
91382d4e2dfb
Issue #15424: Add a __sizeof__ implementation for array objects.
Meador Inge <meadori@gmail.com>
parents:
71226
diff
changeset
|
1000 |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
1001 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1002 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
|
1003 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
|
1004 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
|
1005 tests.append(ByteTest) |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
14649
diff
changeset
|
1006 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1007 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
|
1008 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
|
1009 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
|
1010 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
|
1011 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1012 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
|
1013 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
|
1014 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
|
1015 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
|
1016 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1017 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
|
1018 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
|
1019 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
|
1020 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
|
1021 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1022 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
|
1023 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
|
1024 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
|
1025 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
|
1026 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1027 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
|
1028 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
|
1029 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
|
1030 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
|
1031 |
|
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 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
|
1033 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
|
1034 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
|
1035 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
|
1036 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1037 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
|
1038 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
|
1039 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
|
1040 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
|
1041 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1042 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
|
1043 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
|
1044 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
|
1045 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
|
1046 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
|
1047 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1048 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
|
1049 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
|
1050 |
|
29204
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1051 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
|
1052 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
|
1053 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
|
1054 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
|
1055 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
|
1056 b.byteswap() |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1057 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
|
1058 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
|
1059 else: |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1060 # 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
|
1061 # 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
|
1062 # => compare the 8bit string values instead |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1063 self.assertNotEqual(a.tostring(), b.tostring()) |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1064 b.byteswap() |
|
b1f643690a88
test_byteswap() fails on alphas, because treating the byte swapped bit
Walter Dörwald <walter@livinglogic.de>
parents:
29163
diff
changeset
|
1065 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
|
1066 |
|
29205
56ffca02c824
Walter's last checkin also needs to work on doubles.
Neal Norwitz <nnorwitz@gmail.com>
parents:
29204
diff
changeset
|
1067 class FloatTest(FPTest): |
|
56ffca02c824
Walter's last checkin also needs to work on doubles.
Neal Norwitz <nnorwitz@gmail.com>
parents:
29204
diff
changeset
|
1068 typecode = 'f' |
|
56ffca02c824
Walter's last checkin also needs to work on doubles.
Neal Norwitz <nnorwitz@gmail.com>
parents:
29204
diff
changeset
|
1069 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
|
1070 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
|
1071 |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1072 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
|
1073 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
|
1074 minitemsize = 8 |
|
47587
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
46388
diff
changeset
|
1075 |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
46388
diff
changeset
|
1076 def test_alloc_overflow(self): |
|
49362
ea53163b06de
fix for issue 3862: test_array fails FreeBSD 7 amd64
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
47587
diff
changeset
|
1077 from sys import maxsize |
|
47587
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
46388
diff
changeset
|
1078 a = array.array('d', [-1]*65536) |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
46388
diff
changeset
|
1079 try: |
|
49362
ea53163b06de
fix for issue 3862: test_array fails FreeBSD 7 amd64
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
47587
diff
changeset
|
1080 a *= maxsize//65536 + 1 |
|
47587
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
46388
diff
changeset
|
1081 except MemoryError: |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
46388
diff
changeset
|
1082 pass |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
46388
diff
changeset
|
1083 else: |
|
49362
ea53163b06de
fix for issue 3862: test_array fails FreeBSD 7 amd64
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
47587
diff
changeset
|
1084 self.fail("Array of size > maxsize created - MemoryError expected") |
|
47587
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
46388
diff
changeset
|
1085 b = array.array('d', [ 2.71828183, 3.14159265, -1]) |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
46388
diff
changeset
|
1086 try: |
|
49362
ea53163b06de
fix for issue 3862: test_array fails FreeBSD 7 amd64
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
47587
diff
changeset
|
1087 b * (maxsize//3 + 1) |
|
47587
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
46388
diff
changeset
|
1088 except MemoryError: |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
46388
diff
changeset
|
1089 pass |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
46388
diff
changeset
|
1090 else: |
|
49362
ea53163b06de
fix for issue 3862: test_array fails FreeBSD 7 amd64
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
47587
diff
changeset
|
1091 self.fail("Array of size > maxsize created - MemoryError expected") |
|
47587
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
46388
diff
changeset
|
1092 |
|
29157
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1093 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
|
1094 |
|
33316
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1095 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
|
1096 import sys |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1097 |
|
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 test_support.run_unittest(*tests) |
|
7f0074ee8ab9
Port test_array and test_winsound to PyUnit. Enhance tests for array
Walter Dörwald <walter@livinglogic.de>
parents:
27128
diff
changeset
|
1099 |
|
33316
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1100 # verify reference counting |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1101 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
|
1102 import gc |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1103 counts = [None] * 5 |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1104 for i in xrange(len(counts)): |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1105 test_support.run_unittest(*tests) |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1106 gc.collect() |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1107 counts[i] = sys.gettotalrefcount() |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1108 print counts |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1109 |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1110 if __name__ == "__main__": |
|
0b181bf230c9
SF feature request #992967: array.array objects should support sequences.
Raymond Hettinger <python@rcn.com>
parents:
32159
diff
changeset
|
1111 test_main(verbose=True) |
