[Python-checkins] python/dist/src/Lib/test test_pprint.py, 1.11, 1.12

doerwalter at users.sourceforge.net doerwalter at users.sourceforge.net
Wed Dec 3 15:15:31 EST 2003


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv12889/Lib/test

Modified Files:
	test_pprint.py 
Log Message:
Patch #750542: pprint now will pretty print subclasses of list, tuple
and dict too, as long as they don't overwrite __repr__().


Index: test_pprint.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_pprint.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** test_pprint.py	31 Dec 2002 07:16:16 -0000	1.11
--- test_pprint.py	3 Dec 2003 20:15:28 -0000	1.12
***************
*** 9,12 ****
--- 9,28 ----
          return x
  
+ # list, tuple and dict subclasses that do or don't overwrite __repr__
+ class list2(list):
+     pass
+ class list3(list):
+     def __repr__(self):
+         return list.__repr__(self)
+ class tuple2(tuple):
+     pass
+ class tuple3(tuple):
+     def __repr__(self):
+         return tuple.__repr__(self)
+ class dict2(dict):
+     pass
+ class dict3(dict):
+     def __repr__(self):
+         return dict.__repr__(self)
  
  class QueryTestCase(unittest.TestCase):
***************
*** 85,93 ****
  
      def test_same_as_repr(self):
!         # Simple objects and small containers that should be same as repr()
          verify = self.assert_
!         for simple in (0, 0L, 0+0j, 0.0, "", uni(""), (), [], {}, verify, pprint,
                         -6, -6L, -6-6j, -1.5, "x", uni("x"), (3,), [3], {3: 6},
                         (1,2), [3,4], {5: 6, 7: 8},
                         {"xy\tab\n": (3,), 5: [[]], (): {}},
                         range(10, -11, -1)
--- 101,118 ----
  
      def test_same_as_repr(self):
!         # Simple objects, small containers and classes that overwrite __repr__
!         # For those the result should be the same as repr()
          verify = self.assert_
!         for simple in (0, 0L, 0+0j, 0.0, "", uni(""),
!                        (), tuple2(), tuple3(),
!                        [], list2(), list3(),
!                        {}, dict2(), dict3(),
!                        verify, pprint,
                         -6, -6L, -6-6j, -1.5, "x", uni("x"), (3,), [3], {3: 6},
                         (1,2), [3,4], {5: 6, 7: 8},
+                        tuple2((1,2)), tuple3((1,2)), tuple3(range(100)),
+                        [3,4], list2([3,4]), list3([3,4]), list3(range(100)),
+                        {5: 6, 7: 8}, dict2({5: 6, 7: 8}), dict3({5: 6, 7: 8}),
+                        dict3([(x,x) for x in range(100)]),
                         {"xy\tab\n": (3,), 5: [[]], (): {}},
                         range(10, -11, -1)
***************
*** 100,104 ****
                                        (native, got, function))
  
- 
      def test_basic_line_wrap(self):
          # verify basic line-wrapping operation
--- 125,128 ----
***************
*** 118,122 ****
   'read_io_runtime_us': 0,
   'write_io_runtime_us': 43690}"""
!         self.assertEqual(pprint.pformat(o), exp)
  
      def test_subclassing(self):
--- 142,157 ----
   'read_io_runtime_us': 0,
   'write_io_runtime_us': 43690}"""
!         for type in [dict, dict2]:
!             self.assertEqual(pprint.pformat(type(o)), exp)
! 
!         o = range(100)
!         exp = '[%s]' % ',\n '.join(map(str, o))
!         for type in [list, list2]:
!             self.assertEqual(pprint.pformat(type(o)), exp)
! 
!         o = tuple(range(100))
!         exp = '(%s)' % ',\n '.join(map(str, o))
!         for type in [tuple, tuple2]:
!             self.assertEqual(pprint.pformat(type(o)), exp)
  
      def test_subclassing(self):





More information about the Python-checkins mailing list