Patchwork [2,of,4,py3] tests: try and fail more gracefully with broken unicode escapes

login
register
mail settings
Submitter Augie Fackler
Date June 15, 2017, 7:32 p.m.
Message ID <389d9fd524f9355578b4.1497555151@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/21401/
State Accepted
Headers show

Comments

Augie Fackler - June 15, 2017, 7:32 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1497546816 14400
#      Thu Jun 15 13:13:36 2017 -0400
# Node ID 389d9fd524f9355578b46cfffd732429fb813b99
# Parent  9ae07d7aff47d4067215216a02e5744c8c974a9c
tests: try and fail more gracefully with broken unicode escapes

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -2093,13 +2093,17 @@  class TextTestRunner(unittest.TextTestRu
             for tc, __ in testcases:
                 if tc.name in timesd:
                     diff = result.faildata.get(tc.name, b'')
+                    try:
+                        diff = diff.decode('unicode_escape')
+                    except UnicodeDecodeError as e:
+                        diff = '%r decoding diff, sorry' % e
                     tres = {'result': res,
                             'time': ('%0.3f' % timesd[tc.name][2]),
                             'cuser': ('%0.3f' % timesd[tc.name][0]),
                             'csys': ('%0.3f' % timesd[tc.name][1]),
                             'start': ('%0.3f' % timesd[tc.name][3]),
                             'end': ('%0.3f' % timesd[tc.name][4]),
-                            'diff': diff.decode('unicode_escape'),
+                            'diff': diff,
                             }
                 else:
                     # blacklisted test