annotate Lib/test/list_tests.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 19ffa12ffdd4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
1 """
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
2 Tests common to list and UserList.UserList
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
3 """
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
4
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
5 import sys
33623
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
6 import os
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
7
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
8 from test import test_support, seq_tests
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
9
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
10 class CommonTest(seq_tests.CommonTest):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
11
33623
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
12 def test_init(self):
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
13 # Iterable arg is optional
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
14 self.assertEqual(self.type2test([]), self.type2test())
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
15
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
16 # Init clears previous values
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
17 a = self.type2test([1, 2, 3])
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
18 a.__init__()
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
19 self.assertEqual(a, self.type2test([]))
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
20
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
21 # Init overwrites previous values
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
22 a = self.type2test([1, 2, 3])
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
23 a.__init__([4, 5, 6])
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
24 self.assertEqual(a, self.type2test([4, 5, 6]))
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
25
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
26 # Mutables always return a new object
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
27 b = self.type2test(a)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
28 self.assertNotEqual(id(a), id(b))
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
29 self.assertEqual(a, b)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
30
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
31 def test_repr(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
32 l0 = []
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
33 l2 = [0, 1, 2]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
34 a0 = self.type2test(l0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
35 a2 = self.type2test(l2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
36
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
37 self.assertEqual(str(a0), str(l0))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
38 self.assertEqual(repr(a0), repr(l0))
63572
51102abdec50 Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61627
diff changeset
39 self.assertEqual(repr(a2), repr(l2))
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
40 self.assertEqual(str(a2), "[0, 1, 2]")
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
41 self.assertEqual(repr(a2), "[0, 1, 2]")
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
42
33623
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
43 a2.append(a2)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
44 a2.append(3)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
45 self.assertEqual(str(a2), "[0, 1, 2, [...], 3]")
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
46 self.assertEqual(repr(a2), "[0, 1, 2, [...], 3]")
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
47
43324
4a6c788226f5 Fix a possible segfault from recursing too deep to get the repr of a list.
Brett Cannon <bcannon@gmail.com>
parents: 42951
diff changeset
48 l0 = []
4a6c788226f5 Fix a possible segfault from recursing too deep to get the repr of a list.
Brett Cannon <bcannon@gmail.com>
parents: 42951
diff changeset
49 for i in xrange(sys.getrecursionlimit() + 100):
4a6c788226f5 Fix a possible segfault from recursing too deep to get the repr of a list.
Brett Cannon <bcannon@gmail.com>
parents: 42951
diff changeset
50 l0 = [l0]
4a6c788226f5 Fix a possible segfault from recursing too deep to get the repr of a list.
Brett Cannon <bcannon@gmail.com>
parents: 42951
diff changeset
51 self.assertRaises(RuntimeError, repr, l0)
4a6c788226f5 Fix a possible segfault from recursing too deep to get the repr of a list.
Brett Cannon <bcannon@gmail.com>
parents: 42951
diff changeset
52
33623
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
53 def test_print(self):
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
54 d = self.type2test(xrange(200))
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
55 d.append(d)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
56 d.extend(xrange(200,400))
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
57 d.append(d)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
58 d.append(400)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
59 try:
61627
f350acbce790 Merged revisions 81224 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 58562
diff changeset
60 with open(test_support.TESTFN, "wb") as fo:
f350acbce790 Merged revisions 81224 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 58562
diff changeset
61 print >> fo, d,
f350acbce790 Merged revisions 81224 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 58562
diff changeset
62 with open(test_support.TESTFN, "rb") as fo:
f350acbce790 Merged revisions 81224 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 58562
diff changeset
63 self.assertEqual(fo.read(), repr(d))
33623
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
64 finally:
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
65 os.remove(test_support.TESTFN)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
66
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
67 def test_set_subscript(self):
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
68 a = self.type2test(range(20))
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
69 self.assertRaises(ValueError, a.__setitem__, slice(0, 10, 0), [1,2,3])
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
70 self.assertRaises(TypeError, a.__setitem__, slice(0, 10), 1)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
71 self.assertRaises(ValueError, a.__setitem__, slice(0, 10, 2), [1,2])
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
72 self.assertRaises(TypeError, a.__getitem__, 'x', 1)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
73 a[slice(2,10,3)] = [1,2,3]
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
74 self.assertEqual(a, self.type2test([0, 1, 1, 3, 4, 2, 6, 7, 3,
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
75 9, 10, 11, 12, 13, 14, 15,
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
76 16, 17, 18, 19]))
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
77
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
78 def test_reversed(self):
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
79 a = self.type2test(range(20))
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
80 r = reversed(a)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
81 self.assertEqual(list(r), self.type2test(range(19, -1, -1)))
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
82 self.assertRaises(StopIteration, r.next)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
83 self.assertEqual(list(reversed(self.type2test())),
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
84 self.type2test())
50008
11bf59fe10b9 Merged revisions 67326,67498,67531-67532,67538,67553-67554,67556-67557 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45468
diff changeset
85 # Bug 3689: make sure list-reversed-iterator doesn't have __len__
11bf59fe10b9 Merged revisions 67326,67498,67531-67532,67538,67553-67554,67556-67557 via svnmerge from
Georg Brandl <georg@python.org>
parents: 45468
diff changeset
86 self.assertRaises(TypeError, len, reversed([1,2,3]))
33623
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
87
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
88 def test_setitem(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
89 a = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
90 a[0] = 0
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
91 a[1] = 100
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
92 self.assertEqual(a, self.type2test([0, 100]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
93 a[-1] = 200
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
94 self.assertEqual(a, self.type2test([0, 200]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
95 a[-2] = 100
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
96 self.assertEqual(a, self.type2test([100, 200]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
97 self.assertRaises(IndexError, a.__setitem__, -3, 200)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
98 self.assertRaises(IndexError, a.__setitem__, 2, 200)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
99
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
100 a = self.type2test([])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
101 self.assertRaises(IndexError, a.__setitem__, 0, 200)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
102 self.assertRaises(IndexError, a.__setitem__, -1, 200)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
103 self.assertRaises(TypeError, a.__setitem__)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
104
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
105 a = self.type2test([0,1,2,3,4])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
106 a[0L] = 1
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
107 a[1L] = 2
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
108 a[2L] = 3
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
109 self.assertEqual(a, self.type2test([1,2,3,3,4]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
110 a[0] = 5
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
111 a[1] = 6
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
112 a[2] = 7
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
113 self.assertEqual(a, self.type2test([5,6,7,3,4]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
114 a[-2L] = 88
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
115 a[-1L] = 99
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
116 self.assertEqual(a, self.type2test([5,6,7,88,99]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
117 a[-2] = 8
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
118 a[-1] = 9
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
119 self.assertEqual(a, self.type2test([5,6,7,8,9]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
120
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
121 def test_delitem(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
122 a = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
123 del a[1]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
124 self.assertEqual(a, [0])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
125 del a[0]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
126 self.assertEqual(a, [])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
127
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
128 a = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
129 del a[-2]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
130 self.assertEqual(a, [1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
131 del a[-1]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
132 self.assertEqual(a, [])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
133
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
134 a = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
135 self.assertRaises(IndexError, a.__delitem__, -3)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
136 self.assertRaises(IndexError, a.__delitem__, 2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
137
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
138 a = self.type2test([])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
139 self.assertRaises(IndexError, a.__delitem__, 0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
140
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
141 self.assertRaises(TypeError, a.__delitem__)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
142
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
143 def test_setslice(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
144 l = [0, 1]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
145 a = self.type2test(l)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
146
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
147 for i in range(-3, 4):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
148 a[:i] = l[:i]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
149 self.assertEqual(a, l)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
150 a2 = a[:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
151 a2[:i] = a[:i]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
152 self.assertEqual(a2, a)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
153 a[i:] = l[i:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
154 self.assertEqual(a, l)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
155 a2 = a[:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
156 a2[i:] = a[i:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
157 self.assertEqual(a2, a)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
158 for j in range(-3, 4):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
159 a[i:j] = l[i:j]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
160 self.assertEqual(a, l)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
161 a2 = a[:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
162 a2[i:j] = a[i:j]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
163 self.assertEqual(a2, a)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
164
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
165 aa2 = a2[:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
166 aa2[:0] = [-2, -1]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
167 self.assertEqual(aa2, [-2, -1, 0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
168 aa2[0:] = []
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
169 self.assertEqual(aa2, [])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
170
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
171 a = self.type2test([1, 2, 3, 4, 5])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
172 a[:-1] = a
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
173 self.assertEqual(a, self.type2test([1, 2, 3, 4, 5, 5]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
174 a = self.type2test([1, 2, 3, 4, 5])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
175 a[1:] = a
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
176 self.assertEqual(a, self.type2test([1, 1, 2, 3, 4, 5]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
177 a = self.type2test([1, 2, 3, 4, 5])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
178 a[1:-1] = a
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
179 self.assertEqual(a, self.type2test([1, 1, 2, 3, 4, 5, 5]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
180
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
181 a = self.type2test([])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
182 a[:] = tuple(range(10))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
183 self.assertEqual(a, self.type2test(range(10)))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
184
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
185 self.assertRaises(TypeError, a.__setslice__, 0, 1, 5)
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 39995
diff changeset
186 self.assertRaises(TypeError, a.__setitem__, slice(0, 1, 5))
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
187
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
188 self.assertRaises(TypeError, a.__setslice__)
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 39995
diff changeset
189 self.assertRaises(TypeError, a.__setitem__)
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
190
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
191 def test_delslice(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
192 a = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
193 del a[1:2]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
194 del a[0:1]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
195 self.assertEqual(a, self.type2test([]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
196
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
197 a = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
198 del a[1L:2L]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
199 del a[0L:1L]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
200 self.assertEqual(a, self.type2test([]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
201
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
202 a = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
203 del a[-2:-1]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
204 self.assertEqual(a, self.type2test([1]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
205
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
206 a = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
207 del a[-2L:-1L]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
208 self.assertEqual(a, self.type2test([1]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
209
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
210 a = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
211 del a[1:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
212 del a[:1]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
213 self.assertEqual(a, self.type2test([]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
214
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
215 a = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
216 del a[1L:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
217 del a[:1L]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
218 self.assertEqual(a, self.type2test([]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
219
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
220 a = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
221 del a[-1:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
222 self.assertEqual(a, self.type2test([0]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
223
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
224 a = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
225 del a[-1L:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
226 self.assertEqual(a, self.type2test([0]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
227
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
228 a = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
229 del a[:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
230 self.assertEqual(a, self.type2test([]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
231
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
232 def test_append(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
233 a = self.type2test([])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
234 a.append(0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
235 a.append(1)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
236 a.append(2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
237 self.assertEqual(a, self.type2test([0, 1, 2]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
238
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
239 self.assertRaises(TypeError, a.append)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
240
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
241 def test_extend(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
242 a1 = self.type2test([0])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
243 a2 = self.type2test((0, 1))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
244 a = a1[:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
245 a.extend(a2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
246 self.assertEqual(a, a1 + a2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
247
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
248 a.extend(self.type2test([]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
249 self.assertEqual(a, a1 + a2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
250
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
251 a.extend(a)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
252 self.assertEqual(a, self.type2test([0, 0, 1, 0, 0, 1]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
253
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
254 a = self.type2test("spam")
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
255 a.extend("eggs")
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
256 self.assertEqual(a, list("spameggs"))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
257
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
258 self.assertRaises(TypeError, a.extend, None)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
259
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
260 self.assertRaises(TypeError, a.extend)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
261
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
262 def test_insert(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
263 a = self.type2test([0, 1, 2])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
264 a.insert(0, -2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
265 a.insert(1, -1)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
266 a.insert(2, 0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
267 self.assertEqual(a, [-2, -1, 0, 0, 1, 2])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
268
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
269 b = a[:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
270 b.insert(-2, "foo")
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
271 b.insert(-200, "left")
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
272 b.insert(200, "right")
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
273 self.assertEqual(b, self.type2test(["left",-2,-1,0,0,"foo",1,2,"right"]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
274
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
275 self.assertRaises(TypeError, a.insert)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
276
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
277 def test_pop(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
278 a = self.type2test([-1, 0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
279 a.pop()
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
280 self.assertEqual(a, [-1, 0])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
281 a.pop(0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
282 self.assertEqual(a, [0])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
283 self.assertRaises(IndexError, a.pop, 5)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
284 a.pop(0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
285 self.assertEqual(a, [])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
286 self.assertRaises(IndexError, a.pop)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
287 self.assertRaises(TypeError, a.pop, 42, 42)
33623
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
288 a = self.type2test([0, 10, 20, 30, 40])
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
289
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
290 def test_remove(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
291 a = self.type2test([0, 0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
292 a.remove(1)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
293 self.assertEqual(a, [0, 0])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
294 a.remove(0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
295 self.assertEqual(a, [0])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
296 a.remove(0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
297 self.assertEqual(a, [])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
298
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
299 self.assertRaises(ValueError, a.remove, 0)
31392
c9bed200500e For whatever reason, these files had \r\r\n line endings on Windows,
Tim Peters <tim.peters@gmail.com>
parents: 31159
diff changeset
300
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
301 self.assertRaises(TypeError, a.remove)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
302
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
303 class BadExc(Exception):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
304 pass
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
305
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
306 class BadCmp:
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
307 def __eq__(self, other):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
308 if other == 2:
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
309 raise BadExc()
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
310 return False
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
311
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
312 a = self.type2test([0, 1, 2, 3])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
313 self.assertRaises(BadExc, a.remove, BadCmp())
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
314
34795
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
315 class BadCmp2:
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
316 def __eq__(self, other):
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
317 raise BadExc()
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
318
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
319 d = self.type2test('abcdefghcij')
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
320 d.remove('c')
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
321 self.assertEqual(d, self.type2test('abdefghcij'))
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
322 d.remove('c')
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
323 self.assertEqual(d, self.type2test('abdefghij'))
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
324 self.assertRaises(ValueError, d.remove, 'c')
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
325 self.assertEqual(d, self.type2test('abdefghij'))
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
326
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
327 # Handle comparison errors
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
328 d = self.type2test(['a', 'b', BadCmp2(), 'c'])
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
329 e = self.type2test(d)
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
330 self.assertRaises(BadExc, d.remove, 'c')
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
331 for x, y in zip(d, e):
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
332 # verify that original order and values are retained.
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61626
diff changeset
333 self.assertIs(x, y)
34795
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
334
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
335 def test_count(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
336 a = self.type2test([0, 1, 2])*3
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
337 self.assertEqual(a.count(0), 3)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
338 self.assertEqual(a.count(1), 3)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
339 self.assertEqual(a.count(3), 0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
340
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
341 self.assertRaises(TypeError, a.count)
31392
c9bed200500e For whatever reason, these files had \r\r\n line endings on Windows,
Tim Peters <tim.peters@gmail.com>
parents: 31159
diff changeset
342
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
343 class BadExc(Exception):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
344 pass
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
345
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
346 class BadCmp:
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
347 def __eq__(self, other):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
348 if other == 2:
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
349 raise BadExc()
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
350 return False
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
351
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
352 self.assertRaises(BadExc, a.count, BadCmp())
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
353
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
354 def test_index(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
355 u = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
356 self.assertEqual(u.index(0), 0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
357 self.assertEqual(u.index(1), 1)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
358 self.assertRaises(ValueError, u.index, 2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
359
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
360 u = self.type2test([-2, -1, 0, 0, 1, 2])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
361 self.assertEqual(u.count(0), 2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
362 self.assertEqual(u.index(0), 2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
363 self.assertEqual(u.index(0, 2), 2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
364 self.assertEqual(u.index(-2, -10), 0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
365 self.assertEqual(u.index(0, 3), 3)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
366 self.assertEqual(u.index(0, 3, 4), 3)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
367 self.assertRaises(ValueError, u.index, 2, 0, -10)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
368
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
369 self.assertRaises(TypeError, u.index)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
370
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
371 class BadExc(Exception):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
372 pass
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
373
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
374 class BadCmp:
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
375 def __eq__(self, other):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
376 if other == 2:
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
377 raise BadExc()
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
378 return False
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
379
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
380 a = self.type2test([0, 1, 2, 3])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
381 self.assertRaises(BadExc, a.index, BadCmp())
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
382
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
383 a = self.type2test([-2, -1, 0, 0, 1, 2])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
384 self.assertEqual(a.index(0), 2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
385 self.assertEqual(a.index(0, 2), 2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
386 self.assertEqual(a.index(0, -4), 2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
387 self.assertEqual(a.index(-2, -10), 0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
388 self.assertEqual(a.index(0, 3), 3)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
389 self.assertEqual(a.index(0, -3), 3)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
390 self.assertEqual(a.index(0, 3, 4), 3)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
391 self.assertEqual(a.index(0, -3, -2), 3)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
392 self.assertEqual(a.index(0, -4*sys.maxint, 4*sys.maxint), 2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
393 self.assertRaises(ValueError, a.index, 0, 4*sys.maxint,-4*sys.maxint)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
394 self.assertRaises(ValueError, a.index, 2, 0, -10)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
395 a.remove(0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
396 self.assertRaises(ValueError, a.index, 2, 0, 4)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
397 self.assertEqual(a, self.type2test([-2, -1, 0, 1, 2]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
398
33114
e4a73efa4d23 SF patch #1005778, Fix seg fault if list object is modified during list.index()
Neal Norwitz <nnorwitz@gmail.com>
parents: 31392
diff changeset
399 # Test modifying the list during index's iteration
e4a73efa4d23 SF patch #1005778, Fix seg fault if list object is modified during list.index()
Neal Norwitz <nnorwitz@gmail.com>
parents: 31392
diff changeset
400 class EvilCmp:
e4a73efa4d23 SF patch #1005778, Fix seg fault if list object is modified during list.index()
Neal Norwitz <nnorwitz@gmail.com>
parents: 31392
diff changeset
401 def __init__(self, victim):
e4a73efa4d23 SF patch #1005778, Fix seg fault if list object is modified during list.index()
Neal Norwitz <nnorwitz@gmail.com>
parents: 31392
diff changeset
402 self.victim = victim
e4a73efa4d23 SF patch #1005778, Fix seg fault if list object is modified during list.index()
Neal Norwitz <nnorwitz@gmail.com>
parents: 31392
diff changeset
403 def __eq__(self, other):
e4a73efa4d23 SF patch #1005778, Fix seg fault if list object is modified during list.index()
Neal Norwitz <nnorwitz@gmail.com>
parents: 31392
diff changeset
404 del self.victim[:]
e4a73efa4d23 SF patch #1005778, Fix seg fault if list object is modified during list.index()
Neal Norwitz <nnorwitz@gmail.com>
parents: 31392
diff changeset
405 return False
e4a73efa4d23 SF patch #1005778, Fix seg fault if list object is modified during list.index()
Neal Norwitz <nnorwitz@gmail.com>
parents: 31392
diff changeset
406 a = self.type2test()
e4a73efa4d23 SF patch #1005778, Fix seg fault if list object is modified during list.index()
Neal Norwitz <nnorwitz@gmail.com>
parents: 31392
diff changeset
407 a[:] = [EvilCmp(a) for _ in xrange(100)]
e4a73efa4d23 SF patch #1005778, Fix seg fault if list object is modified during list.index()
Neal Norwitz <nnorwitz@gmail.com>
parents: 31392
diff changeset
408 # This used to seg fault before patch #1005778
e4a73efa4d23 SF patch #1005778, Fix seg fault if list object is modified during list.index()
Neal Norwitz <nnorwitz@gmail.com>
parents: 31392
diff changeset
409 self.assertRaises(ValueError, a.index, None)
e4a73efa4d23 SF patch #1005778, Fix seg fault if list object is modified during list.index()
Neal Norwitz <nnorwitz@gmail.com>
parents: 31392
diff changeset
410
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
411 def test_reverse(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
412 u = self.type2test([-2, -1, 0, 1, 2])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
413 u2 = u[:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
414 u.reverse()
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
415 self.assertEqual(u, [2, 1, 0, -1, -2])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
416 u.reverse()
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
417 self.assertEqual(u, u2)
31392
c9bed200500e For whatever reason, these files had \r\r\n line endings on Windows,
Tim Peters <tim.peters@gmail.com>
parents: 31159
diff changeset
418
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
419 self.assertRaises(TypeError, u.reverse, 42)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
420
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
421 def test_sort(self):
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
422 with test_support.check_py3k_warnings(
63572
51102abdec50 Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61627
diff changeset
423 ("the cmp argument is not supported", DeprecationWarning)):
51102abdec50 Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61627
diff changeset
424 self._test_sort()
51102abdec50 Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61627
diff changeset
425
51102abdec50 Merged revisions 79165 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61627
diff changeset
426 def _test_sort(self):
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
427 u = self.type2test([1, 0])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
428 u.sort()
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
429 self.assertEqual(u, [0, 1])
31392
c9bed200500e For whatever reason, these files had \r\r\n line endings on Windows,
Tim Peters <tim.peters@gmail.com>
parents: 31159
diff changeset
430
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
431 u = self.type2test([2,1,0,-1,-2])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
432 u.sort()
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
433 self.assertEqual(u, self.type2test([-2,-1,0,1,2]))
31392
c9bed200500e For whatever reason, these files had \r\r\n line endings on Windows,
Tim Peters <tim.peters@gmail.com>
parents: 31159
diff changeset
434
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
435 self.assertRaises(TypeError, u.sort, 42, 42)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
436
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
437 def revcmp(a, b):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
438 return cmp(b, a)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
439 u.sort(revcmp)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
440 self.assertEqual(u, self.type2test([2,1,0,-1,-2]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
441
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
442 # The following dumps core in unpatched Python 1.5:
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
443 def myComparison(x,y):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
444 return cmp(x%3, y%7)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
445 z = self.type2test(range(12))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
446 z.sort(myComparison)
31392
c9bed200500e For whatever reason, these files had \r\r\n line endings on Windows,
Tim Peters <tim.peters@gmail.com>
parents: 31159
diff changeset
447
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
448 self.assertRaises(TypeError, z.sort, 2)
31392
c9bed200500e For whatever reason, these files had \r\r\n line endings on Windows,
Tim Peters <tim.peters@gmail.com>
parents: 31159
diff changeset
449
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
450 def selfmodifyingComparison(x,y):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
451 z.append(1)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
452 return cmp(x, y)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
453 self.assertRaises(ValueError, z.sort, selfmodifyingComparison)
31392
c9bed200500e For whatever reason, these files had \r\r\n line endings on Windows,
Tim Peters <tim.peters@gmail.com>
parents: 31159
diff changeset
454
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
455 self.assertRaises(TypeError, z.sort, lambda x, y: 's')
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
456
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
457 self.assertRaises(TypeError, z.sort, 42, 42, 42, 42)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
458
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
459 def test_slice(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
460 u = self.type2test("spam")
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
461 u[:2] = "h"
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
462 self.assertEqual(u, list("ham"))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
463
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
464 def test_iadd(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
465 super(CommonTest, self).test_iadd()
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
466 u = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
467 u2 = u
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
468 u += [2, 3]
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61626
diff changeset
469 self.assertIs(u, u2)
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
470
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
471 u = self.type2test("spam")
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
472 u += "eggs"
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
473 self.assertEqual(u, self.type2test("spameggs"))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
474
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
475 self.assertRaises(TypeError, u.__iadd__, None)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
476
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
477 def test_imul(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
478 u = self.type2test([0, 1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
479 u *= 3
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
480 self.assertEqual(u, self.type2test([0, 1, 0, 1, 0, 1]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
481 u *= 0
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
482 self.assertEqual(u, self.type2test([]))
33623
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
483 s = self.type2test([])
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
484 oldid = id(s)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
485 s *= 10
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
486 self.assertEqual(id(s), oldid)
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
487
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
488 def test_extendedslicing(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
489 # subscript
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
490 a = self.type2test([0,1,2,3,4])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
491
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
492 # deletion
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
493 del a[::2]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
494 self.assertEqual(a, self.type2test([1,3]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
495 a = self.type2test(range(5))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
496 del a[1::2]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
497 self.assertEqual(a, self.type2test([0,2,4]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
498 a = self.type2test(range(5))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
499 del a[1::-2]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
500 self.assertEqual(a, self.type2test([0,2,3,4]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
501 a = self.type2test(range(10))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
502 del a[::1000]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
503 self.assertEqual(a, self.type2test([1, 2, 3, 4, 5, 6, 7, 8, 9]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
504 # assignment
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
505 a = self.type2test(range(10))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
506 a[::2] = [-1]*5
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
507 self.assertEqual(a, self.type2test([-1, 1, -1, 3, -1, 5, -1, 7, -1, 9]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
508 a = self.type2test(range(10))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
509 a[::-4] = [10]*3
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
510 self.assertEqual(a, self.type2test([0, 10, 2, 3, 4, 10, 6, 7, 8 ,10]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
511 a = self.type2test(range(4))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
512 a[::-1] = a
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
513 self.assertEqual(a, self.type2test([3, 2, 1, 0]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
514 a = self.type2test(range(10))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
515 b = a[:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
516 c = a[:]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
517 a[2:3] = self.type2test(["two", "elements"])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
518 b[slice(2,3)] = self.type2test(["two", "elements"])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
519 c[2:3:] = self.type2test(["two", "elements"])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
520 self.assertEqual(a, b)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
521 self.assertEqual(a, c)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
522 a = self.type2test(range(10))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
523 a[::2] = tuple(range(5))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
524 self.assertEqual(a, self.type2test([0, 1, 1, 3, 2, 5, 3, 7, 4, 9]))
58562
3ce860b9e732 Merged revisions 77821 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50008
diff changeset
525 # test issue7788
3ce860b9e732 Merged revisions 77821 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50008
diff changeset
526 a = self.type2test(range(10))
3ce860b9e732 Merged revisions 77821 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50008
diff changeset
527 del a[9::1<<333]
35364
aeb8580a1af7 SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Raymond Hettinger <python@rcn.com>
parents: 34795
diff changeset
528
aeb8580a1af7 SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Raymond Hettinger <python@rcn.com>
parents: 34795
diff changeset
529 def test_constructor_exception_handling(self):
aeb8580a1af7 SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Raymond Hettinger <python@rcn.com>
parents: 34795
diff changeset
530 # Bug #1242657
aeb8580a1af7 SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Raymond Hettinger <python@rcn.com>
parents: 34795
diff changeset
531 class F(object):
aeb8580a1af7 SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Raymond Hettinger <python@rcn.com>
parents: 34795
diff changeset
532 def __iter__(self):
aeb8580a1af7 SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Raymond Hettinger <python@rcn.com>
parents: 34795
diff changeset
533 raise KeyboardInterrupt
aeb8580a1af7 SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Raymond Hettinger <python@rcn.com>
parents: 34795
diff changeset
534 self.assertRaises(KeyboardInterrupt, list, F())