run-tests: use difflib.diff_bytes on Python 3
authorAugie Fackler <augie@google.com>
Tue, 21 Apr 2015 12:24:34 -0400
changeset 25045 8a425c2eef5d
parent 25044 9de94acfde8a
child 25046 40b4308d5653
run-tests: use difflib.diff_bytes on Python 3 This method was introduced in Python 3.5 to satisfy our diffing-strings-of-bytes needs.
tests/run-tests.py
--- a/tests/run-tests.py	Sun Apr 12 16:14:07 2015 -0400
+++ b/tests/run-tests.py	Tue Apr 21 12:24:34 2015 -0400
@@ -324,17 +324,22 @@
     shutil.copy(src, dst)
     os.remove(src)
 
+_unified_diff = difflib.unified_diff
+if sys.version_info[0] > 2:
+    import functools
+    _unified_diff = functools.partial(difflib.diff_bytes, difflib.unified_diff)
+
 def getdiff(expected, output, ref, err):
     servefail = False
     lines = []
-    for line in difflib.unified_diff(expected, output, ref, err):
-        if line.startswith('+++') or line.startswith('---'):
-            line = line.replace('\\', '/')
-            if line.endswith(' \n'):
-                line = line[:-2] + '\n'
+    for line in _unified_diff(expected, output, ref, err):
+        if line.startswith(b'+++') or line.startswith(b'---'):
+            line = line.replace(b'\\', b'/')
+            if line.endswith(b' \n'):
+                line = line[:-2] + b'\n'
         lines.append(line)
         if not servefail and line.startswith(
-                             '+  abort: child process failed to start'):
+                             b'+  abort: child process failed to start'):
             servefail = True
 
     return servefail, lines