From 7355e8133d3b03b11fd3d3b1d83e071c5fd9873e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20D=C3=B6rwald?= Date: Mon, 21 Mar 2005 21:31:47 +0000 Subject: [PATCH] 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) --- Lib/test/list_tests.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py index e616c79fb54..284edb39c39 100644 --- a/Lib/test/list_tests.py +++ b/Lib/test/list_tests.py @@ -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)