Lines Matching refs:self
7 def __index__(self): argument
8 return self.ind
11 def __index__(self): argument
12 return int(self)
15 def setUp(self): argument
16 self.o = newstyle()
17 self.n = newstyle()
19 def test_basic(self): argument
20 self.o.ind = -2
21 self.n.ind = 2
22 self.assertEqual(operator.index(self.o), -2)
23 self.assertEqual(operator.index(self.n), 2)
25 def test_slice(self): argument
26 self.o.ind = 1
27 self.n.ind = 2
28 slc = slice(self.o, self.o, self.o)
30 self.assertEqual(slc.indices(self.o), check_slc.indices(1))
31 slc = slice(self.n, self.n, self.n)
33 self.assertEqual(slc.indices(self.n), check_slc.indices(2))
35 def test_wrappers(self): argument
36 self.o.ind = 4
37 self.n.ind = 5
38 self.assertEqual(6 .__index__(), 6)
39 self.assertEqual(-7 .__index__(), -7)
40 self.assertEqual(self.o.__index__(), 4)
41 self.assertEqual(self.n.__index__(), 5)
42 self.assertEqual(True.__index__(), 1)
43 self.assertEqual(False.__index__(), 0)
45 def test_subclasses(self): argument
47 self.assertEqual(r[TrapInt(5):TrapInt(10)], r[5:10])
48 self.assertEqual(slice(TrapInt()).indices(0), (0,0,1))
50 def test_error(self): argument
51 self.o.ind = 'dumb'
52 self.n.ind = 'bad'
53 self.assertRaises(TypeError, operator.index, self.o)
54 self.assertRaises(TypeError, operator.index, self.n)
55 self.assertRaises(TypeError, slice(self.o).indices, 0)
56 self.assertRaises(TypeError, slice(self.n).indices, 0)
58 def test_int_subclass_with_index(self): argument
62 def __index__(self): argument
63 return int(str(self)) + 1
68 self.assertEqual(direct_index, 8)
69 self.assertEqual(operator_index, 7)
71 self.assertIs(type(direct_index), int)
74 def test_index_returns_int_subclass(self): argument
76 def __index__(self): argument
80 def __index__(self): argument
84 with self.assertWarns(DeprecationWarning):
86 self.assertEqual(n, 1)
90 self.assertEqual(n, 0)
96 def setUp(self): argument
97 self.o = newstyle()
98 self.n = newstyle()
99 self.o2 = newstyle()
100 self.n2 = newstyle()
102 def test_index(self): argument
103 self.o.ind = -2
104 self.n.ind = 2
105 self.assertEqual(self.seq[self.n], self.seq[2])
106 self.assertEqual(self.seq[self.o], self.seq[-2])
108 def test_slice(self): argument
109 self.o.ind = 1
110 self.o2.ind = 3
111 self.n.ind = 2
112 self.n2.ind = 4
113 self.assertEqual(self.seq[self.o:self.o2], self.seq[1:3])
114 self.assertEqual(self.seq[self.n:self.n2], self.seq[2:4])
116 def test_slice_bug7532(self): argument
117 seqlen = len(self.seq)
118 self.o.ind = int(seqlen * 1.5)
119 self.n.ind = seqlen + 2
120 self.assertEqual(self.seq[self.o:], self.seq[0:0])
121 self.assertEqual(self.seq[:self.o], self.seq)
122 self.assertEqual(self.seq[self.n:], self.seq[0:0])
123 self.assertEqual(self.seq[:self.n], self.seq)
124 self.o2.ind = -seqlen - 2
125 self.n2.ind = -int(seqlen * 1.5)
126 self.assertEqual(self.seq[self.o2:], self.seq)
127 self.assertEqual(self.seq[:self.o2], self.seq[0:0])
128 self.assertEqual(self.seq[self.n2:], self.seq)
129 self.assertEqual(self.seq[:self.n2], self.seq[0:0])
131 def test_repeat(self): argument
132 self.o.ind = 3
133 self.n.ind = 2
134 self.assertEqual(self.seq * self.o, self.seq * 3)
135 self.assertEqual(self.seq * self.n, self.seq * 2)
136 self.assertEqual(self.o * self.seq, self.seq * 3)
137 self.assertEqual(self.n * self.seq, self.seq * 2)
139 def test_wrappers(self): argument
140 self.o.ind = 4
141 self.n.ind = 5
142 self.assertEqual(self.seq.__getitem__(self.o), self.seq[4])
143 self.assertEqual(self.seq.__mul__(self.o), self.seq * 4)
144 self.assertEqual(self.seq.__rmul__(self.o), self.seq * 4)
145 self.assertEqual(self.seq.__getitem__(self.n), self.seq[5])
146 self.assertEqual(self.seq.__mul__(self.n), self.seq * 5)
147 self.assertEqual(self.seq.__rmul__(self.n), self.seq * 5)
149 def test_subclasses(self): argument
150 self.assertEqual(self.seq[TrapInt()], self.seq[0])
152 def test_error(self): argument
153 self.o.ind = 'dumb'
154 self.n.ind = 'bad'
156 self.assertRaises(TypeError, indexobj, self.o, self)
157 self.assertRaises(TypeError, indexobj, self.n, self)
159 self.assertRaises(TypeError, sliceobj, self.o, self)
160 self.assertRaises(TypeError, sliceobj, self.n, self)
166 def test_setdelitem(self): argument
167 self.o.ind = -2
168 self.n.ind = 2
170 del lst[self.o]
171 del lst[self.n]
172 lst[self.o] = 'X'
173 lst[self.n] = 'Y'
174 self.assertEqual(lst, list('abYdefghXj'))
177 lst.__setitem__(self.n, "here")
178 self.assertEqual(lst, [5, 6, "here", 8, 9, 10, 11])
179 lst.__delitem__(self.n)
180 self.assertEqual(lst, [5, 6, 8, 9, 10, 11])
182 def test_inplace_repeat(self): argument
183 self.o.ind = 2
184 self.n.ind = 3
186 lst *= self.o
187 self.assertEqual(lst, [6, 4, 6, 4])
188 lst *= self.n
189 self.assertEqual(lst, [6, 4, 6, 4] * 3)
192 l2 = lst.__imul__(self.n)
193 self.assertIs(l2, lst)
194 self.assertEqual(lst, [5, 6, 7, 8, 9, 11] * 3)
199 def __init__(self, iterable): argument
200 self._list = list(iterable)
202 def __repr__(self): argument
203 return repr(self._list)
205 def __eq__(self, other): argument
206 return self._list == other
208 def __len__(self): argument
209 return len(self._list)
211 def __mul__(self, n): argument
212 return self.__class__(self._list*n)
215 def __getitem__(self, index): argument
216 return self._list[index]
238 def test_range(self): argument
241 self.assertEqual(range(1, 20)[n], 6)
242 self.assertEqual(range(1, 20).__getitem__(n), 6)
247 def setUp(self): argument
248 self.pos = 2**100
249 self.neg = -self.pos
251 def test_large_longs(self): argument
252 self.assertEqual(self.pos.__index__(), self.pos)
253 self.assertEqual(self.neg.__index__(), self.neg)
255 def test_getitem(self): argument
257 def __len__(self): argument
259 def __getitem__(self, key): argument
262 self.assertEqual(x[self.pos], self.pos)
263 self.assertEqual(x[self.neg], self.neg)
264 self.assertEqual(x[self.neg:self.pos].indices(maxsize),
266 self.assertEqual(x[self.neg:self.pos:1].indices(maxsize),
269 def test_sequence_repeat(self): argument
270 self.assertRaises(OverflowError, lambda: "a" * self.pos)
271 self.assertRaises(OverflowError, lambda: "a" * self.neg)