diff tests/run-tests.py @ 24500:7b0a20cd8c95

run-tests: explicitly handle unicode when writing xunit file The xunit writer was passing a str to a minidom API. An implicit .decode('ascii') was performed somewhere, causing UnicodeDecodeError if test output contained non-ascii sequences. This patch converts test output to utf-8 before passing it to minidom. We use the "replace" strategy to ensure invalid utf-8 sequences get munged into �.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 29 Mar 2015 10:41:23 -0700
parents 9612b96730d7
children 7046ecabd9a8
line wrap: on
line diff
--- a/tests/run-tests.py	Sun Mar 29 19:06:23 2015 +0200
+++ b/tests/run-tests.py	Sun Mar 29 10:41:23 2015 -0700
@@ -1469,7 +1469,11 @@
                     t = doc.createElement('testcase')
                     t.setAttribute('name', tc)
                     t.setAttribute('time', '%.3f' % timesd[tc])
-                    cd = doc.createCDATASection(cdatasafe(err))
+                    # createCDATASection expects a unicode or it will convert
+                    # using default conversion rules, which will fail if
+                    # string isn't ASCII.
+                    err = cdatasafe(err).decode('utf-8', 'replace')
+                    cd = doc.createCDATASection(err)
                     t.appendChild(cd)
                     s.appendChild(t)
                 xuf.write(doc.toprettyxml(indent='  ', encoding='utf-8'))