bpo-28850: Fix PrettyPrinter.format overrides ignored for contents of small containers (GH-22120)
diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py
index 8ee18e8..c4a8578 100644
--- a/Lib/test/test_pprint.py
+++ b/Lib/test/test_pprint.py
@@ -453,12 +453,23 @@ class AdvancedNamespace(types.SimpleNamespace): pass
dog=8)""")
def test_subclassing(self):
+ # length(repr(obj)) > width
o = {'names with spaces': 'should be presented using repr()',
'others.should.not.be': 'like.this'}
exp = """\
{'names with spaces': 'should be presented using repr()',
others.should.not.be: like.this}"""
- self.assertEqual(DottedPrettyPrinter().pformat(o), exp)
+
+ dotted_printer = DottedPrettyPrinter()
+ self.assertEqual(dotted_printer.pformat(o), exp)
+
+ # length(repr(obj)) < width
+ o1 = ['with space']
+ exp1 = "['with space']"
+ self.assertEqual(dotted_printer.pformat(o1), exp1)
+ o2 = ['without.space']
+ exp2 = "[without.space]"
+ self.assertEqual(dotted_printer.pformat(o2), exp2)
def test_set_reprs(self):
self.assertEqual(pprint.pformat(set()), 'set()')