diff options
author | Michael Foord <michael@python.org> | 2011-03-14 19:03:30 -0400 |
---|---|---|
committer | Michael Foord <michael@python.org> | 2011-03-14 19:03:30 -0400 |
commit | ee354eabc996ed532bcd648e628d367468b6c00c (patch) | |
tree | d83a0f2c8a118cfe4d161294f43326c27fa3d3d6 /Lib/test/test_string.py | |
parent | 1341bb0019868345bab8adff94263c81e1d66eae (diff) | |
parent | 5596a8c179e3a336bdac46d2982fba20e7e0f4eb (diff) | |
download | cpython-git-ee354eabc996ed532bcd648e628d367468b6c00c.tar.gz |
merge default
Diffstat (limited to 'Lib/test/test_string.py')
-rw-r--r-- | Lib/test/test_string.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py index b495d69717..c4b186a273 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) |