]> granicus.if.org Git - python/commitdiff
#6780: merge with 3.1.
authorEzio Melotti <ezio.melotti@gmail.com>
Tue, 26 Apr 2011 03:40:59 +0000 (06:40 +0300)
committerEzio Melotti <ezio.melotti@gmail.com>
Tue, 26 Apr 2011 03:40:59 +0000 (06:40 +0300)
1  2 
Lib/test/test_bytes.py
Lib/test/test_unicode.py
Misc/NEWS
Objects/bytearrayobject.c
Objects/bytesobject.c
Objects/unicodeobject.c

index d074758c667ff65b636febb71114217c00d9b3ca,a1e08cc735eff2976a01c15ec97c525acf624c50..5eab8f5561f1b10b7d3ad84e8dc9c681fea43c32
@@@ -303,6 -290,14 +303,11 @@@ class BaseBytesTest(unittest.TestCase)
          self.assertTrue(b.startswith(b"h"))
          self.assertFalse(b.startswith(b"hellow"))
          self.assertFalse(b.startswith(b"ha"))
 -        try:
++        with self.assertRaises(TypeError) as cm:
+             b.startswith([b'h'])
 -        except TypeError as err:
 -            exc = str(err)
 -        else:
 -            self.fail('startswith unexpectedly succeeded')
++        exc = str(cm.exception)
+         self.assertIn('bytes', exc)
+         self.assertIn('tuple', exc)
  
      def test_endswith(self):
          b = self.type2test(b'hello')
          self.assertTrue(b.endswith(b"o"))
          self.assertFalse(b.endswith(b"whello"))
          self.assertFalse(b.endswith(b"no"))
 -        try:
++        with self.assertRaises(TypeError) as cm:
+             b.endswith([b'o'])
 -        except TypeError as err:
 -            exc = str(err)
 -        else:
 -            self.fail('endswith unexpectedly succeeded')
++        exc = str(cm.exception)
+         self.assertIn('bytes', exc)
+         self.assertIn('tuple', exc)
  
      def test_find(self):
          b = self.type2test(b'mississippi')
index 65b26c55b2e5d65a10a9568fb005163f86662f95,772ea35d3f295022340a5c9d7f919b101899a7c8..97be58793fee2da6506963afd604e6544f1bdf02
@@@ -819,6 -789,17 +819,14 @@@ class UnicodeTest(string_tests.CommonTe
          self.assertEqual('%f' % INF, 'inf')
          self.assertEqual('%F' % INF, 'INF')
  
 -            try:
+     def test_startswith_endswith_errors(self):
+         for meth in ('foo'.startswith, 'foo'.endswith):
 -            except TypeError as err:
 -                exc = str(err)
 -            else:
 -                self.fail('starts/endswith unexpectedly succeeded')
++            with self.assertRaises(TypeError) as cm:
+                 meth(['f'])
++            exc = str(cm.exception)
+             self.assertIn('str', exc)
+             self.assertIn('tuple', exc)
      @support.run_with_locale('LC_ALL', 'de_DE', 'fr_FR')
      def test_format_float(self):
          # should not format with a comma, but always with C locale
diff --cc Misc/NEWS
Simple merge
Simple merge
Simple merge
Simple merge