Commit 2cab50b9 authored by Brett Cannon's avatar Brett Cannon

Make test_import a little bit more robust for cleaning up after itself in the

face of a failure.
parent e401c684
...@@ -147,22 +147,24 @@ class ImportTests(unittest.TestCase): ...@@ -147,22 +147,24 @@ class ImportTests(unittest.TestCase):
filename = module + '.py' filename = module + '.py'
# Create a file with a list of 65000 elements. # Create a file with a list of 65000 elements.
with open(filename, 'w+') as f: with open(filename, 'w') as f:
f.write('d = [\n') f.write('d = [\n')
for i in range(65000): for i in range(65000):
f.write('"",\n') f.write('"",\n')
f.write(']') f.write(']')
try:
# Compile & remove .py file; we only need .pyc (or .pyo). # Compile & remove .py file; we only need .pyc (or .pyo).
# Bytecode must be relocated from the PEP 3147 bytecode-only location. # Bytecode must be relocated from the PEP 3147 bytecode-only location.
py_compile.compile(filename) py_compile.compile(filename)
finally:
unlink(filename) unlink(filename)
make_legacy_pyc(filename)
# Need to be able to load from current dir. # Need to be able to load from current dir.
sys.path.append('') sys.path.append('')
try: try:
make_legacy_pyc(filename)
# This used to crash. # This used to crash.
exec('import ' + module) exec('import ' + module)
finally: finally:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment