Repository: ARMmbed/greentea

Issue:
mbedgt crash with UnicodeDecodeError
Hi

I am sorry, but I still get some crash with the new green tea version ...

mbedgt: exporting to HTML file 'C:/mcu/reports/report__mbed_os5_release_non_regression_F756ZG_mbed-os-5.5.7__2017_09_28_00_06.html'...
mbedgt: unexpected error:
	'unicodeescape' codec can't decode bytes in position 6308-6310: truncated \uXXXX escape
Traceback (most recent call last):
  File "C:\Python27\Scripts\mbedgt-script.py", line 11, in <module>
    load_entry_point('mbed-greentea==1.3.0', 'console_scripts', 'mbedgt')()
  File "c:\python27\lib\site-packages\mbed_greentea\mbed_greentea_cli.py", line 416, in main
    cli_ret = main_cli(opts, args)
  File "c:\python27\lib\site-packages\mbed_greentea\mbed_greentea_cli.py", line 1067, in main_cli
    html_report = exporter_html(test_report)
  File "c:\python27\lib\site-packages\mbed_greentea\mbed_report_api.py", line 747, in exporter_html
    test_results)
  File "c:\python27\lib\site-packages\mbed_greentea\mbed_report_api.py", line 636, in get_result_overlay
    overlay_dropdowns = get_result_overlay_dropdowns(result_div_id, test_results)
  File "c:\python27\lib\site-packages\mbed_greentea\mbed_report_api.py", line 598, in get_result_overlay_dropdowns
    .decode("unicode-escape")
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 6308-6310: truncated \uXXXX escape

@theotherjimmy 


Comments:

Patch:
diff --git a/mbed_greentea/mbed_report_api.py b/mbed_greentea/mbed_report_api.py
index 166bc29..22a3778 100644
--- a/mbed_greentea/mbed_report_api.py
+++ b/mbed_greentea/mbed_report_api.py
@@ -42,7 +42,7 @@ def exporter_json(test_result_ext, test_suite_properties=None):
         for suite in target.values():
             try:
                 suite["single_test_output"] = suite["single_test_output"]\
-                                              .decode("unicode_escape")
+                                              .decode("utf-8", "replace")
             except KeyError:
                 pass
     return json.dumps(test_result_ext, indent=4)
@@ -603,7 +603,7 @@ def get_result_overlay_dropdowns(result_div_id, test_results):
     result_output_dropdown = get_dropdown_html(result_output_div_id,
                                                "Test Output",
                                                test_results['single_test_output']
-                                               .decode("unicode-escape")
+                                               .decode("utf-8", "replace")
                                                .rstrip("\n"),
                                                output_text=True)
 


Test patch:
diff --git a/test/report_api.py b/test/report_api.py
index 122e26e..2a4275f 100644
--- a/test/report_api.py
+++ b/test/report_api.py
@@ -45,7 +45,7 @@ class ReportEmitting(unittest.TestCase):
                     u'build_path_abs': u'N/A',
                     u'copy_method': u'N/A',
                     u'image_path': u'N/A',
-                    u'single_test_output': b'N/A',
+                    u'single_test_output': b'\x80abc\uXXXX' ,
                     u'platform_name': u'k64f',
                     u'test_bin_name': u'N/A',
                     u'testcase_result': {},