diff options
author | Raymond Hettinger <python@rcn.com> | 2005-09-16 07:14:21 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2005-09-16 07:14:21 +0000 |
commit | d55516293059693746d0652a5258641320db85de (patch) | |
tree | 1c94171ba420f4c5ef698b0554a365ef1ea5e310 /Lib/test/test_set.py | |
parent | 2c9591307d68e764ffa1083a801135a9b828e0f6 (diff) | |
download | cpython-d55516293059693746d0652a5258641320db85de.tar.gz |
No longer ignore exceptions raised by comparisons during key lookup.
Inspired by Armin Rigo's suggestion to do the same with dictionaries.
Diffstat (limited to 'Lib/test/test_set.py')
-rw-r--r-- | Lib/test/test_set.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index 2ebeff65e3..77df31b622 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -15,6 +15,12 @@ def check_pass_thru(): raise PassThru yield 1 +class BadCmp: + def __hash__(self): + return 1 + def __cmp__(self, other): + raise RuntimeError + class TestJointOps(unittest.TestCase): # Tests common to both set and frozenset @@ -227,6 +233,17 @@ class TestJointOps(unittest.TestCase): f.add(s) f.discard(s) + def test_badcmp(self): + s = self.thetype([BadCmp()]) + # Detect comparison errors during insertion and lookup + self.assertRaises(RuntimeError, self.thetype, [BadCmp(), BadCmp()]) + self.assertRaises(RuntimeError, s.__contains__, BadCmp()) + # Detect errors during mutating operations + if hasattr(s, 'add'): + self.assertRaises(RuntimeError, s.add, BadCmp()) + self.assertRaises(RuntimeError, s.discard, BadCmp()) + self.assertRaises(RuntimeError, s.remove, BadCmp()) + class TestSet(TestJointOps): thetype = set |