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')
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