[pypy-svn] r72487 - pypy/trunk/py/plugin

arigo at codespeak.net arigo at codespeak.net
Sun Mar 21 12:12:06 CET 2010


Author: arigo
Date: Sun Mar 21 12:12:04 2010
New Revision: 72487

Modified:
   pypy/trunk/py/plugin/pytest_resultlog.py
Log:
Try to be safe against str(unicode-with-non-standard-chars).
We got a few such crashes on the nightly builds.


Modified: pypy/trunk/py/plugin/pytest_resultlog.py
==============================================================================
--- pypy/trunk/py/plugin/pytest_resultlog.py	(original)
+++ pypy/trunk/py/plugin/pytest_resultlog.py	Sun Mar 21 12:12:04 2010
@@ -68,15 +68,15 @@
         else:
             code = report.shortrepr
         if code == 'x':
-            longrepr = str(report.longrepr)
+            longrepr = safestr(report.longrepr)
         elif code == 'P':
             longrepr = ''
         elif report.passed:
             longrepr = ""
         elif report.failed:
-            longrepr = str(report.longrepr) 
+            longrepr = safestr(report.longrepr) 
         elif report.skipped:
-            longrepr = str(report.longrepr.reprcrash.message)
+            longrepr = safestr(report.longrepr.reprcrash.message)
         self.log_outcome(report.item, code, longrepr) 
 
     def pytest_collectreport(self, report):
@@ -86,9 +86,16 @@
             else:
                 assert report.skipped
                 code = "S"
-            longrepr = str(report.longrepr.reprcrash)
+            longrepr = safestr(report.longrepr.reprcrash)
             self.log_outcome(report.collector, code, longrepr)    
 
     def pytest_internalerror(self, excrepr):
         path = excrepr.reprcrash.path 
-        self.write_log_entry(path, '!', str(excrepr))
+        self.write_log_entry(path, '!', safestr(excrepr))
+
+
+def safestr(x):
+    if isinstance(x, unicode):
+        return x.encode('utf-8')
+    else:
+        return str(x)



More information about the Pypy-commit mailing list