summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2007-08-27 19:07:22 (GMT)
committerEric Smith <eric@trueblade.com>2007-08-27 19:07:22 (GMT)
commit739e2ad64bc2a5a345723a23ca01fa6b54ba1c9f (patch)
tree29a38db5bd5595c72aaa46193f792de4cead845f
parent9c62772d5e0e096458c6f5c8e50cc84fcc1383f7 (diff)
downloadcpython-739e2ad64bc2a5a345723a23ca01fa6b54ba1c9f.zip
cpython-739e2ad64bc2a5a345723a23ca01fa6b54ba1c9f.tar.gz
cpython-739e2ad64bc2a5a345723a23ca01fa6b54ba1c9f.tar.bz2
Additional test for formatting code.
-rw-r--r--Lib/test/test_builtin.py3
-rw-r--r--Lib/test/test_unicode.py12
2 files changed, 11 insertions, 4 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 0560045..2d3e1cc 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -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
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 662acd3..47d7236 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -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')