##// END OF EJS Templates
Merge pull request #11164 from minrk/os-environ-pretty...
Thomas Kluyver -
r24373:2284ccfe merge
parent child Browse files
Show More
@@ -77,11 +77,13 b' Inheritance diagram:'
77 77 Portions (c) 2009 by Robert Kern.
78 78 :license: BSD License.
79 79 """
80
80 81 from contextlib import contextmanager
82 import datetime
83 import os
84 import re
81 85 import sys
82 86 import types
83 import re
84 import datetime
85 87 from collections import deque
86 88 from io import StringIO
87 89 from warnings import warn
@@ -742,7 +744,6 b' _type_pprinters = {'
742 744 tuple: _seq_pprinter_factory('(', ')'),
743 745 list: _seq_pprinter_factory('[', ']'),
744 746 dict: _dict_pprinter_factory('{', '}'),
745
746 747 set: _set_pprinter_factory('{', '}'),
747 748 frozenset: _set_pprinter_factory('frozenset({', '})'),
748 749 super: _super_pprint,
@@ -751,12 +752,17 b' _type_pprinters = {'
751 752 types.FunctionType: _function_pprint,
752 753 types.BuiltinFunctionType: _function_pprint,
753 754 types.MethodType: _repr_pprint,
754
755 755 datetime.datetime: _repr_pprint,
756 756 datetime.timedelta: _repr_pprint,
757 757 _exception_base: _exception_pprint
758 758 }
759 759
760 # render os.environ like a dict
761 _env_type = type(os.environ)
762 # future-proof in case os.environ becomes a plain dict?
763 if _env_type is not dict:
764 _type_pprinters[_env_type] = _dict_pprinter_factory('environ{', '}')
765
760 766 try:
761 767 # In PyPy, types.DictProxyType is dict, setting the dictproxy printer
762 768 # using dict.setdefault avoids overwritting the dict printer
@@ -768,7 +774,7 b' except AttributeError: # Python 3'
768 774 _type_pprinters[types.MappingProxyType] = \
769 775 _dict_pprinter_factory('mappingproxy({', '})')
770 776 _type_pprinters[slice] = _repr_pprint
771
777
772 778 try:
773 779 _type_pprinters[long] = _repr_pprint
774 780 _type_pprinters[unicode] = _repr_pprint
@@ -6,6 +6,7 b''
6 6
7 7
8 8 from collections import Counter, defaultdict, deque, OrderedDict
9 import os
9 10 import types
10 11 import string
11 12 import unittest
@@ -406,6 +407,15 b' def test_mappingproxy():'
406 407 for obj, expected in cases:
407 408 nt.assert_equal(pretty.pretty(obj), expected)
408 409
410
411 def test_pretty_environ():
412 dict_repr = pretty.pretty(dict(os.environ))
413 # reindent to align with 'environ' prefix
414 dict_indented = dict_repr.replace('\n', '\n' + (' ' * len('environ')))
415 env_repr = pretty.pretty(os.environ)
416 nt.assert_equals(env_repr, 'environ' + dict_indented)
417
418
409 419 def test_function_pretty():
410 420 "Test pretty print of function"
411 421 # posixpath is a pure python module, its interface is consistent
General Comments 0
You need to be logged in to leave comments. Login now