diff options
author | Raymond Hettinger <python@rcn.com> | 2005-03-18 21:20:23 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2005-03-18 21:20:23 +0000 |
commit | 4aec61e0fc29217c93acd0615ad54bd081a64658 (patch) | |
tree | 3fb574eb0ca43704ad5e6a3f21e8f556a1a0b194 /Lib/test/test_deque.py | |
parent | 5011c3f7fcda2c6ee7cc970e61e363a4ec1f092e (diff) | |
download | cpython-git-4aec61e0fc29217c93acd0615ad54bd081a64658.tar.gz |
Add a remove() method to collections.deque objects.
Diffstat (limited to 'Lib/test/test_deque.py')
-rw-r--r-- | Lib/test/test_deque.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py index 0a6c1f97ff..f498124cef 100644 --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -14,6 +14,17 @@ def fail(): raise SyntaxError yield 1 +class BadCmp: + def __eq__(self, other): + raise RuntimeError + +class MutateCmp: + def __init__(self, deque): + self.deque = deque + def __eq__(self, other): + self.deque.clear() + return True + class TestBasic(unittest.TestCase): def test_basics(self): @@ -197,6 +208,30 @@ class TestBasic(unittest.TestCase): d.clear() # clear an emtpy deque self.assertEqual(list(d), []) + def test_remove(self): + d = deque('abcdefghcij') + d.remove('c') + self.assertEqual(d, deque('abdefghcij')) + d.remove('c') + self.assertEqual(d, deque('abdefghij')) + self.assertRaises(ValueError, d.remove, 'c') + self.assertEqual(d, deque('abdefghij')) + + # Handle comparision errors + d = deque(['a', 'b', BadCmp(), 'c']) + e = deque(d) + self.assertRaises(RuntimeError, d.remove, 'c') + for x, y in zip(d, e): + # verify that original order and values are retained. + self.assert_(x is y) + + # Handle evil mutator + d = deque(['ab']) + d.extend([MutateCmp(d), 'c']) + e = deque(d) + self.assertRaises(IndexError, d.remove, 'c') + self.assertEqual(d, deque()) + def test_repr(self): d = deque(xrange(200)) e = eval(repr(d)) |