fixes for I/O handling in test runner
authorStefan Behnel <scoder@users.berlios.de>
Thu, 7 Apr 2011 18:17:52 +0000 (20:17 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Thu, 7 Apr 2011 18:17:52 +0000 (20:17 +0200)
runtests.py

index cee950f3b6bf2ee0bcf6adecb068aca496009f53..4dcac43ef857794b1fffa077dcbfb704e76e6187 100644 (file)
@@ -22,6 +22,11 @@ try:
 except ImportError:
     import pickle
 
+try:
+    from io import open as io_open
+except ImportError:
+    from codecs import open as io_open
+
 try:
     import threading
 except ImportError: # No threads, no problems
@@ -130,17 +135,21 @@ def memoize(f):
 
 def parse_tags(filepath):
     tags = defaultdict(list)
-    for line in open(filepath):
-        line = line.strip()
-        if not line:
-            continue
-        if line[0] != '#':
-            break
-        ix = line.find(':')
-        if ix != -1:
-            tag = line[1:ix].strip()
-            values = line[ix+1:].split(',')
-            tags[tag].extend([value.strip() for value in values])
+    f = io_open(filepath, encoding='ISO-8859-1', errors='replace')
+    try:
+        for line in f:
+            line = line.strip()
+            if not line:
+                continue
+            if line[0] != '#':
+                break
+            ix = line.find(':')
+            if ix != -1:
+                tag = line[1:ix].strip()
+                values = line[ix+1:].split(',')
+                tags[tag].extend([value.strip() for value in values])
+    finally:
+        f.close()
     return tags
 
 parse_tags = memoize(parse_tags)
@@ -400,10 +409,10 @@ class CythonCompileTestCase(unittest.TestCase):
 
     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_and_output = codecs.open(source_file, 'rU', 'ISO-8859-1')
+        source_and_output = io_open(source_file, 'rU', encoding='ISO-8859-1')
         try:
-            out = codecs.open(os.path.join(workdir, module + os.path.splitext(source_file)[1]),
-                              'w', 'ISO-8859-1')
+            out = io_open(os.path.join(workdir, module + os.path.splitext(source_file)[1]),
+                              'w', encoding='ISO-8859-1')
             for line in source_and_output:
                 last_line = line
                 if line.startswith("_ERRORS"):