Skip to content

Commit a976ef0

Browse files
Merge pull request #151 from bridadan/fix_decode_reports
Fix string decoding reports
2 parents c13a4f8 + 7764e9d commit a976ef0

File tree

4 files changed

+12
-33
lines changed

4 files changed

+12
-33
lines changed

packages/mbed-greentea/mbed_greentea/mbed_greentea_cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import random
2424
import optparse
2525
import imp
26+
import io
2627
from time import time
2728
try:
2829
from Queue import Queue
@@ -980,7 +981,7 @@ def dump_report_to_text_file(filename, content):
980981
@return True if write was successful, else return False
981982
"""
982983
try:
983-
with open(filename, 'w') as f:
984+
with io.open(filename, encoding="utf-8", errors="backslashreplace", mode="w") as f:
984985
f.write(content)
985986
except IOError as e:
986987
gt_logger.gt_log_err("can't export to '%s', reason:"% filename)

packages/mbed-greentea/test/report_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_report_zero_testcases(self):
4444
u'build_path_abs': u'N/A',
4545
u'copy_method': u'N/A',
4646
u'image_path': u'N/A',
47-
u'single_test_output': b'\x80abc\uXXXX' ,
47+
u'single_test_output': u'\x80abc' ,
4848
u'platform_name': u'k64f',
4949
u'test_bin_name': u'N/A',
5050
u'testcase_result': {},

src/mbed_os_tools/test/mbed_report_api.py

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def exporter_json(test_result_ext, test_suite_properties=None):
3737
for target in test_result_ext.values():
3838
for suite in target.values():
3939
try:
40-
suite["single_test_output"] = suite["single_test_output"]\
41-
.decode("utf-8", "replace")
40+
suite["single_test_output"] = suite["single_test_output"]
4241
except KeyError:
4342
pass
4443
return json.dumps(test_result_ext, indent=4)
@@ -161,16 +160,7 @@ def exporter_testcase_junit(test_result_ext, test_suite_properties=None):
161160
test_results = test_result_ext[target_name]
162161
for test_suite_name in test_results:
163162
test = test_results[test_suite_name]
164-
165-
try:
166-
if sys.version_info >= (3, 0):
167-
tc_stdout = str(test['single_test_output']).encode('ascii', 'ignore')
168-
else:
169-
tc_stdout = test['single_test_output'].decode('unicode_escape').encode('ascii', 'ignore')
170-
except UnicodeDecodeError as e:
171-
err_mgs = "(UnicodeDecodeError) exporter_testcase_junit:", str(e)
172-
tc_stdout = err_mgs
173-
print(err_mgs)
163+
tc_stdout = test['single_test_output']
174164

175165
# testcase_result stores info about test case results
176166
testcase_result = test['testcase_result']
@@ -189,18 +179,7 @@ def exporter_testcase_junit(test_result_ext, test_suite_properties=None):
189179
utest_log = testcase_result[tc_name].get('utest_log', '')
190180
result_text = testcase_result[tc_name].get('result_text', "UNDEF")
191181

192-
try:
193-
lines = '\n'.join(utest_log)
194-
195-
if sys.version_info >= (3, 0):
196-
tc_stderr = str(lines).encode('ascii', 'ignore')
197-
else:
198-
tc_stderr = lines.decode('unicode_escape').encode('ascii', 'ignore')
199-
except UnicodeDecodeError as e:
200-
err_mgs = "(UnicodeDecodeError) exporter_testcase_junit:" + str(e)
201-
tc_stderr = err_mgs
202-
print(err_mgs)
203-
182+
tc_stderr = '\n'.join(utest_log)
204183
tc_class = target_name + '.' + test_suite_name
205184

206185
if result_text == 'SKIPPED':
@@ -604,12 +583,11 @@ def get_result_overlay_dropdowns(result_div_id, test_results):
604583

605584
# The HTML for the dropdown containing the ouput of the test
606585
result_output_div_id = "%s_output" % result_div_id
607-
result_output_dropdown = get_dropdown_html(result_output_div_id,
608-
"Test Output",
609-
test_results['single_test_output']
610-
.decode("utf-8", "replace")
611-
.rstrip("\n"),
612-
output_text=True)
586+
result_output_dropdown = get_dropdown_html(
587+
result_output_div_id, "Test Output",
588+
test_results['single_test_output'].rstrip("\n"),
589+
output_text=True
590+
)
613591

614592
# Add a dropdown for the testcases if they are present
615593
if len(test_results) > 0:

test/test/report_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_report_zero_testcases(self):
4242
u'build_path_abs': u'N/A',
4343
u'copy_method': u'N/A',
4444
u'image_path': u'N/A',
45-
u'single_test_output': b'\x80abc\uXXXX' ,
45+
u'single_test_output': u'\x80abc',
4646
u'platform_name': u'k64f',
4747
u'test_bin_name': u'N/A',
4848
u'testcase_result': {},

0 commit comments

Comments
 (0)