annotate Lib/test/seq_tests.py @ 70817:dd775b1561ba

Fix markup.
author Georg Brandl <georg@python.org>
date Tue, 14 Jun 2011 21:09:55 +0200
parents 3c9232a684ae
children 5c1fcaf3cf1c
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 tuple, 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 unittest
45206
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
6 import sys
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
34802
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
8 # Various iterables
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
9 # This is used for checking the constructor (here and in test_deque.py)
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
10 def iterfunc(seqn):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
11 'Regular generator'
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
12 for i in seqn:
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
13 yield i
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
14
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
15 class Sequence:
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
16 'Sequence using __getitem__'
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
17 def __init__(self, seqn):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
18 self.seqn = seqn
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
19 def __getitem__(self, i):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
20 return self.seqn[i]
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
21
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
22 class IterFunc:
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
23 'Sequence using iterator protocol'
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
24 def __init__(self, seqn):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
25 self.seqn = seqn
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
26 self.i = 0
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
27 def __iter__(self):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
28 return self
41501
0c5019afc55b PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents: 40644
diff changeset
29 def __next__(self):
34802
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
30 if self.i >= len(self.seqn): raise StopIteration
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
31 v = self.seqn[self.i]
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
32 self.i += 1
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
33 return v
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
34
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
35 class IterGen:
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
36 'Sequence using iterator protocol defined with a generator'
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
37 def __init__(self, seqn):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
38 self.seqn = seqn
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
39 self.i = 0
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
40 def __iter__(self):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
41 for val in self.seqn:
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
42 yield val
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
43
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
44 class IterNextOnly:
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
45 'Missing __getitem__ and __iter__'
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
46 def __init__(self, seqn):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
47 self.seqn = seqn
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
48 self.i = 0
41501
0c5019afc55b PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents: 40644
diff changeset
49 def __next__(self):
34802
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
50 if self.i >= len(self.seqn): raise StopIteration
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
51 v = self.seqn[self.i]
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
52 self.i += 1
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
53 return v
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
54
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
55 class IterNoNext:
41501
0c5019afc55b PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents: 40644
diff changeset
56 'Iterator missing __next__()'
34802
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
57 def __init__(self, seqn):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
58 self.seqn = seqn
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
59 self.i = 0
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
60 def __iter__(self):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
61 return self
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
62
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
63 class IterGenExc:
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
64 'Test propagation of exceptions'
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
65 def __init__(self, seqn):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
66 self.seqn = seqn
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
67 self.i = 0
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
68 def __iter__(self):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
69 return self
41501
0c5019afc55b PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents: 40644
diff changeset
70 def __next__(self):
34802
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
71 3 // 0
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
72
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
73 class IterFuncStop:
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
74 'Test immediate stop'
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
75 def __init__(self, seqn):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
76 pass
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
77 def __iter__(self):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
78 return self
41501
0c5019afc55b PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents: 40644
diff changeset
79 def __next__(self):
34802
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
80 raise StopIteration
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
81
45738
740b5808c57a Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents: 45735
diff changeset
82 from itertools import chain
34802
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
83 def itermulti(seqn):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
84 'Test multiple tiers of iterators'
45735
7adaab64eb72 Issues 2186 and 2187. Move map() from itertools to builtins.
Raymond Hettinger <python@rcn.com>
parents: 45471
diff changeset
85 return chain(map(lambda x:x, iterfunc(IterGen(Sequence(seqn)))))
34802
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
86
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
87 class CommonTest(unittest.TestCase):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
88 # The type to be tested
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
89 type2test = None
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
90
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
91 def test_constructors(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
92 l0 = []
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
93 l1 = [0]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
94 l2 = [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
95
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
96 u = 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
97 u0 = 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
98 u1 = self.type2test(l1)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
99 u2 = 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
100
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
101 uu = self.type2test(u)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
102 uu0 = self.type2test(u0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
103 uu1 = self.type2test(u1)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
104 uu2 = self.type2test(u2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
105
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
106 v = self.type2test(tuple(u))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
107 class OtherSeq:
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
108 def __init__(self, initseq):
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.__data = initseq
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
110 def __len__(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
111 return len(self.__data)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
112 def __getitem__(self, i):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
113 return self.__data[i]
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
114 s = OtherSeq(u0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
115 v0 = self.type2test(s)
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(len(v0), len(s))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
117
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
118 s = "this is also a sequence"
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
119 vv = self.type2test(s)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
120 self.assertEqual(len(vv), len(s))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
121
34802
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
122 # Create from various iteratables
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41501
diff changeset
123 for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
34802
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
124 for g in (Sequence, IterFunc, IterGen,
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
125 itermulti, iterfunc):
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
126 self.assertEqual(self.type2test(g(s)), self.type2test(s))
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
127 self.assertEqual(self.type2test(IterFuncStop(s)), self.type2test())
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
128 self.assertEqual(self.type2test(c for c in "123"), self.type2test("123"))
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
129 self.assertRaises(TypeError, self.type2test, IterNextOnly(s))
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
130 self.assertRaises(TypeError, self.type2test, IterNoNext(s))
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
131 self.assertRaises(ZeroDivisionError, self.type2test, IterGenExc(s))
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
132
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
133 def test_truth(self):
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 48850
diff changeset
134 self.assertFalse(self.type2test())
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 48850
diff changeset
135 self.assertTrue(self.type2test([42]))
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
136
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
137 def test_getitem(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
138 u = self.type2test([0, 1, 2, 3, 4])
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41501
diff changeset
139 for i in range(len(u)):
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
140 self.assertEqual(u[i], i)
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
141 self.assertEqual(u[int(i)], i)
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41501
diff changeset
142 for i in range(-len(u), -1):
31159
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.assertEqual(u[i], len(u)+i)
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
144 self.assertEqual(u[int(i)], len(u)+i)
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
145 self.assertRaises(IndexError, u.__getitem__, -len(u)-1)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
146 self.assertRaises(IndexError, u.__getitem__, len(u))
33629
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
147 self.assertRaises(ValueError, u.__getitem__, slice(0,10,0))
31159
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 u = 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
150 self.assertRaises(IndexError, u.__getitem__, 0)
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.assertRaises(IndexError, u.__getitem__, -1)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
152
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
153 self.assertRaises(TypeError, u.__getitem__)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
154
33629
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
155 a = self.type2test([10, 11])
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
156 self.assertEqual(a[0], 10)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
157 self.assertEqual(a[1], 11)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
158 self.assertEqual(a[-2], 10)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
159 self.assertEqual(a[-1], 11)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
160 self.assertRaises(IndexError, a.__getitem__, -3)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
161 self.assertRaises(IndexError, a.__getitem__, 3)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
162
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
163 def test_getslice(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
164 l = [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
165 u = 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
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 self.assertEqual(u[0:0], 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
168 self.assertEqual(u[1:2], 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
169 self.assertEqual(u[-2:-1], self.type2test([3]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
170 self.assertEqual(u[-1000:1000], u)
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(u[1000:-1000], 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
172 self.assertEqual(u[:], u)
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(u[1:None], self.type2test([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
174 self.assertEqual(u[None:3], 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
175
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
176 # Extended slices
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
177 self.assertEqual(u[::], u)
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(u[::2], 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
179 self.assertEqual(u[1::2], 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
180 self.assertEqual(u[::-1], self.type2test([4, 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
181 self.assertEqual(u[::-2], self.type2test([4, 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
182 self.assertEqual(u[3::-2], self.type2test([3, 1]))
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(u[3:3:-2], 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 self.assertEqual(u[3:2:-2], self.type2test([3]))
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(u[3:1:-2], self.type2test([3]))
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
186 self.assertEqual(u[3:0:-2], self.type2test([3, 1]))
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.assertEqual(u[::-100], self.type2test([4]))
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.assertEqual(u[100:-100:], 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
189 self.assertEqual(u[-100:100:], u)
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.assertEqual(u[100:-100:-1], u[::-1])
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
191 self.assertEqual(u[-100:100:-1], self.type2test([]))
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
192 self.assertEqual(u[-100:100:2], self.type2test([0, 2, 4]))
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
193
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
194 # Test extreme cases with long ints
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
195 a = self.type2test([0,1,2,3,4])
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
196 self.assertEqual(a[ -pow(2,128): 3 ], self.type2test([0,1,2]))
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
197 self.assertEqual(a[ 3: pow(2,145) ], self.type2test([3,4]))
31159
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 def test_contains(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
200 u = 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
201 for i in u:
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 48850
diff changeset
202 self.assertIn(i, u)
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
203 for i in min(u)-1, max(u)+1:
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 48850
diff changeset
204 self.assertNotIn(i, u)
31159
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 self.assertRaises(TypeError, u.__contains__)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
207
35420
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
208 def test_contains_fake(self):
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
209 class AllEq:
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
210 # Sequences must use rich comparison against each item
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
211 # (unless "is" is true, or an earlier item answered)
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
212 # So instances of AllEq must be found in all non-empty sequences.
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
213 def __eq__(self, other):
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
214 return True
48475
f4e7ef4329a9 Manual forward port of 64962 - use PyObject_HashNotImplemented as a tp_hash level indicator that the default hash implementation has not been inherited
Nick Coghlan <ncoghlan@gmail.com>
parents: 45738
diff changeset
215 __hash__ = None # Can't meet hash invariant requirements
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 48850
diff changeset
216 self.assertNotIn(AllEq(), self.type2test([]))
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 48850
diff changeset
217 self.assertIn(AllEq(), self.type2test([1]))
35420
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
218
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
219 def test_contains_order(self):
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
220 # Sequences must test in-order. If a rich comparison has side
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
221 # effects, these will be visible to tests against later members.
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
222 # In this test, the "side effect" is a short-circuiting raise.
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
223 class DoNotTestEq(Exception):
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
224 pass
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
225 class StopCompares:
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
226 def __eq__(self, other):
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
227 raise DoNotTestEq
35465
3e5c07faab11 Whitespace normalization (via reindent.py).
Tim Peters <tim.peters@gmail.com>
parents: 35420
diff changeset
228
35420
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
229 checkfirst = self.type2test([1, StopCompares()])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 48850
diff changeset
230 self.assertIn(1, checkfirst)
35420
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
231 checklast = self.type2test([StopCompares(), 1])
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
232 self.assertRaises(DoNotTestEq, checklast.__contains__, 1)
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
233
31159
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_len(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 self.assertEqual(len(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
236 self.assertEqual(len(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
237 self.assertEqual(len(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
238 self.assertEqual(len(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
239
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
240 def test_minmax(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
241 u = 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
242 self.assertEqual(min(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
243 self.assertEqual(max(u), 2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
244
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
245 def test_addmul(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
246 u1 = 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
247 u2 = 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
248 self.assertEqual(u1, u1 + 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(u1, self.type2test() + u1)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
250 self.assertEqual(u1 + self.type2test([1]), u2)
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(self.type2test([-1]) + u1, 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
252 self.assertEqual(self.type2test(), u2*0)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
253 self.assertEqual(self.type2test(), 0*u2)
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
254 self.assertEqual(self.type2test(), u2*0)
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
255 self.assertEqual(self.type2test(), 0*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
256 self.assertEqual(u2, u2*1)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
257 self.assertEqual(u2, 1*u2)
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
258 self.assertEqual(u2, u2*1)
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
259 self.assertEqual(u2, 1*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
260 self.assertEqual(u2+u2, u2*2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
261 self.assertEqual(u2+u2, 2*u2)
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
262 self.assertEqual(u2+u2, u2*2)
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
263 self.assertEqual(u2+u2, 2*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
264 self.assertEqual(u2+u2+u2, u2*3)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
265 self.assertEqual(u2+u2+u2, 3*u2)
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
266
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
267 class subclass(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
268 pass
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
269 u3 = subclass([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
270 self.assertEqual(u3, u3*1)
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 48850
diff changeset
271 self.assertIsNot(u3, u3*1)
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
272
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
273 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
274 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
275 u += 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
276 self.assertEqual(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
277 u += self.type2test([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
278 self.assertEqual(u, 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
279 u += self.type2test([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
280 self.assertEqual(u, self.type2test([0, 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
281
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
282 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
283 u += self.type2test("eggs")
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(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
285
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
286 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
287 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
288 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
289 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
290
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
291 def test_getitemoverwriteiter(self):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
292 # Verify that __getitem__ overrides are not recognized by __iter__
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
293 class T(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
294 def __getitem__(self, key):
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
295 return str(key) + '!!!'
41501
0c5019afc55b PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents: 40644
diff changeset
296 self.assertEqual(next(iter(T((1,2)))), 1)
33629
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
297
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
298 def test_repeat(self):
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41501
diff changeset
299 for m in range(4):
33629
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
300 s = tuple(range(m))
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41501
diff changeset
301 for n in range(-3, 5):
33629
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
302 self.assertEqual(self.type2test(s*n), self.type2test(s)*n)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
303 self.assertEqual(self.type2test(s)*(-4), self.type2test([]))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
304 self.assertEqual(id(s), id(s*1))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
305
43877
1165d261fb05 Merged revisions 58947-59004 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 43100
diff changeset
306 def test_bigrepeat(self):
48850
afb9808b0f30 Closes release blocker #3627.
Neal Norwitz <nnorwitz@gmail.com>
parents: 48475
diff changeset
307 import sys
afb9808b0f30 Closes release blocker #3627.
Neal Norwitz <nnorwitz@gmail.com>
parents: 48475
diff changeset
308 if sys.maxsize <= 2147483647:
afb9808b0f30 Closes release blocker #3627.
Neal Norwitz <nnorwitz@gmail.com>
parents: 48475
diff changeset
309 x = self.type2test([0])
afb9808b0f30 Closes release blocker #3627.
Neal Norwitz <nnorwitz@gmail.com>
parents: 48475
diff changeset
310 x *= 2**16
afb9808b0f30 Closes release blocker #3627.
Neal Norwitz <nnorwitz@gmail.com>
parents: 48475
diff changeset
311 self.assertRaises(MemoryError, x.__mul__, 2**16)
afb9808b0f30 Closes release blocker #3627.
Neal Norwitz <nnorwitz@gmail.com>
parents: 48475
diff changeset
312 if hasattr(x, '__imul__'):
afb9808b0f30 Closes release blocker #3627.
Neal Norwitz <nnorwitz@gmail.com>
parents: 48475
diff changeset
313 self.assertRaises(MemoryError, x.__imul__, 2**16)
43877
1165d261fb05 Merged revisions 58947-59004 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 43100
diff changeset
314
33629
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
315 def test_subscript(self):
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
316 a = self.type2test([10, 11])
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
317 self.assertEqual(a.__getitem__(0), 10)
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
318 self.assertEqual(a.__getitem__(1), 11)
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
319 self.assertEqual(a.__getitem__(-2), 10)
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
320 self.assertEqual(a.__getitem__(-1), 11)
33629
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
321 self.assertRaises(IndexError, a.__getitem__, -3)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
322 self.assertRaises(IndexError, a.__getitem__, 3)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
323 self.assertEqual(a.__getitem__(slice(0,1)), self.type2test([10]))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
324 self.assertEqual(a.__getitem__(slice(1,2)), self.type2test([11]))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
325 self.assertEqual(a.__getitem__(slice(0,2)), self.type2test([10, 11]))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
326 self.assertEqual(a.__getitem__(slice(0,3)), self.type2test([10, 11]))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
327 self.assertEqual(a.__getitem__(slice(3,5)), self.type2test([]))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
328 self.assertRaises(ValueError, a.__getitem__, slice(0, 10, 0))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
329 self.assertRaises(TypeError, a.__getitem__, 'x')
45206
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
330
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
331 def test_count(self):
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
332 a = self.type2test([0, 1, 2])*3
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
333 self.assertEqual(a.count(0), 3)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
334 self.assertEqual(a.count(1), 3)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
335 self.assertEqual(a.count(3), 0)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
336
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
337 self.assertRaises(TypeError, a.count)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
338
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
339 class BadExc(Exception):
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
340 pass
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
341
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
342 class BadCmp:
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
343 def __eq__(self, other):
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
344 if other == 2:
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
345 raise BadExc()
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
346 return False
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
347
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
348 self.assertRaises(BadExc, a.count, BadCmp())
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
349
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
350 def test_index(self):
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
351 u = self.type2test([0, 1])
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
352 self.assertEqual(u.index(0), 0)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
353 self.assertEqual(u.index(1), 1)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
354 self.assertRaises(ValueError, u.index, 2)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
355
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
356 u = self.type2test([-2, -1, 0, 0, 1, 2])
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
357 self.assertEqual(u.count(0), 2)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
358 self.assertEqual(u.index(0), 2)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
359 self.assertEqual(u.index(0, 2), 2)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
360 self.assertEqual(u.index(-2, -10), 0)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
361 self.assertEqual(u.index(0, 3), 3)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
362 self.assertEqual(u.index(0, 3, 4), 3)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
363 self.assertRaises(ValueError, u.index, 2, 0, -10)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
364
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
365 self.assertRaises(TypeError, u.index)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
366
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
367 class BadExc(Exception):
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
368 pass
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
369
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
370 class BadCmp:
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
371 def __eq__(self, other):
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
372 if other == 2:
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
373 raise BadExc()
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
374 return False
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
375
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
376 a = self.type2test([0, 1, 2, 3])
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
377 self.assertRaises(BadExc, a.index, BadCmp())
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
378
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
379 a = self.type2test([-2, -1, 0, 0, 1, 2])
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
380 self.assertEqual(a.index(0), 2)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
381 self.assertEqual(a.index(0, 2), 2)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
382 self.assertEqual(a.index(0, -4), 2)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
383 self.assertEqual(a.index(-2, -10), 0)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
384 self.assertEqual(a.index(0, 3), 3)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
385 self.assertEqual(a.index(0, -3), 3)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
386 self.assertEqual(a.index(0, 3, 4), 3)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
387 self.assertEqual(a.index(0, -3, -2), 3)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
388 self.assertEqual(a.index(0, -4*sys.maxsize, 4*sys.maxsize), 2)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
389 self.assertRaises(ValueError, a.index, 0, 4*sys.maxsize,-4*sys.maxsize)
063d022ac011 Issue 2025: Add index() and count() methods to tuple so that it will follow
Raymond Hettinger <python@rcn.com>
parents: 43877
diff changeset
390 self.assertRaises(ValueError, a.index, 2, 0, -10)