test runner: close files immediately after use
authorStefan Behnel <scoder@users.berlios.de>
Fri, 12 Nov 2010 10:59:58 +0000 (11:59 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 12 Nov 2010 10:59:58 +0000 (11:59 +0100)
runtests.py

index b8eec3ada54b749226f2e58a4939e82308909e60..e91a412d526e97aa3f88f8ecfe1dd23df385169c 100644 (file)
@@ -316,18 +316,22 @@ class CythonCompileTestCase(unittest.TestCase):
         source_file = os.path.join(test_directory, module) + '.pyx'
         source_and_output = codecs.open(
             self.find_module_source_file(source_file), 'rU', 'ISO-8859-1')
-        out = codecs.open(os.path.join(workdir, module + '.pyx'),
-                          'w', 'ISO-8859-1')
-        for line in source_and_output:
-            last_line = line
-            if line.startswith("_ERRORS"):
-                out.close()
-                out = ErrorWriter()
-            else:
-                out.write(line)
+        try:
+            out = codecs.open(os.path.join(workdir, module + '.pyx'),
+                              'w', 'ISO-8859-1')
+            for line in source_and_output:
+                last_line = line
+                if line.startswith("_ERRORS"):
+                    out.close()
+                    out = ErrorWriter()
+                else:
+                    out.write(line)
+        finally:
+            source_and_output.close()
         try:
             geterrors = out.geterrors
         except AttributeError:
+            out.close()
             return []
         else:
             return geterrors()