summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_string.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_string.py')
-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 c2bdfdb..3e65071 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'-")