[Python-checkins] r79141 - in python/branches/py3k/Lib: test/test_unittest.py unittest/case.py

michael.foord python-checkins at python.org
Sat Mar 20 18:21:27 CET 2010


Author: michael.foord
Date: Sat Mar 20 18:21:27 2010
New Revision: 79141

Log:
Issue 7832. Deprecating assertSameElements in Py3k.

Modified:
   python/branches/py3k/Lib/test/test_unittest.py
   python/branches/py3k/Lib/unittest/case.py

Modified: python/branches/py3k/Lib/test/test_unittest.py
==============================================================================
--- python/branches/py3k/Lib/test/test_unittest.py	(original)
+++ python/branches/py3k/Lib/test/test_unittest.py	Sat Mar 20 18:21:27 2010
@@ -2758,24 +2758,6 @@
         self.assertRaises(self.failureException, self.assertDictEqual, [], d)
         self.assertRaises(self.failureException, self.assertDictEqual, 1, 1)
 
-        self.assertSameElements([1, 2, 3], [3, 2, 1])
-        self.assertSameElements([1, 2] + [3] * 100, [1] * 100 + [2, 3])
-        self.assertSameElements(['foo', 'bar', 'baz'], ['bar', 'baz', 'foo'])
-        self.assertRaises(self.failureException, self.assertSameElements,
-                          [10], [10, 11])
-        self.assertRaises(self.failureException, self.assertSameElements,
-                          [10, 11], [10])
-
-        # Test that sequences of unhashable objects can be tested for sameness:
-        self.assertSameElements([[1, 2], [3, 4]], [[3, 4], [1, 2]])
-
-        self.assertSameElements([{'a': 1}, {'b': 2}], [{'b': 2}, {'a': 1}])
-        self.assertRaises(self.failureException, self.assertSameElements,
-                          [[1]], [[2]])
-        self.assertRaises(self.failureException, self.assertSameElements,
-                          [{'a': 1}, {'b': 2}], [{'b': 2}, {'a': 2}])
-
-
     def testAssertItemsEqual(self):
         a = object()
         self.assertItemsEqual([1, 2, 3], [3, 2, 1])
@@ -3032,7 +3014,8 @@
             (self.failIfAlmostEqual, (3.0, 5.0)),
             (self.failUnless, (True,)),
             (self.failUnlessRaises, (TypeError, lambda _: 3.14 + 'spam')),
-            (self.failIf, (False,))
+            (self.failIf, (False,)),
+            (self.assertSameElements, ([1, 1, 2, 3], [1, 2, 3]))
         )
         for meth, args in old:
             with warnings.catch_warnings(record=True) as w:

Modified: python/branches/py3k/Lib/unittest/case.py
==============================================================================
--- python/branches/py3k/Lib/unittest/case.py	(original)
+++ python/branches/py3k/Lib/unittest/case.py	Sat Mar 20 18:21:27 2010
@@ -700,10 +700,9 @@
             msg: Optional message to use on failure instead of a list of
                     differences.
 
-        For more general containership equality, assertSameElements will work
-        with things other than sets.    This uses ducktyping to support
-        different types of sets, and is optimized for sets specifically
-        (parameters must support a difference method).
+        assertSetEqual uses ducktyping to support different types of sets, and
+        is optimized for sets specifically (parameters must support a
+        difference method).
         """
         try:
             difference1 = set1.difference(set2)
@@ -809,6 +808,8 @@
         set(actual))`` but it works with sequences of unhashable objects as
         well.
         """
+        warnings.warn('assertSameElements is deprecated',
+                      DeprecationWarning)
         try:
             expected = set(expected_seq)
             actual = set(actual_seq)


More information about the Python-checkins mailing list