[Python-checkins] CVS: python/dist/src/Lib/test test_pprint.py,1.7,1.8

Fred L. Drake fdrake@users.sourceforge.net
2002年4月01日 21:08:38 -0800


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv16772/Lib/test
Modified Files:
	test_pprint.py 
Log Message:
Add an experimental mechanism to support extending the pprint formatting.
Partly responds to SF bug #505152.
Index: test_pprint.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_pprint.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** test_pprint.py	28 Nov 2001 05:49:39 -0000	1.7
--- test_pprint.py	2 Apr 2002 05:08:35 -0000	1.8
***************
*** 97,100 ****
--- 97,121 ----
 self.assertEqual(pprint.pformat(o), exp)
 
+ def test_subclassing(self):
+ 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)
+ 
+ 
+ class DottedPrettyPrinter(pprint.PrettyPrinter):
+ def format(self, object, context, maxlevels, level):
+ if isinstance(object, str):
+ if ' ' in object:
+ return `object`, 1, 0
+ else:
+ return object, 0, 0
+ else:
+ return pprint.PrettyPrinter.format(
+ self, object, context, maxlevels, level)
+ 
+ 
 def test_main():
 test_support.run_unittest(QueryTestCase)

AltStyle によって変換されたページ (->オリジナル) /