[Python-checkins] python/dist/src/Lib/test test_richcmp.py, 1.10, 1.11 seq_tests.py, 1.4, 1.5

birkenfeld@users.sourceforge.net birkenfeld at users.sourceforge.net
Wed Aug 24 11:09:08 CEST 2005


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11448

Modified Files:
	test_richcmp.py seq_tests.py 
Log Message:
patch [ 1141428 ] more __contains__ tests



Index: test_richcmp.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_richcmp.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- test_richcmp.py	28 Oct 2003 12:05:47 -0000	1.10
+++ test_richcmp.py	24 Aug 2005 09:08:57 -0000	1.11
@@ -259,8 +259,8 @@
 
     def test_dicts(self):
         # Verify that __eq__ and __ne__ work for dicts even if the keys and
-        # values don't support anything other than __eq__ and __ne__.  Complex
-        # numbers are a fine example of that.
+        # values don't support anything other than __eq__ and __ne__ (and
+        # __hash__).  Complex numbers are a fine example of that.
         import random
         imag1a = {}
         for i in range(50):

Index: seq_tests.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/seq_tests.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- seq_tests.py	22 Mar 2005 22:43:27 -0000	1.4
+++ seq_tests.py	24 Aug 2005 09:08:57 -0000	1.5
@@ -207,6 +207,33 @@
 
         self.assertRaises(TypeError, u.__contains__)
 
+    def test_contains_fake(self):
+        class AllEq:
+            # Sequences must use rich comparison against each item
+            # (unless "is" is true, or an earlier item answered)
+            # So instances of AllEq must be found in all non-empty sequences.
+            def __eq__(self, other):
+                return True
+            def __hash__(self):
+                raise NotImplemented
+        self.assert_(AllEq() not in self.type2test([]))
+        self.assert_(AllEq() in self.type2test([1]))
+
+    def test_contains_order(self):
+        # Sequences must test in-order.  If a rich comparison has side
+        # effects, these will be visible to tests against later members.
+        # In this test, the "side effect" is a short-circuiting raise.
+        class DoNotTestEq(Exception):
+            pass
+        class StopCompares:
+            def __eq__(self, other):
+                raise DoNotTestEq
+        
+        checkfirst = self.type2test([1, StopCompares()])
+        self.assert_(1 in checkfirst)
+        checklast = self.type2test([StopCompares(), 1])
+        self.assertRaises(DoNotTestEq, checklast.__contains__, 1)
+
     def test_len(self):
         self.assertEqual(len(self.type2test()), 0)
         self.assertEqual(len(self.type2test([])), 0)



More information about the Python-checkins mailing list