Kaydet (Commit) 739e2ad6 authored tarafından Eric Smith's avatar Eric Smith

Additional test for formatting code.

üst 9c62772d
......@@ -541,7 +541,8 @@ class BuiltinTest(unittest.TestCase):
self.assertEqual(format(-3.1415e-104, ""), str(-3.1415e-104))
self.assertEqual(format(object, ""), str(object))
#self.assertRaises(TypeError, format, H(), "")
# TypeError because self.__format__ returns the wrong type
self.assertRaises(TypeError, format, H(), "")
def test_getattr(self):
import sys
......
......@@ -424,6 +424,10 @@ class UnicodeTest(
def __format__(self, format_spec):
return 1.0
class I(datetime.date):
def __format__(self, format_spec):
return self.strftime(format_spec)
self.assertEqual(''.format(), '')
self.assertEqual('abc'.format(), 'abc')
......@@ -504,9 +508,6 @@ class UnicodeTest(
self.assertEqual('{0!r:}'.format('Hello'), "'Hello'")
self.assertEqual('{0!r}'.format(F('Hello')), 'F(Hello)')
# XXX should pass, but currently don't
# format(object, "")
# test fallback to object.__format__
self.assertEqual('{0}'.format({}), '{}')
self.assertEqual('{0}'.format([]), '[]')
......@@ -518,6 +519,11 @@ class UnicodeTest(
self.assertEqual('{0:>15s}'.format(G('data')), ' string is data')
self.assertEqual('{0!s}'.format(G('data')), 'string is data')
self.assertEqual("{0:date: %Y-%m-%d}".format(I(year=2007,
month=8,
day=27)),
"date: 2007-08-27")
# string format specifiers
self.assertEqual('{0:}'.format('a'), 'a')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment