nuxeo / FunkLoad

Functional and load testing framework for web applications, written in Python
http://funkload.nuxeo.org/
GNU General Public License v2.0
381 stars 83 forks source link

Problem creating report with non-us characters. #14

Closed kadamski closed 13 years ago

kadamski commented 13 years ago

I've got following error:

$ fl-build-report --html bench_result.xml
Creating html report: ...Traceback (most recent call last):
  File "/home/k/build/fl-build-report", line 7, in 
    execfile(__file__)
  File "/home/k/funkload-repo/scripts/fl-build-report", line 25, in 
    main()
  File "/home/k/funkload-repo/src/funkload/ReportBuilder.py", line 288, in main
    xml_parser.monitorconfig, options)()
  File "/home/k/funkload-repo/src/funkload/ReportRenderHtmlBase.py", line 126, in render
    self.createRstFile()
  File "/home/k/funkload-repo/src/funkload/ReportRenderHtmlBase.py", line 85, in createRstFile
    f.write(str(self))
UnicodeEncodeError: 'ascii' codec can't encode character u'\u017a' in position 5251: ordinal not in range(128)

Here's my solution:

diff --git a/src/funkload/ReportBuilder.py b/src/funkload/ReportBuilder.py
index 71becf9..3f3a9d9 100644
--- a/src/funkload/ReportBuilder.py
+++ b/src/funkload/ReportBuilder.py
@@ -290,13 +290,13 @@ def main():
             trace(html_path + "\n")
         elif options.org:
             from ReportRenderOrg import RenderOrg
-            print str(RenderOrg(xml_parser.config, xml_parser.stats,
+            print unicode(RenderOrg(xml_parser.config, xml_parser.stats,
                                 xml_parser.error, xml_parser.monitor,
-                                options))
+                                xml_parser.monitorconfig, options)).encode("utf-8")
         else:
-            print str(RenderRst(xml_parser.config, xml_parser.stats,
+            print unicode(RenderRst(xml_parser.config, xml_parser.stats,
                                 xml_parser.error, xml_parser.monitor,
-                                xml_parser.monitorconfig, options))
+                                xml_parser.monitorconfig, options)).encode("utf-8")

 if __name__ == '__main__':
diff --git a/src/funkload/ReportRenderHtmlBase.py b/src/funkload/ReportRenderHtmlBase.py
index 92ff9f3..00b67d0 100644
--- a/src/funkload/ReportRenderHtmlBase.py
+++ b/src/funkload/ReportRenderHtmlBase.py
@@ -82,7 +82,7 @@ class RenderHtmlBase(RenderRst):
         """Create the ReST file."""
         rst_path = os.path.join(self.report_dir, 'index.rst')
         f = open(rst_path, 'w')
-        f.write(str(self))
+        f.write(unicode(self).encode("utf-8"))
         f.close()
         self.rst_path = rst_path

There may be some more places that need to be changed like this but for now, this is enough for me.