Commit 5932f48a authored by Stefan Behnel's avatar Stefan Behnel

fix more dangling open files in tests

parent 5215b5b2
...@@ -173,15 +173,23 @@ def unpack_source_tree(tree_file, dir=None): ...@@ -173,15 +173,23 @@ def unpack_source_tree(tree_file, dir=None):
dir = tempfile.mkdtemp() dir = tempfile.mkdtemp()
header = [] header = []
cur_file = None cur_file = None
for line in open(tree_file).readlines(): f = open(tree_file)
lines = f.readlines()
f.close()
f = None
for line in lines:
if line[:5] == '#####': if line[:5] == '#####':
filename = line.strip().strip('#').strip().replace('/', os.path.sep) filename = line.strip().strip('#').strip().replace('/', os.path.sep)
path = os.path.join(dir, filename) path = os.path.join(dir, filename)
if not os.path.exists(os.path.dirname(path)): if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path)) os.makedirs(os.path.dirname(path))
if cur_file is not None:
cur_file.close()
cur_file = open(path, 'w') cur_file = open(path, 'w')
elif cur_file is not None: elif cur_file is not None:
cur_file.write(line) cur_file.write(line)
else: else:
header.append(line) header.append(line)
if cur_file is not None:
cur_file.close()
return dir, ''.join(header) return dir, ''.join(header)
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