|
6 | 6 | import sys
|
7 | 7 | import pickle
|
8 | 8 | from test import support
|
| 9 | +from test.support import ALWAYS_EQ, NEVER_EQ |
9 | 10 |
|
10 | 11 | # Various iterables
|
11 | 12 | # This is used for checking the constructor (here and in test_deque.py)
|
@@ -221,15 +222,15 @@ def test_contains(self):
|
221 | 222 | self.assertRaises(TypeError, u.__contains__)
|
222 | 223 |
|
223 | 224 | def test_contains_fake(self):
|
224 |
| - class AllEq: |
225 |
| - # Sequences must use rich comparison against each item |
226 |
| - # (unless "is" is true, or an earlier item answered) |
227 |
| - # So instances of AllEq must be found in all non-empty sequences. |
228 |
| - def __eq__(self, other): |
229 |
| - return True |
230 |
| - __hash__ = None # Can't meet hash invariant requirements |
231 |
| - self.assertNotIn(AllEq(), self.type2test([])) |
232 |
| - self.assertIn(AllEq(), self.type2test([1])) |
| 225 | + # Sequences must use rich comparison against each item |
| 226 | + # (unless "is" is true, or an earlier item answered) |
| 227 | + # So ALWAYS_EQ must be found in all non-empty sequences. |
| 228 | + self.assertNotIn(ALWAYS_EQ, self.type2test([])) |
| 229 | + self.assertIn(ALWAYS_EQ, self.type2test([1])) |
| 230 | + self.assertIn(1, self.type2test([ALWAYS_EQ])) |
| 231 | + self.assertNotIn(NEVER_EQ, self.type2test([])) |
| 232 | + self.assertNotIn(ALWAYS_EQ, self.type2test([NEVER_EQ])) |
| 233 | + self.assertIn(NEVER_EQ, self.type2test([ALWAYS_EQ])) |
233 | 234 |
|
234 | 235 | def test_contains_order(self):
|
235 | 236 | # Sequences must test in-order. If a rich comparison has side
|
@@ -350,6 +351,11 @@ def test_count(self):
|
350 | 351 | self.assertEqual(a.count(1), 3)
|
351 | 352 | self.assertEqual(a.count(3), 0)
|
352 | 353 |
|
| 354 | + self.assertEqual(a.count(ALWAYS_EQ), 9) |
| 355 | + self.assertEqual(self.type2test([ALWAYS_EQ, ALWAYS_EQ]).count(1), 2) |
| 356 | + self.assertEqual(self.type2test([ALWAYS_EQ, ALWAYS_EQ]).count(NEVER_EQ), 2) |
| 357 | + self.assertEqual(self.type2test([NEVER_EQ, NEVER_EQ]).count(ALWAYS_EQ), 0) |
| 358 | + |
353 | 359 | self.assertRaises(TypeError, a.count)
|
354 | 360 |
|
355 | 361 | class BadExc(Exception):
|
@@ -378,6 +384,11 @@ def test_index(self):
|
378 | 384 | self.assertEqual(u.index(0, 3, 4), 3)
|
379 | 385 | self.assertRaises(ValueError, u.index, 2, 0, -10)
|
380 | 386 |
|
| 387 | + self.assertEqual(u.index(ALWAYS_EQ), 0) |
| 388 | + self.assertEqual(self.type2test([ALWAYS_EQ, ALWAYS_EQ]).index(1), 0) |
| 389 | + self.assertEqual(self.type2test([ALWAYS_EQ, ALWAYS_EQ]).index(NEVER_EQ), 0) |
| 390 | + self.assertRaises(ValueError, self.type2test([NEVER_EQ, NEVER_EQ]).index, ALWAYS_EQ) |
| 391 | + |
381 | 392 | self.assertRaises(TypeError, u.index)
|
382 | 393 |
|
383 | 394 | class BadExc(Exception):
|
|
0 commit comments