summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorEzio Melotti <devnull@localhost>2011-04-26 05:12:51 +0300
committerEzio Melotti <devnull@localhost>2011-04-26 05:12:51 +0300
commit0c6c6472c4a3471c2e8071cfe7ae17f384df3917 (patch)
treedcee9ea0307d510b7cbf69a2d5dfdeac50986346 /Lib
parent765002461568316e8fcc5c428030d407a3c0b9e8 (diff)
downloadcpython-0c6c6472c4a3471c2e8071cfe7ae17f384df3917.tar.gz
#6780: fix starts/endswith error message to mention that tuples are accepted too.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_str.py13
-rw-r--r--Lib/test/test_unicode.py11
2 files changed, 23 insertions, 1 deletions
diff --git a/Lib/test/test_str.py b/Lib/test/test_str.py
index 4f88b28848..2ecf3276b4 100644
--- a/Lib/test/test_str.py
+++ b/Lib/test/test_str.py
@@ -414,7 +414,18 @@ class StrTest(
self.assertEqual('Andr\202 x'.decode('ascii', 'replace'),
'Andr\202 x'.decode(encoding='ascii', errors='replace'))
-
+ def test_startswith_endswith_errors(self):
+ with self.assertRaises(UnicodeDecodeError):
+ '\xff'.startswith(u'x')
+ with self.assertRaises(UnicodeDecodeError):
+ '\xff'.endswith(u'x')
+ for meth in ('foo'.startswith, 'foo'.endswith):
+ with self.assertRaises(TypeError) as cm:
+ meth(['f'])
+ exc = str(cm.exception)
+ self.assertIn('unicode', exc)
+ self.assertIn('str', exc)
+ self.assertIn('tuple', exc)
def test_main():
test_support.run_unittest(StrTest)
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index ae4c355f48..bd43dbc57b 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -442,6 +442,17 @@ class UnicodeTest(
return u'\u1234'
self.assertEqual('%s' % Wrapper(), u'\u1234')
+ def test_startswith_endswith_errors(self):
+ for meth in (u'foo'.startswith, u'foo'.endswith):
+ with self.assertRaises(UnicodeDecodeError):
+ meth('\xff')
+ with self.assertRaises(TypeError) as cm:
+ meth(['f'])
+ exc = str(cm.exception)
+ self.assertIn('unicode', exc)
+ self.assertIn('str', exc)
+ self.assertIn('tuple', exc)
+
@test_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