Commit 0b368ad3 authored by Stefan Behnel's avatar Stefan Behnel

Clean up some file open/close usages in the test runner.

parent 036637f1
...@@ -948,7 +948,9 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -948,7 +948,9 @@ class CythonCompileTestCase(unittest.TestCase):
if self.preparse and self.preparse != 'id': if self.preparse and self.preparse != 'id':
preparse_func = globals()[self.preparse] preparse_func = globals()[self.preparse]
def copy(src, dest): def copy(src, dest):
open(dest, 'w').write(preparse_func(open(src).read())) with open(src) as fin:
with open(dest, 'w') as fout:
fout.write(preparse_func(fin.read()))
else: else:
# use symlink on Unix, copy on Windows # use symlink on Unix, copy on Windows
try: try:
...@@ -969,22 +971,22 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -969,22 +971,22 @@ class CythonCompileTestCase(unittest.TestCase):
def split_source_and_output(self, test_directory, module, workdir): def split_source_and_output(self, test_directory, module, workdir):
source_file = self.find_module_source_file(os.path.join(test_directory, module) + '.pyx') source_file = self.find_module_source_file(os.path.join(test_directory, module) + '.pyx')
source_and_output = io_open(source_file, 'r', encoding='ISO-8859-1') with io_open(source_file, 'r', encoding='ISO-8859-1') as source_and_output:
error_writer = warnings_writer = None error_writer = warnings_writer = None
try:
out = io_open(os.path.join(workdir, module + os.path.splitext(source_file)[1]), out = io_open(os.path.join(workdir, module + os.path.splitext(source_file)[1]),
'w', encoding='ISO-8859-1') 'w', encoding='ISO-8859-1')
for line in source_and_output: try:
if line.startswith("_ERRORS"): for line in source_and_output:
out.close() if line.startswith("_ERRORS"):
out = error_writer = ErrorWriter() out.close()
elif line.startswith("_WARNINGS"): out = error_writer = ErrorWriter()
out.close() elif line.startswith("_WARNINGS"):
out = warnings_writer = ErrorWriter() out.close()
else: out = warnings_writer = ErrorWriter()
out.write(line) else:
finally: out.write(line)
source_and_output.close() finally:
out.close()
return (error_writer.geterrors() if error_writer else [], return (error_writer.geterrors() if error_writer else [],
warnings_writer.geterrors() if warnings_writer else []) warnings_writer.geterrors() if warnings_writer else [])
......
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