annotate Lib/test/seq_tests.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 4ff234337e24
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
1 """
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
2 Tests common to 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
76091
4ff234337e24 Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 73408
diff changeset
7 import pickle
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
8
34802
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
9 # 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
10 # 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
11 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
12 '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
13 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
14 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
15
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
16 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
17 '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
18 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
19 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
20 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
21 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
22
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
23 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
24 '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
25 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
26 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
27 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
28 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
29 return self
41501
0c5019afc55b PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents: 40644
diff changeset
30 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
31 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
32 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
33 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
34 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
35
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
36 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
37 '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
38 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
39 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
40 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
41 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
42 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
43 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
44
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
45 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
46 '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
47 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
48 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
49 self.i = 0
41501
0c5019afc55b PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents: 40644
diff changeset
50 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
51 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
52 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
53 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
54 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
55
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
56 class IterNoNext:
41501
0c5019afc55b PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents: 40644
diff changeset
57 '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
58 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
59 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
60 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
61 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
62 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
63
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
64 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
65 '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
66 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
67 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
68 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
69 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
70 return self
41501
0c5019afc55b PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents: 40644
diff changeset
71 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
72 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
73
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
74 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
75 '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
76 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
77 pass
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
78 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
79 return self
41501
0c5019afc55b PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents: 40644
diff changeset
80 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
81 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
82
45738
740b5808c57a Move itertools izip() code to builtins as zip(). Complete the renaming.
Raymond Hettinger <python@rcn.com>
parents: 45735
diff changeset
83 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
84 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
85 '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
86 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
87
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
88 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
89 # 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
90 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
91
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
92 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
93 l0 = []
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
94 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
95 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
96
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
97 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
98 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
99 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
100 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
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 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
103 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
104 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
105 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
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 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
108 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
109 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
110 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
111 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
112 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
113 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
114 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
115 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
116 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
117 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
118
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
119 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
120 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
121 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
122
34802
718b0b5a6419 Add tests for tuple, list and UserList that initialize the object from
Walter Dörwald <walter@livinglogic.de>
parents: 33629
diff changeset
123 # Create from various iteratables
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41501
diff changeset
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132 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
133
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
134 def test_truth(self):
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 48850
diff changeset
135 self.assertFalse(self.type2test())
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 48850
diff changeset
136 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
137
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 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
147 self.assertRaises(IndexError, u.__getitem__, len(u))
33629
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
148 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
149
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
150 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
151 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
152 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
153
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.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
155
33629
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
156 a = self.type2test([10, 11])
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
157 self.assertEqual(a[0], 10)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
158 self.assertEqual(a[1], 11)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
159 self.assertEqual(a[-2], 10)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
160 self.assertEqual(a[-1], 11)
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 self.assertRaises(IndexError, a.__getitem__, 3)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
163
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
164 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
165 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
166 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
167
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[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
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
177 # 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
178 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
179 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
180 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
181 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
182 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
183 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
184 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
185 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
186 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
187 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
188 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
189 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
190 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
191 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
192 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
193 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
194
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
195 # 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
196 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
197 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
198 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
199
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
200 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
201 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
202 for i in u:
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 48850
diff changeset
203 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
204 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
205 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
206
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
207 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
208
35420
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
209 def test_contains_fake(self):
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
210 class AllEq:
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
211 # Sequences must use rich comparison against each item
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
212 # (unless "is" is true, or an earlier item answered)
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
213 # 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
214 def __eq__(self, other):
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
215 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
216 __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
217 self.assertNotIn(AllEq(), self.type2test([]))
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 48850
diff changeset
218 self.assertIn(AllEq(), self.type2test([1]))
35420
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
219
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
220 def test_contains_order(self):
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
221 # 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
222 # 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
223 # 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
224 class DoNotTestEq(Exception):
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
225 pass
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
226 class StopCompares:
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
227 def __eq__(self, other):
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
228 raise DoNotTestEq
35465
3e5c07faab11 Whitespace normalization (via reindent.py).
Tim Peters <tim.peters@gmail.com>
parents: 35420
diff changeset
229
35420
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
230 checkfirst = self.type2test([1, StopCompares()])
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 48850
diff changeset
231 self.assertIn(1, checkfirst)
35420
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
232 checklast = self.type2test([StopCompares(), 1])
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
233 self.assertRaises(DoNotTestEq, checklast.__contains__, 1)
c4e5ed7a2ba3 patch [ 1141428 ] more __contains__ tests
Georg Brandl <georg@python.org>
parents: 34802
diff changeset
234
31159
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
235 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
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)
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)
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(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
240
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
241 def test_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
242 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
243 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
244 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
245
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
246 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
247 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
248 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
249 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
250 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
251 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
252 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
253 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
254 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
255 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
256 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
257 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
258 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
259 self.assertEqual(u2, u2*1)
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 35465
diff changeset
260 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
261 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
262 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
263 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
264 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
265 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
266 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
267
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
268 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
269 pass
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
270 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
271 self.assertEqual(u3, u3*1)
66340
2beb25369289 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 48850
diff changeset
272 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
273
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
274 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
275 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
276 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
277 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
278 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
279 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
280 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
281 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
282
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("spam")
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
284 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
285 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
286
e1f1fb74451b Move list and tuple tests from test_types.py to their own scripts:
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
287 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
288 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
289 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
290 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
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_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
293 # 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
294 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
295 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
296 return str(key) + '!!!'
41501
0c5019afc55b PEP 3114: rename .next() to .__next__() and add next() builtin.
Georg Brandl <georg@python.org>
parents: 40644
diff changeset
297 self.assertEqual(next(iter(T((1,2)))), 1)
33629
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
298
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
299 def test_repeat(self):
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41501
diff changeset
300 for m in range(4):
33629
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
301 s = tuple(range(m))
41642
a6eb6acfe04a Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41501
diff changeset
302 for n in range(-3, 5):
33629
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
303 self.assertEqual(self.type2test(s*n), self.type2test(s)*n)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
304 self.assertEqual(self.type2test(s)*(-4), self.type2test([]))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
305 self.assertEqual(id(s), id(s*1))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
306
43877
1165d261fb05 Merged revisions 58947-59004 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 43100
diff changeset
307 def test_bigrepeat(self):
48850
afb9808b0f30 Closes release blocker #3627.
Neal Norwitz <nnorwitz@gmail.com>
parents: 48475
diff changeset
308 import sys
afb9808b0f30 Closes release blocker #3627.
Neal Norwitz <nnorwitz@gmail.com>
parents: 48475
diff changeset
309 if sys.maxsize <= 2147483647:
afb9808b0f30 Closes release blocker #3627.
Neal Norwitz <nnorwitz@gmail.com>
parents: 48475
diff changeset
310 x = self.type2test([0])
afb9808b0f30 Closes release blocker #3627.
Neal Norwitz <nnorwitz@gmail.com>
parents: 48475
diff changeset
311 x *= 2**16
afb9808b0f30 Closes release blocker #3627.
Neal Norwitz <nnorwitz@gmail.com>
parents: 48475
diff changeset
312 self.assertRaises(MemoryError, x.__mul__, 2**16)
afb9808b0f30 Closes release blocker #3627.
Neal Norwitz <nnorwitz@gmail.com>
parents: 48475
diff changeset
313 if hasattr(x, '__imul__'):
afb9808b0f30 Closes release blocker #3627.
Neal Norwitz <nnorwitz@gmail.com>
parents: 48475
diff changeset
314 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
315
33629
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
316 def test_subscript(self):
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
317 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
318 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
319 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
320 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
321 self.assertEqual(a.__getitem__(-1), 11)
33629
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.assertRaises(IndexError, a.__getitem__, 3)
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
324 self.assertEqual(a.__getitem__(slice(0,1)), self.type2test([10]))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
325 self.assertEqual(a.__getitem__(slice(1,2)), self.type2test([11]))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
326 self.assertEqual(a.__getitem__(slice(0,2)), self.type2test([10, 11]))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
327 self.assertEqual(a.__getitem__(slice(0,3)), self.type2test([10, 11]))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
328 self.assertEqual(a.__getitem__(slice(3,5)), self.type2test([]))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
329 self.assertRaises(ValueError, a.__getitem__, slice(0, 10, 0))
c84dbe717d49 Improve test coverage.
Raymond Hettinger <python@rcn.com>
parents: 31159
diff changeset
330 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
331
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 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
333 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
334 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
335 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
336 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
337
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 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
339
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 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
341 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
342
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 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
344 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
345 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
346 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
347 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
348
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 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
350
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 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
352 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
353 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
354 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
355 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
356
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 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
358 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
359 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
360 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
361 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
362 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
363 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
364 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
365
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 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
367
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 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
369 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
370
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 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
372 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
373 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
374 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
375 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
376
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 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
378 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
379
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 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
381 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
382 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
383 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
384 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
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), 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, 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
388 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
389 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
390 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
391 self.assertRaises(ValueError, a.index, 2, 0, -10)
76091
4ff234337e24 Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 73408
diff changeset
392
4ff234337e24 Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 73408
diff changeset
393 def test_pickle(self):
4ff234337e24 Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 73408
diff changeset
394 lst = self.type2test([4, 5, 6, 7])
4ff234337e24 Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 73408
diff changeset
395 lst2 = pickle.loads(pickle.dumps(lst))
4ff234337e24 Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 73408
diff changeset
396 self.assertEqual(lst2, lst)
4ff234337e24 Issue #14288: Serialization support for builtin iterators.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 73408
diff changeset
397 self.assertNotEqual(id(lst2), id(lst))