Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
24499:90db70de6f9c | 24500:7b0a20cd8c95 |
---|---|
1467 s.appendChild(t) | 1467 s.appendChild(t) |
1468 for tc, err in sorted(result.faildata.iteritems()): | 1468 for tc, err in sorted(result.faildata.iteritems()): |
1469 t = doc.createElement('testcase') | 1469 t = doc.createElement('testcase') |
1470 t.setAttribute('name', tc) | 1470 t.setAttribute('name', tc) |
1471 t.setAttribute('time', '%.3f' % timesd[tc]) | 1471 t.setAttribute('time', '%.3f' % timesd[tc]) |
1472 cd = doc.createCDATASection(cdatasafe(err)) | 1472 # createCDATASection expects a unicode or it will convert |
1473 # using default conversion rules, which will fail if | |
1474 # string isn't ASCII. | |
1475 err = cdatasafe(err).decode('utf-8', 'replace') | |
1476 cd = doc.createCDATASection(err) | |
1473 t.appendChild(cd) | 1477 t.appendChild(cd) |
1474 s.appendChild(t) | 1478 s.appendChild(t) |
1475 xuf.write(doc.toprettyxml(indent=' ', encoding='utf-8')) | 1479 xuf.write(doc.toprettyxml(indent=' ', encoding='utf-8')) |
1476 finally: | 1480 finally: |
1477 xuf.close() | 1481 xuf.close() |