summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_string.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-08-19 21:26:34 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-08-19 21:26:34 (GMT)
commite56bf97ef4283a877c459390516bb7385e8e4ec4 (patch)
treed175af7fff6eeacc8c58a7bdad0a0f546063b292 /Lib/test/test_string.py
parent828607170da3986af909defe99f956e5762e4dd0 (diff)
downloadcpython-e56bf97ef4283a877c459390516bb7385e8e4ec4.zip
cpython-e56bf97ef4283a877c459390516bb7385e8e4ec4.tar.gz
cpython-e56bf97ef4283a877c459390516bb7385e8e4ec4.tar.bz2
#13579: teach string.Formatter about 'a'.
Patch by Francisco Martín Brugué.
Diffstat (limited to 'Lib/test/test_string.py')
-rw-r--r--Lib/test/test_string.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py
index a352ee3..34d1dcf 100644
--- a/Lib/test/test_string.py
+++ b/Lib/test/test_string.py
@@ -26,6 +26,18 @@ class ModuleTest(unittest.TestCase):
self.assertEqual(string.capwords('\taBc\tDeF\t'), 'Abc Def')
self.assertEqual(string.capwords('\taBc\tDeF\t', '\t'), '\tAbc\tDef\t')
+ def test_conversion_specifiers(self):
+ fmt = string.Formatter()
+ self.assertEqual(fmt.format("-{arg!r}-", arg='test'), "-'test'-")
+ self.assertEqual(fmt.format("{0!s}", 'test'), 'test')
+ self.assertRaises(ValueError, fmt.format, "{0!h}", 'test')
+ # issue13579
+ self.assertEqual(fmt.format("{0!a}", 42), '42')
+ self.assertEqual(fmt.format("{0!a}", string.ascii_letters),
+ "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'")
+ self.assertEqual(fmt.format("{0!a}", chr(255)), "'\\xff'")
+ self.assertEqual(fmt.format("{0!a}", chr(256)), "'\\u0100'")
+
def test_formatter(self):
fmt = string.Formatter()
self.assertEqual(fmt.format("foo"), "foo")