annotate Lib/test/list_tests.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 11bf59fe10b9
children 3ce860b9e732 7caf54ce529e
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))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
39 self.assertEqual(`a2`, `l2`)
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:
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
60 fo = open(test_support.TESTFN, "wb")
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
61 print >> fo, d,
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
62 fo.close()
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
63 fo = open(test_support.TESTFN, "rb")
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
64 self.assertEqual(fo.read(), repr(d))
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
65 finally:
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
66 fo.close()
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
67 os.remove(test_support.TESTFN)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
68
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
69 def test_set_subscript(self):
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
70 a = self.type2test(range(20))
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
71 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
72 self.assertRaises(TypeError, a.__setitem__, slice(0, 10), 1)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
73 self.assertRaises(ValueError, a.__setitem__, slice(0, 10, 2), [1,2])
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
74 self.assertRaises(TypeError, a.__getitem__, 'x', 1)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
75 a[slice(2,10,3)] = [1,2,3]
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
76 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
77 9, 10, 11, 12, 13, 14, 15,
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
78 16, 17, 18, 19]))
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
79
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
80 def test_reversed(self):
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
81 a = self.type2test(range(20))
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
82 r = reversed(a)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
83 self.assertEqual(list(r), self.type2test(range(19, -1, -1)))
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
84 self.assertRaises(StopIteration, r.next)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
85 self.assertEqual(list(reversed(self.type2test())),
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
86 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
87 # 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
88 self.assertRaises(TypeError, len, reversed([1,2,3]))
33623
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
89
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
90 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
91 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
92 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
93 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
94 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
95 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
96 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
97 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
98 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
99 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
100 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
101
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
102 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
103 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
104 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
105 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
106
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 = 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
108 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
109 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
110 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
111 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
112 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
113 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
114 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
115 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
116 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
117 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
118 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
119 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
120 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
121 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
122
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
123 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
124 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
125 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
126 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
127 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
128 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
129
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
130 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
131 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
132 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
133 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
134 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
135
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
136 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
137 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
138 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
139
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
140 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
141 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
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 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
144
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
145 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
146 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
147 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
148
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
149 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
150 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
151 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
152 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 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
154 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
155 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
156 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
157 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 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
159 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
160 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
161 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
162 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
163 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 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
165 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
166
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
167 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
168 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
169 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
170 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
171 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
172
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
173 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
174 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
175 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
176 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
177 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
178 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
179 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
180 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
181 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
182
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
183 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
184 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
185 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
186
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
187 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
188 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
189
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
190 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
191 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
192
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
193 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
194 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
195 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
196 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
197 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
198
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
199 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
200 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
201 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
202 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
203
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
204 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
205 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
206 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
207
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
208 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
209 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
210 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
211
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
212 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
213 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
214 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
215 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
216
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
217 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
218 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
219 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
220 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
221
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
222 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
223 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
224 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
225
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
226 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
227 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
228 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
229
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
230 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
231 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
232 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
233
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
234 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
235 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
236 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
237 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
238 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
239 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
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 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
242
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
243 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
244 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
245 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
246 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
247 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
248 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
249
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
250 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
251 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
252
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
253 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
254 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
255
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
256 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
257 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
258 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
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, None)
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 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
263
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
264 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
265 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
266 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
267 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
268 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
269 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
270
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 = a[:]
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(-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
273 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
274 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
275 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
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 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
278
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
279 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
280 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
281 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
282 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
283 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
284 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
285 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
286 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
287 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
288 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
289 self.assertRaises(TypeError, a.pop, 42, 42)
33623
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
290 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
291
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
292 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
293 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
294 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
295 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
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, [0])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
298 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
299 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
300
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(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
302
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
303 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
304
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
305 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
306 pass
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
307
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
308 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
309 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
310 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
311 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
312 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
313
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
314 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
315 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
316
34795
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
317 class BadCmp2:
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
318 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
319 raise BadExc()
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
320
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
321 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
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('abdefghcij'))
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
324 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 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
327 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
328
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
329 # 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
330 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
331 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
332 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
333 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
334 # verify that original order and values are retained.
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
335 self.assert_(x is y)
4c13b0146b3f Add list tests that ensure that remove() removes the first occurrence.
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
336
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
337 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
338 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
339 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
340 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
341 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
342
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
343 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
344
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
345 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
346 pass
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
347
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
348 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
349 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
350 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
351 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
352 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
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 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
355
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
356 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
357 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
358 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
359 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
360 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
361
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
362 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
363 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
364 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
365 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
366 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
367 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
368 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
369 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
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 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
372
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
373 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
374 pass
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
375
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
376 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
377 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
378 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
379 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
380 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
381
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
382 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
383 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
384
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
385 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
386 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
387 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
388 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
389 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
390 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
391 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
392 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
393 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
394 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
395 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
396 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
397 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
398 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
399 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
400
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
401 # 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
402 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
403 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
404 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
405 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
406 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
407 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
408 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
409 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
410 # 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
411 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
412
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
413 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
414 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
415 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
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, [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
418 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
419 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
420
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
421 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
422
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
423 def test_sort(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
424 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
425 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
426 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
427
31159
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 = 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
429 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
430 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
431
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
432 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
433
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
434 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
435 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
436 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
437 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
438
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
439 # 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
440 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
441 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
442 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
443 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
444
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
445 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
446
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
447 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
448 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
449 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
450 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
451
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
452 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
453
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
454 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
455
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
456 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
457 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
458 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
459 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
460
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
461 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
462 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
463 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
464 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
465 u += [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
466 self.assert_(u is u2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
467
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 = 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
469 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
470 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
471
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
472 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
473
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
474 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
475 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
476 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
477 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
478 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
479 self.assertEqual(u, self.type2test([]))
33623
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
480 s = self.type2test([])
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
481 oldid = id(s)
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
482 s *= 10
8e9dcfe14d81 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 33114
diff changeset
483 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
484
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
485 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
486 # subscript
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
487 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
488
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
489 # deletion
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
490 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
491 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
492 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
493 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
494 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
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,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
498 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
499 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
500 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
501 # assignment
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
502 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
503 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
504 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
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[::-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
507 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
508 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
509 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
510 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
511 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
512 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
513 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
514 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
515 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
516 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
517 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
518 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
519 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
520 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
521 self.assertEqual(a, self.type2test([0, 1, 1, 3, 2, 5, 3, 7, 4, 9]))
35364
aeb8580a1af7 SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Raymond Hettinger <python@rcn.com>
parents: 34795
diff changeset
522
aeb8580a1af7 SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Raymond Hettinger <python@rcn.com>
parents: 34795
diff changeset
523 def test_constructor_exception_handling(self):
aeb8580a1af7 SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Raymond Hettinger <python@rcn.com>
parents: 34795
diff changeset
524 # Bug #1242657
aeb8580a1af7 SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Raymond Hettinger <python@rcn.com>
parents: 34795
diff changeset
525 class F(object):
aeb8580a1af7 SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Raymond Hettinger <python@rcn.com>
parents: 34795
diff changeset
526 def __iter__(self):
aeb8580a1af7 SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Raymond Hettinger <python@rcn.com>
parents: 34795
diff changeset
527 raise KeyboardInterrupt
aeb8580a1af7 SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Raymond Hettinger <python@rcn.com>
parents: 34795
diff changeset
528 self.assertRaises(KeyboardInterrupt, list, F())