[Python-checkins] python/dist/src/Lib/test test_descr.py,1.176,1.177

nnorwitz@users.sourceforge.net nnorwitz@users.sourceforge.net
Mon, 13 Jan 2003 12:13:46 -0800


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

Modified Files:
	test_descr.py 
Log Message:
Fix SF bug #667147, Segmentation fault printing str subclass

Fix infinite recursion which occurred when printing an object
whose __str__() returned self.

Will backport


Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.176
retrieving revision 1.177
diff -C2 -d -r1.176 -r1.177
*** test_descr.py	7 Jan 2003 13:41:37 -0000	1.176
--- test_descr.py	13 Jan 2003 20:13:09 -0000	1.177
***************
*** 1,5 ****
  # Test enhancements related to descriptors and new-style classes
  
! from test.test_support import verify, vereq, verbose, TestFailed, TESTFN
  from copy import deepcopy
  import warnings
--- 1,5 ----
  # Test enhancements related to descriptors and new-style classes
  
! from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_original_stdout
  from copy import deepcopy
  import warnings
***************
*** 1821,1824 ****
--- 1821,1847 ----
      unsafecmp(1, 1L)
      unsafecmp(1L, 1)
+ 
+     class Letter(str):
+         def __new__(cls, letter):
+             if letter == 'EPS':
+                 return str.__new__(cls)
+             return str.__new__(cls, letter)
+         def __str__(self):
+             if not self:
+                 return 'EPS'
+             return self 
+ 
+     # sys.stdout needs to be the original to trigger the recursion bug
+     import sys
+     test_stdout = sys.stdout
+     sys.stdout = get_original_stdout()
+     try:
+         # nothing should actually be printed, this should raise an exception
+         print Letter('w')
+     except RuntimeError:
+         pass
+     else:
+         raise TestFailed, "expected a RuntimeError for print recursion"
+     sys.stdout = test_stdout
  
  def weakrefs():