summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_string.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2011-03-14 22:54:37 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2011-03-14 22:54:37 (GMT)
commitd25fd4d7102cfa98dadd6bfeb5753ce419c3fb3b (patch)
tree91e5ad090a239c79ea62e02c914d65c488231f63 /Lib/test/test_string.py
parent750beda5353e3433df3978b6e9e3d57b6253e066 (diff)
downloadcpython-d25fd4d7102cfa98dadd6bfeb5753ce419c3fb3b.zip
cpython-d25fd4d7102cfa98dadd6bfeb5753ce419c3fb3b.tar.gz
cpython-d25fd4d7102cfa98dadd6bfeb5753ce419c3fb3b.tar.bz2
Close #11505: Improve string.py coverage
Diffstat (limited to 'Lib/test/test_string.py')
-rw-r--r--Lib/test/test_string.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py
index b495d69..c4b186a 100644
--- a/Lib/test/test_string.py
+++ b/Lib/test/test_string.py
@@ -112,6 +112,30 @@ class ModuleTest(unittest.TestCase):
self.assertRaises(ValueError, fmt.format, "{0}", 10, 20, i=100)
self.assertRaises(ValueError, fmt.format, "{i}", 10, 20, i=100)
+ def test_vformat_assert(self):
+ cls = string.Formatter()
+ kwargs = {
+ "i": 100
+ }
+ self.assertRaises(ValueError, cls._vformat,
+ cls.format, "{0}", kwargs, set(), -2)
+
+ def test_convert_field(self):
+ cls = string.Formatter()
+ self.assertEqual(cls.format("{0!s}", 'foo'), 'foo')
+ self.assertRaises(ValueError, cls.format, "{0!h}", 'foo')
+
+ def test_get_field(self):
+ cls = string.Formatter()
+ class MyClass:
+ name = 'lumberjack'
+ x = MyClass()
+ self.assertEqual(cls.format("{0.name}", x), 'lumberjack')
+
+ lookup = ["eggs", "and", "spam"]
+ self.assertEqual(cls.format("{0[2]}", lookup), 'spam')
+
+
def test_main():
support.run_unittest(ModuleTest)