summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pprint.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-03-24 17:31:50 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-03-24 17:31:50 (GMT)
commit87eb482e30ec76976e7c04b1547faaab0df40261 (patch)
tree14fe5585683be0734d33da68ea2f40f52686edca /Lib/test/test_pprint.py
parent022f20376a2458e0ecbd38e393957452570cd3a4 (diff)
downloadcpython-87eb482e30ec76976e7c04b1547faaab0df40261.zip
cpython-87eb482e30ec76976e7c04b1547faaab0df40261.tar.gz
cpython-87eb482e30ec76976e7c04b1547faaab0df40261.tar.bz2
Issue #23502: The pprint module now supports mapping proxies.
In particular the __dict__ attributes of building types.
Diffstat (limited to 'Lib/test/test_pprint.py')
-rw-r--r--Lib/test/test_pprint.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py
index 50d7d59..3a798d9 100644
--- a/Lib/test/test_pprint.py
+++ b/Lib/test/test_pprint.py
@@ -7,6 +7,7 @@ import test.test_set
import random
import collections
import itertools
+import types
# list, tuple and dict subclasses that do or don't overwrite __repr__
class list2(list):
@@ -271,6 +272,34 @@ class QueryTestCase(unittest.TestCase):
'a': 6,
'lazy': 7,
'dog': 8}""")
+
+ def test_mapping_proxy(self):
+ words = 'the quick brown fox jumped over a lazy dog'.split()
+ d = dict(zip(words, itertools.count()))
+ m = types.MappingProxyType(d)
+ self.assertEqual(pprint.pformat(m), """\
+mappingproxy({'a': 6,
+ 'brown': 2,
+ 'dog': 8,
+ 'fox': 3,
+ 'jumped': 4,
+ 'lazy': 7,
+ 'over': 5,
+ 'quick': 1,
+ 'the': 0})""")
+ d = collections.OrderedDict(zip(words, itertools.count()))
+ m = types.MappingProxyType(d)
+ self.assertEqual(pprint.pformat(m), """\
+mappingproxy({'the': 0,
+ 'quick': 1,
+ 'brown': 2,
+ 'fox': 3,
+ 'jumped': 4,
+ 'over': 5,
+ 'a': 6,
+ 'lazy': 7,
+ 'dog': 8})""")
+
def test_subclassing(self):
o = {'names with spaces': 'should be presented using repr()',
'others.should.not.be': 'like.this'}