diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2011-04-26 03:09:45 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2011-04-26 03:09:45 (GMT) |
commit | ba42fd5801af664060dd90fccc4054b73967944c (patch) | |
tree | 4dc15aa0aac6a604f28de7a316701c0c4c64425f /Lib | |
parent | 2043f9c582943ec7624f8aec5dc58e59a0b9a5b0 (diff) | |
download | cpython-ba42fd5801af664060dd90fccc4054b73967944c.zip cpython-ba42fd5801af664060dd90fccc4054b73967944c.tar.gz cpython-ba42fd5801af664060dd90fccc4054b73967944c.tar.bz2 |
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_bytes.py | 16 | ||||
-rw-r--r-- | Lib/test/test_unicode.py | 11 |
2 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index a607bef..a1e08cc 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -290,6 +290,14 @@ class BaseBytesTest(unittest.TestCase): self.assertTrue(b.startswith(b"h")) self.assertFalse(b.startswith(b"hellow")) self.assertFalse(b.startswith(b"ha")) + try: + b.startswith([b'h']) + except TypeError as err: + exc = str(err) + else: + self.fail('startswith unexpectedly succeeded') + self.assertIn('bytes', exc) + self.assertIn('tuple', exc) def test_endswith(self): b = self.type2test(b'hello') @@ -299,6 +307,14 @@ class BaseBytesTest(unittest.TestCase): self.assertTrue(b.endswith(b"o")) self.assertFalse(b.endswith(b"whello")) self.assertFalse(b.endswith(b"no")) + try: + b.endswith([b'o']) + except TypeError as err: + exc = str(err) + else: + self.fail('endswith unexpectedly succeeded') + self.assertIn('bytes', exc) + self.assertIn('tuple', exc) def test_find(self): b = self.type2test(b'mississippi') diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 4793707..772ea35 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -789,6 +789,17 @@ class UnicodeTest( self.assertEqual('%f' % INF, 'inf') self.assertEqual('%F' % INF, 'INF') + def test_startswith_endswith_errors(self): + for meth in ('foo'.startswith, 'foo'.endswith): + try: + meth(['f']) + except TypeError as err: + exc = str(err) + else: + self.fail('starts/endswith unexpectedly succeeded') + 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 |