[Python-checkins] python/dist/src/Lib/test test_import.py,1.11,1.12
nnorwitz@users.sourceforge.net
nnorwitz@users.sourceforge.net
Thu, 13 Jun 2002 18:07:42 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv15627/Lib/test
Modified Files:
test_import.py
Log Message:
Fix SF bug # 561858 Assertion with very long lists
Write 4 bytes for co_stacksize, etc. to prevent writing out
bad .pyc files which can cause a crash when read back in.
Index: test_import.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_import.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** test_import.py 30 May 2002 17:10:20 -0000 1.11
--- test_import.py 14 Jun 2002 01:07:39 -0000 1.12
***************
*** 4,7 ****
--- 4,8 ----
import random
import sys
+ import py_compile
# Brief digression to test that import is case-sensitive: if we got this
***************
*** 75,76 ****
--- 76,107 ----
x = imp.find_module("os")
os = imp.load_module("os", *x)
+
+ def test_module_with_large_stack(module):
+ # create module w/list of 65000 elements to test bug #561858
+ filename = module + '.py'
+
+ # create a file with a list of 65000 elements
+ f = open(filename, 'w+')
+ f.write('d = [\n')
+ for i in range(65000):
+ f.write('"",\n')
+ f.write(']')
+ f.close()
+
+ # compile & remove .py file, we only need .pyc
+ f = open(filename, 'r')
+ py_compile.compile(filename)
+ os.unlink(filename)
+
+ # need to be able to load from current dir
+ sys.path.append('')
+
+ # this used to crash
+ exec 'import ' + module
+
+ # cleanup
+ del sys.path[-1]
+ os.unlink(module + '.pyc')
+
+ test_module_with_large_stack('longlist')
+