[Python-checkins] r78116 - in python/trunk: Doc/library/unittest.rst Lib/test/test_unittest.py Lib/unittest/case.py

michael.foord python-checkins at python.org
Mon Feb 8 23:41:16 CET 2010


Author: michael.foord
Date: Mon Feb  8 23:41:16 2010
New Revision: 78116

Log:
Make assertMultiLineEqual the default for comparing unicode strings.

Modified:
   python/trunk/Doc/library/unittest.rst
   python/trunk/Lib/test/test_unittest.py
   python/trunk/Lib/unittest/case.py

Modified: python/trunk/Doc/library/unittest.rst
==============================================================================
--- python/trunk/Doc/library/unittest.rst	(original)
+++ python/trunk/Doc/library/unittest.rst	Mon Feb  8 23:41:16 2010
@@ -695,7 +695,7 @@
       *second*.
 
       In addition, if *first* and *second* are the exact same type and one of
-      list, tuple, dict, set, or frozenset or any type that a subclass
+      list, tuple, dict, set, frozenset or unicode or any type that a subclass
       registers :meth:`addTypeEqualityFunc` the type specific equality function
       will be called in order to generate a more useful default error message.
 
@@ -777,7 +777,8 @@
 
       Test that the multiline string *first* is equal to the string *second*.
       When not equal a diff of the two strings highlighting the differences
-      will be included in the error message.
+      will be included in the error message. This method is used by default
+      when comparing Unicode strings with :meth:`assertEqual`.
 
       If specified *msg* will be used as the error message on failure.
 
@@ -823,7 +824,8 @@
    .. method:: assertSetEqual(set1, set2, msg=None)
 
       Tests that two sets are equal.  If not, an error message is constructed
-      that lists the differences between the sets.
+      that lists the differences between the sets.  This method is used by
+      default when comparing sets or frozensets with :meth:`assertEqual`.
 
       Fails if either of *set1* or *set2* does not have a :meth:`set.difference`
       method.
@@ -836,7 +838,9 @@
    .. method:: assertDictEqual(expected, actual, msg=None)
 
       Test that two dictionaries are equal.  If not, an error message is
-      constructed that shows the differences in the dictionaries.
+      constructed that shows the differences in the dictionaries. This
+      method will be used by default to compare dictionaries in
+      calls to :meth:`assertEqual`.
 
       If specified *msg* will be used as the error message on failure.
 
@@ -860,6 +864,8 @@
       Tests that two lists or tuples are equal.  If not an error message is
       constructed that shows only the differences between the two.  An error
       is also raised if either of the parameters are of the wrong type.
+      These methods are used by default when comparing lists or tuples with
+      :meth:`assertEqual`.
 
       If specified *msg* will be used as the error message on failure.
 

Modified: python/trunk/Lib/test/test_unittest.py
==============================================================================
--- python/trunk/Lib/test/test_unittest.py	(original)
+++ python/trunk/Lib/test/test_unittest.py	Mon Feb  8 23:41:16 2010
@@ -2810,8 +2810,9 @@
                 self.assertMultiLineEqual(type_changer(sample_text),
                                           type_changer(revised_sample_text))
             except self.failureException, e:
-                # no fair testing ourself with ourself, use assertEqual..
-                self.assertEqual(sample_text_error, str(e).encode('utf8'))
+                # assertMultiLineEqual is hooked up as the default for
+                # unicode strings - so we can't use it for this check
+                self.assertTrue(sample_text_error == str(e).encode('utf8'))
 
     def testAssertIsNone(self):
         self.assertIsNone(None)

Modified: python/trunk/Lib/unittest/case.py
==============================================================================
--- python/trunk/Lib/unittest/case.py	(original)
+++ python/trunk/Lib/unittest/case.py	Mon Feb  8 23:41:16 2010
@@ -176,6 +176,7 @@
         self.addTypeEqualityFunc(tuple, self.assertTupleEqual)
         self.addTypeEqualityFunc(set, self.assertSetEqual)
         self.addTypeEqualityFunc(frozenset, self.assertSetEqual)
+        self.addTypeEqualityFunc(unicode, self.assertMultiLineEqual)
 
     def addTypeEqualityFunc(self, typeobj, function):
         """Add a type specific assertEqual style function to compare a type.


More information about the Python-checkins mailing list