Add list tests that ensure that remove() removes the first occurrence.

(Copied from test_deque.py as suggested by Jim Jewett in SF bug #1166274)
This commit is contained in:
Walter Dörwald 2005-03-21 21:31:47 +00:00
parent 98858c9efd
commit 7355e8133d
1 changed files with 20 additions and 0 deletions

View File

@ -309,6 +309,26 @@ class CommonTest(seq_tests.CommonTest):
a = self.type2test([0, 1, 2, 3])
self.assertRaises(BadExc, a.remove, BadCmp())
class BadCmp2:
def __eq__(self, other):
raise BadExc()
d = self.type2test('abcdefghcij')
d.remove('c')
self.assertEqual(d, self.type2test('abdefghcij'))
d.remove('c')
self.assertEqual(d, self.type2test('abdefghij'))
self.assertRaises(ValueError, d.remove, 'c')
self.assertEqual(d, self.type2test('abdefghij'))
# Handle comparison errors
d = self.type2test(['a', 'b', BadCmp2(), 'c'])
e = self.type2test(d)
self.assertRaises(BadExc, d.remove, 'c')
for x, y in zip(d, e):
# verify that original order and values are retained.
self.assert_(x is y)
def test_count(self):
a = self.type2test([0, 1, 2])*3
self.assertEqual(a.count(0), 3)