summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorEric V. Smith <eric@trueblade.com>2014-04-14 16:43:50 -0400
committerEric V. Smith <eric@trueblade.com>2014-04-14 16:43:50 -0400
commit7ce90743a1948680f409bcc02f56f4f100df1a04 (patch)
tree859eab4c0f9138f16a01a7279105ffac1864cfbd /Lib/test
parentefeb9da4ae97861101a7582f8eafdaf836e82cd7 (diff)
downloadcpython-git-7ce90743a1948680f409bcc02f56f4f100df1a04.tar.gz
Issue #13598: Add auto-numbering of replacement fields to string.Formatter.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_string.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py
index c2bdfdb0b0..3e6507151e 100644
--- a/Lib/test/test_string.py
+++ b/Lib/test/test_string.py
@@ -32,6 +32,23 @@ class ModuleTest(unittest.TestCase):
self.assertEqual(fmt.format("foo{0}", "bar"), "foobar")
self.assertEqual(fmt.format("foo{1}{0}-{1}", "bar", 6), "foo6bar-6")
+ def test_auto_numbering(self):
+ fmt = string.Formatter()
+ self.assertEqual(fmt.format('foo{}{}', 'bar', 6),
+ 'foo{}{}'.format('bar', 6))
+ self.assertEqual(fmt.format('foo{1}{num}{1}', None, 'bar', num=6),
+ 'foo{1}{num}{1}'.format(None, 'bar', num=6))
+ self.assertEqual(fmt.format('{:^{}}', 'bar', 6),
+ '{:^{}}'.format('bar', 6))
+ self.assertEqual(fmt.format('{:^{pad}}{}', 'foo', 'bar', pad=6),
+ '{:^{pad}}{}'.format('foo', 'bar', pad=6))
+
+ with self.assertRaises(ValueError):
+ fmt.format('foo{1}{}', 'bar', 6)
+
+ with self.assertRaises(ValueError):
+ fmt.format('foo{}{1}', 'bar', 6)
+
def test_conversion_specifiers(self):
fmt = string.Formatter()
self.assertEqual(fmt.format("-{arg!r}-", arg='test'), "-'test'-")