summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-09-16 07:14:21 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-09-16 07:14:21 (GMT)
commit9bda1d6f645bd0f3e76c14f27bbbac919814cd38 (patch)
tree78b758d20259b08938187e0ad078134376feaf04 /Lib/test
parentc404ff2f2d711fdb0f9adf096b4ffa01891fd3d4 (diff)
downloadcpython-9bda1d6f645bd0f3e76c14f27bbbac919814cd38.zip
cpython-9bda1d6f645bd0f3e76c14f27bbbac919814cd38.tar.gz
cpython-9bda1d6f645bd0f3e76c14f27bbbac919814cd38.tar.bz2
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')
-rw-r--r--Lib/test/test_set.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index 2ebeff6..77df31b 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