[Python-checkins] python/dist/src/Lib/test test_set.py,1.22,1.23
rhettinger@users.sourceforge.net
rhettinger at users.sourceforge.net
Fri Sep 16 09:14:24 CEST 2005
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv303/Lib/test
Modified Files:
test_set.py
Log Message:
No longer ignore exceptions raised by comparisons during key lookup.
Inspired by Armin Rigo's suggestion to do the same with dictionaries.
Index: test_set.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_set.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- test_set.py 16 Aug 2005 10:44:15 -0000 1.22
+++ test_set.py 16 Sep 2005 07:14:21 -0000 1.23
@@ -15,6 +15,12 @@
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 @@
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
More information about the Python-checkins
mailing list