[Python-checkins] python/dist/src/Lib/test test_b2.py,1.33,1.34

tim_one@sourceforge.net tim_one@sourceforge.net
Sun, 12 May 2002 00:19:40 -0700


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

Modified Files:
	test_b2.py 
Log Message:
SF bug 555042: zip() may trigger MemoryError.
NOT a bugfix candidate:  this is a fix to an optimization introduced
in 2.3.


Index: test_b2.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_b2.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** test_b2.py	2 May 2002 18:40:31 -0000	1.33
--- test_b2.py	12 May 2002 07:19:37 -0000	1.34
***************
*** 345,350 ****
      raise TestFailed, 'zip(a, b) - missing expected TypeError'
  
  
  # Epilogue -- unlink the temp file
- 
  unlink(TESTFN)
--- 345,360 ----
      raise TestFailed, 'zip(a, b) - missing expected TypeError'
  
+ # Make sure zip doesn't try to allocate a billion elements for the
+ # result list when one of its arguments doesn't say how long it is.
+ # A MemoryError is the most likely failure mode.
+ class SequenceWithoutALength:
+     def __getitem__(self, i):
+         if i == 5:
+             raise IndexError
+         else:
+             return i
+ vereq(zip(SequenceWithoutALength(), xrange(2**30)),
+       list(enumerate(range(5))))
  
  # Epilogue -- unlink the temp file
  unlink(TESTFN)