From: Ezio Melotti Date: Tue, 26 Apr 2011 03:40:59 +0000 (+0300) Subject: #6780: merge with 3.1. X-Git-Tag: v3.2.1b1~76 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f2b3f780a160347b0759b8d0f8ea9c41a456f724;p=python #6780: merge with 3.1. --- f2b3f780a160347b0759b8d0f8ea9c41a456f724 diff --cc Lib/test/test_bytes.py index d074758c66,a1e08cc735..5eab8f5561 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@@ -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') @@@ -312,6 -307,14 +317,11 @@@ 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') diff --cc Lib/test/test_unicode.py index 65b26c55b2,772ea35d3f..97be58793f --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@@ -819,6 -789,17 +819,14 @@@ class UnicodeTest(string_tests.CommonTe self.assertEqual('%f' % INF, 'inf') self.assertEqual('%F' % INF, 'INF') + def test_startswith_endswith_errors(self): + for meth in ('foo'.startswith, 'foo'.endswith): - try: ++ with self.assertRaises(TypeError) as cm: + meth(['f']) - except TypeError as err: - exc = str(err) - else: - self.fail('starts/endswith unexpectedly succeeded') ++ 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