mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
Additional test for formatting code.
This commit is contained in:
parent
9c62772d5e
commit
739e2ad64b
2 changed files with 11 additions and 4 deletions
|
@ -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')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue