[Python-checkins] cpython (merge default -> default): merge default

michael.foord python-checkins at python.org
Tue Mar 15 00:02:35 CET 2011


http://hg.python.org/cpython/rev/2a584412d541
changeset:   68480:2a584412d541
parent:      68479:b0b7d1d2354c
parent:      68478:91a9bca3150b
user:        Michael Foord <michael at python.org>
date:        Mon Mar 14 19:03:30 2011 -0400
summary:
  merge default

files:
  Misc/ACKS
  Misc/NEWS

diff --git a/Lib/test/test_pep292.py b/Lib/test/test_pep292.py
--- a/Lib/test/test_pep292.py
+++ b/Lib/test/test_pep292.py
@@ -42,6 +42,19 @@
         s = Template('$who likes $$')
         eq(s.substitute(dict(who='tim', what='ham')), 'tim likes $')
 
+    def test_invalid(self):
+        class MyPattern(Template):
+            pattern = r"""
+            (?:
+            (?P<invalid>)            |
+            (?P<escaped>%(delim)s)   |
+            @(?P<named>%(id)s)       |
+            @{(?P<braced>%(id)s)}
+            )
+            """
+        s = MyPattern('$')
+        self.assertRaises(ValueError, s.substitute, dict())
+
     def test_percents(self):
         eq = self.assertEqual
         s = Template('%(foo)s $foo ${foo}')
diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py
--- a/Lib/test/test_string.py
+++ b/Lib/test/test_string.py
@@ -112,6 +112,30 @@
         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)
 
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -32,6 +32,7 @@
 Ross Andrus
 Jon Anglin
 Éric Araujo
+Alicia Arlen
 Jason Asbahr
 David Ascher
 Chris AtLee
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -203,6 +203,8 @@
 Tests
 -----
 
+- Issue #11505: improves test coverage of string.py
+
 - Issue #11490: test_subprocess:test_leaking_fds_on_error no longer gives a
   false positive if the last directory in the path is inaccessible.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list