]> granicus.if.org Git - python/commitdiff
__format(): Applied SF patch #482003 by Skip to fix multiline dict
authorBarry Warsaw <barry@python.org>
Wed, 28 Nov 2001 05:49:39 +0000 (05:49 +0000)
committerBarry Warsaw <barry@python.org>
Wed, 28 Nov 2001 05:49:39 +0000 (05:49 +0000)
output.

Patch includes additional test case test_basic_line_wrap().

This patch is a candidate for Python 2.1.2.

Lib/pprint.py
Lib/test/test_pprint.py

index b16fb08020731ddbbc54d3d871ae632ba8a0c7b9..5d178a2a55d66e6fa07ad5ba9fefd460fc332d38 100644 (file)
@@ -158,7 +158,7 @@ class PrettyPrinter:
                     if length > 1:
                         for key, ent in items[1:]:
                             rep = self.__repr(key, context, level)
-                            write(',\n%s: %s' % (' '*indent, rep))
+                            write(',\n%s%s: ' % (' '*indent, rep))
                             self.__format(ent, stream, indent + _len(rep) + 2,
                                           allowance + 1, context, level)
                     indent = indent - self.__indent_per_level
index 167b4ac24760a364a83c670a80e740891650a38a..14626fb13fff5e53af70fcaf46b0ee0a6681eeae 100644 (file)
@@ -77,6 +77,25 @@ class QueryTestCase(unittest.TestCase):
                                       (native, got, function))
 
 
+    def test_basic_line_wrap(self):
+        """verify basic line-wrapping operation"""
+        o = {'RPM_cal': 0,
+             'RPM_cal2': 48059,
+             'Speed_cal': 0,
+             'controldesk_runtime_us': 0,
+             'main_code_runtime_us': 0,
+             'read_io_runtime_us': 0,
+             'write_io_runtime_us': 43690}
+        exp = """\
+{'RPM_cal': 0,
+ 'RPM_cal2': 48059,
+ 'Speed_cal': 0,
+ 'controldesk_runtime_us': 0,
+ 'main_code_runtime_us': 0,
+ 'read_io_runtime_us': 0,
+ 'write_io_runtime_us': 43690}"""
+        self.assertEqual(pprint.pformat(o), exp)
+
 def test_main():
     test_support.run_unittest(QueryTestCase)