bpo-30670: Add pp function to the pprint module (GH-11769)

This commit is contained in:
Rémi Lapeyre 2019-03-22 18:22:20 +01:00 committed by Raymond Hettinger
parent c5c6cdada3
commit 96831c7fcf
5 changed files with 84 additions and 35 deletions

View file

@ -81,6 +81,7 @@ class QueryTestCase(unittest.TestCase):
pp = pprint.PrettyPrinter(indent=4, width=40, depth=5,
stream=io.StringIO(), compact=True)
pp = pprint.PrettyPrinter(4, 40, 5, io.StringIO())
pp = pprint.PrettyPrinter(sort_dicts=False)
with self.assertRaises(TypeError):
pp = pprint.PrettyPrinter(4, 40, 5, io.StringIO(), True)
self.assertRaises(ValueError, pprint.PrettyPrinter, indent=-1)
@ -293,6 +294,12 @@ class QueryTestCase(unittest.TestCase):
self.assertEqual(pprint.pformat({"xy\tab\n": (3,), 5: [[]], (): {}}),
r"{5: [[]], 'xy\tab\n': (3,), (): {}}")
def test_sort_dict(self):
d = dict.fromkeys('cba')
self.assertEqual(pprint.pformat(d, sort_dicts=False), "{'c': None, 'b': None, 'a': None}")
self.assertEqual(pprint.pformat([d, d], sort_dicts=False),
"[{'c': None, 'b': None, 'a': None}, {'c': None, 'b': None, 'a': None}]")
def test_ordered_dict(self):
d = collections.OrderedDict()
self.assertEqual(pprint.pformat(d, width=1), 'OrderedDict()')