[Python-checkins] r84773 - in python/branches/release27-maint: Lib/test/string_tests.py Lib/test/test_unicode.py Misc/NEWS

florent.xicluna python-checkins at python.org
Mon Sep 13 10:53:00 CEST 2010


Author: florent.xicluna
Date: Mon Sep 13 10:53:00 2010
New Revision: 84773

Log:
Strengthen test_unicode with explicit type checking for assertEqual tests.

Modified:
   python/branches/release27-maint/Lib/test/string_tests.py
   python/branches/release27-maint/Lib/test/test_unicode.py
   python/branches/release27-maint/Misc/NEWS

Modified: python/branches/release27-maint/Lib/test/string_tests.py
==============================================================================
--- python/branches/release27-maint/Lib/test/string_tests.py	(original)
+++ python/branches/release27-maint/Lib/test/string_tests.py	Mon Sep 13 10:53:00 2010
@@ -254,7 +254,7 @@
                 r2 = j in i
                 self.assertEqual(r1, r2)
                 if loc != -1:
-                    self.assertEqual(i[loc:loc+len(j)], j)
+                    self.assertEqual(i[loc:loc+len(j)], self.fixtype(j))
 
         # issue 7458
         self.checkequal(-1, 'ab', 'rfind', 'xxx', sys.maxsize + 1, 0)

Modified: python/branches/release27-maint/Lib/test/test_unicode.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_unicode.py	(original)
+++ python/branches/release27-maint/Lib/test/test_unicode.py	Mon Sep 13 10:53:00 2010
@@ -34,6 +34,16 @@
     ):
     type2test = unicode
 
+    def assertEqual(self, first, second, msg=None):
+        # strict assertEqual method: reject implicit bytes/unicode equality
+        super(UnicodeTest, self).assertEqual(first, second, msg)
+        if isinstance(first, unicode) or isinstance(second, unicode):
+            self.assertIsInstance(first, unicode)
+            self.assertIsInstance(second, unicode)
+        elif isinstance(first, str) or isinstance(second, str):
+            self.assertIsInstance(first, str)
+            self.assertIsInstance(second, str)
+
     def checkequalnofix(self, result, object, methodname, *args):
         method = getattr(object, methodname)
         realresult = method(*args)
@@ -197,9 +207,9 @@
 
     def test_comparison(self):
         # Comparisons:
-        self.assertEqual(u'abc', 'abc')
-        self.assertEqual('abc', u'abc')
-        self.assertEqual(u'abc', u'abc')
+        self.assertTrue(u'abc' == 'abc')
+        self.assertTrue('abc' == u'abc')
+        self.assertTrue(u'abc' == u'abc')
         self.assertTrue(u'abcd' > 'abc')
         self.assertTrue('abcd' > u'abc')
         self.assertTrue(u'abcd' > u'abc')
@@ -398,8 +408,10 @@
 
         for num in range(0x00,0x80):
             char = chr(num)
-            self.assertEqual(u"%c" % char, char)
-            self.assertEqual(u"%c" % num, char)
+            self.assertEqual(u"%c" % char, unicode(char))
+            self.assertEqual(u"%c" % num, unicode(char))
+            self.assertTrue(char == u"%c" % char)
+            self.assertTrue(char == u"%c" % num)
         # Issue 7649
         for num in range(0x80,0x100):
             uchar = unichr(num)
@@ -558,9 +570,11 @@
         set_o = '!"#$%&*;<=>@[]^_`{|}'
         for c in set_d:
             self.assertEqual(c.encode('utf7'), c.encode('ascii'))
-            self.assertEqual(c.encode('ascii').decode('utf7'), c)
+            self.assertEqual(c.encode('ascii').decode('utf7'), unicode(c))
+            self.assertTrue(c == c.encode('ascii').decode('utf7'))
         for c in set_o:
-            self.assertEqual(c.encode('ascii').decode('utf7'), c)
+            self.assertEqual(c.encode('ascii').decode('utf7'), unicode(c))
+            self.assertTrue(c == c.encode('ascii').decode('utf7'))
 
     def test_codecs_utf8(self):
         self.assertEqual(u''.encode('utf-8'), '')
@@ -1364,7 +1378,7 @@
                 return u'__unicode__ overridden'
         u = U(u'xxx')
         self.assertEqual("%s" % u, u'__unicode__ overridden')
-        self.assertEqual("{}".format(u), u'__unicode__ overridden')
+        self.assertEqual("{}".format(u), '__unicode__ overridden')
 
 
 def test_main():

Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS	(original)
+++ python/branches/release27-maint/Misc/NEWS	Mon Sep 13 10:53:00 2010
@@ -337,6 +337,8 @@
 Tests
 -----
 
+- Strengthen test_unicode with explicit type checking for assertEqual tests.
+
 - Issue #8857: Provide a test case for socket.getaddrinfo.
 
 - Issue #7564: Skip test_ioctl if another process is attached to /dev/tty.


More information about the Python-checkins mailing list